Skip to content

Commit 42f93e5

Browse files
committed
Use new fields and fix N+1
1 parent 68ac022 commit 42f93e5

File tree

7 files changed

+84
-107
lines changed

7 files changed

+84
-107
lines changed

src/api/operations/staffAssignment.fragments.graphql

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1+
# This fragment is resolved both on an individual household (staff assignment card)
2+
# AND on a table of households (staff assignment optional column)
13
fragment HouseholdWithStaffAssignments on Household {
24
id
3-
householdClients {
4-
# this is included because of "My Dashboard" query I think it should be split to 2 fragments
5-
id
6-
relationshipToHoH
7-
client {
8-
id
9-
...ClientName
10-
}
11-
}
12-
staffAssignments(limit: 100) {
13-
nodesCount
14-
nodes {
15-
...StaffAssignmentDetails
16-
}
5+
currentStaffAssignments {
6+
...StaffAssignmentDetails
177
}
188
}
199

src/api/operations/staffAssignment.queries.graphql

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
query GetHouseholdStaffAssignments($id: ID!) {
22
household(id: $id) {
33
...HouseholdWithStaffAssignments
4+
5+
# These are resolved just so that we can show the HoH Client Name
6+
# inside the staff assignment management screen. It would be better
7+
# if we added a hoh or hohName field to the Household type
8+
householdClients {
9+
id
10+
relationshipToHoH
11+
client {
12+
id
13+
...ClientName
14+
}
15+
}
416
}
517
}
618

src/modules/enrollment/columns/enrollmentColumns.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const HOUSEHOLD_ASSIGNED_STAFF_COL = {
8888
},
8989
key: 'assignedStaff',
9090
render: (hh: HouseholdWithStaffAssignmentsFragment) => (
91-
<HouseholdStaff staffAssignments={hh.staffAssignments?.nodes || []} />
91+
<HouseholdStaff staffAssignments={hh.currentStaffAssignments} />
9292
),
9393
};
9494

src/modules/staffAssignment/components/EditStaffAssignmentDialog.tsx

+10-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Stack,
77
Typography,
88
} from '@mui/material';
9-
import React, { useMemo } from 'react';
9+
import React from 'react';
1010
import NewStaffAssignmentForm from './NewStaffAssignmentForm';
1111
import StaffAssignmentHistory from './StaffAssignmentHistory';
1212
import StaffAssignmentTable from './StaffAssignmentTable';
@@ -15,35 +15,32 @@ import { CommonLabeledTextBlock } from '@/components/elements/CommonLabeledTextB
1515
import { useIsMobile } from '@/hooks/useIsMobile';
1616
import useEnrollmentDashboardContext from '@/modules/enrollment/hooks/useEnrollmentDashboardContext';
1717
import EnrollmentDateRangeWithStatus from '@/modules/hmis/components/EnrollmentDateRangeWithStatus';
18-
import { clientBriefName } from '@/modules/hmis/hmisUtil';
19-
import {
20-
HouseholdWithStaffAssignmentsFragment,
21-
RelationshipToHoH,
22-
} from '@/types/gqlTypes';
18+
import { HouseholdWithStaffAssignmentsFragment } from '@/types/gqlTypes';
2319

2420
interface EditStaffAssignmentDialogProps {
2521
household: HouseholdWithStaffAssignmentsFragment;
2622
open: boolean;
2723
onClose: VoidFunction;
24+
hohName: string;
2825
}
2926

3027
const EditStaffAssignmentDialog: React.FC<EditStaffAssignmentDialogProps> = ({
3128
household,
3229
open,
3330
onClose,
31+
hohName,
3432
}) => {
3533
const isTiny = useIsMobile('sm');
3634

37-
const headOfHousehold = useMemo(() => {
38-
return household.householdClients.find(
39-
(c) => c.relationshipToHoH === RelationshipToHoH.SelfHeadOfHousehold
40-
);
41-
}, [household.householdClients]);
35+
// const headOfHousehold = useMemo(() => {
36+
// return household.householdClients.find(
37+
// (c) => c.relationshipToHoH === RelationshipToHoH.SelfHeadOfHousehold
38+
// );
39+
// }, [household.householdClients]);
4240

4341
const { enrollment } = useEnrollmentDashboardContext();
4442

4543
if (!enrollment) return;
46-
if (!headOfHousehold) return;
4744

4845
return (
4946
<CommonDialog fullWidth open={open} onClose={onClose} maxWidth='md'>
@@ -52,7 +49,7 @@ const EditStaffAssignmentDialog: React.FC<EditStaffAssignmentDialogProps> = ({
5249
<Stack gap={3} sx={{ mt: 2 }}>
5350
<Stack direction={isTiny ? 'column' : 'row'} gap={isTiny ? 2 : 4}>
5451
<CommonLabeledTextBlock title='Head of Household'>
55-
{clientBriefName(headOfHousehold.client)}
52+
{hohName}
5653
</CommonLabeledTextBlock>
5754
<CommonLabeledTextBlock title='Project'>
5855
{enrollment.project.projectName}

src/modules/staffAssignment/components/StaffAssignmentCard.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Loading from '@/components/elements/Loading';
1010
import TitleCard from '@/components/elements/TitleCard';
1111
import IconButtonContainer from '@/modules/enrollment/components/IconButtonContainer';
1212
import useEnrollmentDashboardContext from '@/modules/enrollment/hooks/useEnrollmentDashboardContext';
13+
import { clientBriefName } from '@/modules/hmis/hmisUtil';
1314
import {
1415
RelationshipToHoH,
1516
useGetHouseholdStaffAssignmentsQuery,
@@ -35,11 +36,12 @@ const StaffAssignmentCard: React.FC<StaffAssignmentCardProps> = ({
3536
const [editDialogOpen, setEditDialogOpen] = useState(false);
3637

3738
const staffAssignmentRows = useMemo(() => {
38-
if (!household?.staffAssignments?.nodesCount) return;
39+
if (!household?.currentStaffAssignments) return;
40+
if (household.currentStaffAssignments.length === 0) return;
3941

4042
// { relationship => [user1, user2] }
4143
const staff: Record<string, string[]> = {};
42-
household.staffAssignments.nodes.forEach(
44+
household.currentStaffAssignments.forEach(
4345
({ staffAssignmentRelationship, user }) => {
4446
staff[staffAssignmentRelationship] ||= [];
4547
staff[staffAssignmentRelationship].push(user.name);
@@ -49,6 +51,14 @@ const StaffAssignmentCard: React.FC<StaffAssignmentCardProps> = ({
4951
return Object.entries(staff).sort(([a], [b]) => a.localeCompare(b));
5052
}, [household]);
5153

54+
const headOfHousehold = useMemo(() => {
55+
if (!household) return;
56+
57+
return household.householdClients.find(
58+
(c) => c.relationshipToHoH === RelationshipToHoH.SelfHeadOfHousehold
59+
)?.client;
60+
}, [household]);
61+
5262
if (!enrollment) return;
5363
if (error) throw error;
5464

@@ -59,6 +69,7 @@ const StaffAssignmentCard: React.FC<StaffAssignmentCardProps> = ({
5969
household={household}
6070
open={editDialogOpen}
6171
onClose={() => setEditDialogOpen(false)}
72+
hohName={clientBriefName(headOfHousehold || enrollment.client)}
6273
/>
6374
)}
6475
<TitleCard
@@ -77,10 +88,10 @@ const StaffAssignmentCard: React.FC<StaffAssignmentCardProps> = ({
7788
}
7889
>
7990
{loading && <Loading />}
80-
{!loading && household?.staffAssignments && (
91+
{!loading && household?.currentStaffAssignments && (
8192
<>
8293
<Divider />
83-
{household.staffAssignments.nodesCount === 0 && (
94+
{household.currentStaffAssignments.length === 0 && (
8495
<Typography variant='body2' sx={{ p: 2 }} color='text.secondary'>
8596
No staff assigned
8697
</Typography>

src/modules/staffAssignment/components/StaffAssignmentTable.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const StaffAssignmentTable: React.FC<StaffAssignmentTableProps> = ({
9494
return (
9595
<Card sx={cardSx}>
9696
<GenericTable<StaffAssignmentDetailsFragment>
97-
rows={household.staffAssignments?.nodes || []}
97+
rows={household.currentStaffAssignments}
9898
columns={columns || defaultColumns}
9999
noData={'No Staff Assigned'}
100100
tableProps={{ 'aria-label': 'Current staff assignments' }}

src/types/gqlTypes.ts

+41-74
Original file line numberDiff line numberDiff line change
@@ -36351,18 +36351,14 @@ export type ProjectEnrollmentsHouseholdFieldsFragment = {
3635136351
} | null;
3635236352
};
3635336353
}>;
36354-
staffAssignments?: {
36355-
__typename?: 'StaffAssignmentsPaginated';
36356-
nodesCount: number;
36357-
nodes: Array<{
36358-
__typename?: 'StaffAssignment';
36359-
id: string;
36360-
staffAssignmentRelationship: string;
36361-
assignedAt: string;
36362-
unassignedAt?: string | null;
36363-
user: { __typename?: 'ApplicationUser'; id: string; name: string };
36364-
}>;
36365-
} | null;
36354+
currentStaffAssignments: Array<{
36355+
__typename?: 'StaffAssignment';
36356+
id: string;
36357+
staffAssignmentRelationship: string;
36358+
assignedAt: string;
36359+
unassignedAt?: string | null;
36360+
user: { __typename?: 'ApplicationUser'; id: string; name: string };
36361+
}>;
3636636362
};
3636736363

3636836364
export type ProjectEnrollmentsHouseholdClientFieldsFragment = {
@@ -39021,18 +39017,14 @@ export type GetProjectHouseholdsQuery = {
3902139017
} | null;
3902239018
};
3902339019
}>;
39024-
staffAssignments?: {
39025-
__typename?: 'StaffAssignmentsPaginated';
39026-
nodesCount: number;
39027-
nodes: Array<{
39028-
__typename?: 'StaffAssignment';
39029-
id: string;
39030-
staffAssignmentRelationship: string;
39031-
assignedAt: string;
39032-
unassignedAt?: string | null;
39033-
user: { __typename?: 'ApplicationUser'; id: string; name: string };
39034-
}>;
39035-
} | null;
39020+
currentStaffAssignments: Array<{
39021+
__typename?: 'StaffAssignment';
39022+
id: string;
39023+
staffAssignmentRelationship: string;
39024+
assignedAt: string;
39025+
unassignedAt?: string | null;
39026+
user: { __typename?: 'ApplicationUser'; id: string; name: string };
39027+
}>;
3903639028
}>;
3903739029
};
3903839030
} | null;
@@ -42712,32 +42704,14 @@ export type GetServiceCategoryTypesQuery = {
4271242704
export type HouseholdWithStaffAssignmentsFragment = {
4271342705
__typename?: 'Household';
4271442706
id: string;
42715-
householdClients: Array<{
42716-
__typename?: 'HouseholdClient';
42707+
currentStaffAssignments: Array<{
42708+
__typename?: 'StaffAssignment';
4271742709
id: string;
42718-
relationshipToHoH: RelationshipToHoH;
42719-
client: {
42720-
__typename?: 'Client';
42721-
id: string;
42722-
lockVersion: number;
42723-
firstName?: string | null;
42724-
middleName?: string | null;
42725-
lastName?: string | null;
42726-
nameSuffix?: string | null;
42727-
};
42710+
staffAssignmentRelationship: string;
42711+
assignedAt: string;
42712+
unassignedAt?: string | null;
42713+
user: { __typename?: 'ApplicationUser'; id: string; name: string };
4272842714
}>;
42729-
staffAssignments?: {
42730-
__typename?: 'StaffAssignmentsPaginated';
42731-
nodesCount: number;
42732-
nodes: Array<{
42733-
__typename?: 'StaffAssignment';
42734-
id: string;
42735-
staffAssignmentRelationship: string;
42736-
assignedAt: string;
42737-
unassignedAt?: string | null;
42738-
user: { __typename?: 'ApplicationUser'; id: string; name: string };
42739-
}>;
42740-
} | null;
4274142715
};
4274242716

4274342717
export type StaffAssignmentDetailsFragment = {
@@ -42873,18 +42847,14 @@ export type GetHouseholdStaffAssignmentsQuery = {
4287342847
nameSuffix?: string | null;
4287442848
};
4287542849
}>;
42876-
staffAssignments?: {
42877-
__typename?: 'StaffAssignmentsPaginated';
42878-
nodesCount: number;
42879-
nodes: Array<{
42880-
__typename?: 'StaffAssignment';
42881-
id: string;
42882-
staffAssignmentRelationship: string;
42883-
assignedAt: string;
42884-
unassignedAt?: string | null;
42885-
user: { __typename?: 'ApplicationUser'; id: string; name: string };
42886-
}>;
42887-
} | null;
42850+
currentStaffAssignments: Array<{
42851+
__typename?: 'StaffAssignment';
42852+
id: string;
42853+
staffAssignmentRelationship: string;
42854+
assignedAt: string;
42855+
unassignedAt?: string | null;
42856+
user: { __typename?: 'ApplicationUser'; id: string; name: string };
42857+
}>;
4288842858
} | null;
4288942859
};
4289042860

@@ -45180,22 +45150,10 @@ export const StaffAssignmentDetailsFragmentDoc = gql`
4518045150
export const HouseholdWithStaffAssignmentsFragmentDoc = gql`
4518145151
fragment HouseholdWithStaffAssignments on Household {
4518245152
id
45183-
householdClients {
45184-
id
45185-
relationshipToHoH
45186-
client {
45187-
id
45188-
...ClientName
45189-
}
45190-
}
45191-
staffAssignments(limit: 100) {
45192-
nodesCount
45193-
nodes {
45194-
...StaffAssignmentDetails
45195-
}
45153+
currentStaffAssignments {
45154+
...StaffAssignmentDetails
4519645155
}
4519745156
}
45198-
${ClientNameFragmentDoc}
4519945157
${StaffAssignmentDetailsFragmentDoc}
4520045158
`;
4520145159
export const ProjectEnrollmentsHouseholdFieldsFragmentDoc = gql`
@@ -59170,9 +59128,18 @@ export const GetHouseholdStaffAssignmentsDocument = gql`
5917059128
query GetHouseholdStaffAssignments($id: ID!) {
5917159129
household(id: $id) {
5917259130
...HouseholdWithStaffAssignments
59131+
householdClients {
59132+
id
59133+
relationshipToHoH
59134+
client {
59135+
id
59136+
...ClientName
59137+
}
59138+
}
5917359139
}
5917459140
}
5917559141
${HouseholdWithStaffAssignmentsFragmentDoc}
59142+
${ClientNameFragmentDoc}
5917659143
`;
5917759144

5917859145
/**

0 commit comments

Comments
 (0)