Skip to content

Commit

Permalink
Merge branch 'release-147' into deploy/6761-table-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gigxz committed Jan 10, 2025
2 parents d69df9b + f10d4fe commit f860bba
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 58 deletions.
2 changes: 1 addition & 1 deletion docker/templates/non_proxy_headers.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;" alwa
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Feature-Policy "geolocation 'self'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; usb 'none';";
add_header Feature-Policy "geolocation 'self'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; fullscreen 'none'; payment 'none'; usb 'none';";
add_header Permissions-Policy "geolocation=(self)";
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('applyDataCollectedAbout', () => {
applyDataCollectedAbout(
items as FormDefinitionFieldsFragment['definition']['item'],
client,
RelationshipToHoH.DataNotCollected
RelationshipToHoH.UnrelatedHouseholdMember
)
).toMatchObject(items);
});
Expand All @@ -34,7 +34,7 @@ describe('applyDataCollectedAbout', () => {
applyDataCollectedAbout(
items as FormDefinitionFieldsFragment['definition']['item'],
{ ...client, dob: '1960-01-01' },
RelationshipToHoH.DataNotCollected
RelationshipToHoH.UnrelatedHouseholdMember
)
).toMatchObject(items);
});
Expand All @@ -61,7 +61,7 @@ describe('applyDataCollectedAbout', () => {
applyDataCollectedAbout(
items as FormDefinitionFieldsFragment['definition']['item'],
client,
RelationshipToHoH.DataNotCollected
RelationshipToHoH.UnrelatedHouseholdMember
)
).toMatchObject(items);
});
Expand All @@ -76,7 +76,7 @@ describe('applyDataCollectedAbout', () => {
...client,
dob: '2022-01-01',
},
RelationshipToHoH.DataNotCollected
RelationshipToHoH.UnrelatedHouseholdMember
)
).toHaveLength(0);
});
Expand Down
20 changes: 19 additions & 1 deletion src/modules/form/util/formUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,31 @@ export const hasMeaningfulValue = (value: any): boolean => {
return true;
};

/**
* Resolves a GQL Enum name into an array of PickListOptions
* that can be used for selection components (dropdowns, radio buttons, etc).
*
* Optionally specify whether to include "Data Not Collected" (99) equivalent in the list,
* if the enum contains it.
*
* There is a special case to always exclude 99 for the RelationshipToHoH picklist,
* because 99 is not a valid value for collection, but we keep it in the GQL Enum
* because we need to treat it as a valid value for display. This is because there may
* be unfixable migrated-in data with 99s or nulls, and we want to display those as
* 'Data not collected' rather than 'Invalid'.
*
* @param pickListReference - The name of the GraphQL Enum to resolve as a pick list
* @param excludeDataNotCollected - Whether to exlude Data Not Collected from the pick list
* @returns The resolved array of PickListOptions, or null if pick list reference was not found.
*/
export const localResolvePickList = (
pickListReference: string,
excludeDataNotCollected = false
): PickListOption[] | null => {
if (isHmisEnum(pickListReference)) {
let values = Object.entries(HmisEnums[pickListReference]);
if (excludeDataNotCollected) {

if (excludeDataNotCollected || pickListReference === 'RelationshipToHoH') {
values = values.filter(([code]) => !isDataNotCollected(code));
}
return values
Expand Down
20 changes: 1 addition & 19 deletions src/modules/household/components/EditHouseholdMemberTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import RemoveFromHouseholdButton from './elements/RemoveFromHouseholdButton';
import { HOUSEHOLD_MEMBER_COLUMNS } from './HouseholdMemberTable';

import GenericTable from '@/components/elements/table/GenericTable';
import usePrevious from '@/hooks/usePrevious';
import { SsnDobShowContextProvider } from '@/modules/client/providers/ClientSsnDobVisibility';
import { useValidationDialog } from '@/modules/errors/hooks/useValidationDialog';
import {
emptyErrorState,
ErrorState,
partitionValidations,
} from '@/modules/errors/util';
import { sortHouseholdMembers, clientBriefName } from '@/modules/hmis/hmisUtil';
import { clientBriefName, sortHouseholdMembers } from '@/modules/hmis/hmisUtil';
import {
HouseholdClientFieldsFragment,
HouseholdFieldsFragment,
Expand Down Expand Up @@ -60,8 +59,6 @@ const EditHouseholdMemberTable = ({
(hc) => hc.relationshipToHoH === RelationshipToHoH.SelfHeadOfHousehold
) || null
);
const previousMembers =
usePrevious<HouseholdClientFieldsFragment[]>(currentMembers);

// client to highlight for relationship input
const [highlight, setHighlight] = useState<string[]>([]);
Expand Down Expand Up @@ -109,21 +106,6 @@ const EditHouseholdMemberTable = ({
});
}, [currentMembers]);

// If new members have beed added highlight their relationship field if it's DNC
useEffect(() => {
if (!previousMembers || !currentMembers) return;
if (previousMembers.length < currentMembers.length) {
const old = new Set(previousMembers.map((m) => m.client.id));
const newMembers = currentMembers
.filter(
(hc) => hc.relationshipToHoH === RelationshipToHoH.DataNotCollected
)
.map((m) => m.client.id)
.filter((id) => !old.has(id));
setHighlight((old) => [...old, ...newMembers]);
}
}, [previousMembers, currentMembers]);

const onChangeHoH = useCallback(
(hc: HouseholdClientFieldsFragment, confirmed = false) => {
setProposedHoH(hc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ const RelationshipToHoHInput = ({

const onChange = useMemo(
() => (_: any, selected: Option | null) => {
if (!selected) return; // this should never happen because `disableClearable` is passed
setCompleted(false);
setRelationship(selected ? selected.value : null);
setRelationship(selected.value);
void updateRelationship({
variables: {
input: {
enrollmentId,
enrollmentLockVersion,
relationshipToHoH: selected
? selected.value
: RelationshipToHoH.DataNotCollected,
relationshipToHoH: selected.value,
confirmed: true, // we don't support displaying warnings in this view, so ignore them
},
},
Expand All @@ -68,8 +67,8 @@ const RelationshipToHoHInput = ({
<RelationshipToHohSelect
value={relationship || null}
onChange={onChange}
showDataNotCollected
disabled={loading}
disableClearable
{...props}
/>
</InputIndicatorContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Typography } from '@mui/material';
import { omit } from 'lodash-es';
import { useMemo } from 'react';

import GenericSelect, {
GenericSelectProps,
} from '@/components/elements/input/GenericSelect';
import { localResolvePickList } from '@/modules/form/util/formUtil';
import { HmisEnums } from '@/types/gqlEnums';
import { RelationshipToHoH } from '@/types/gqlTypes';

Expand All @@ -13,34 +12,22 @@ export type Option = { value: RelationshipToHoH; label: string };
export interface Props
extends Omit<GenericSelectProps<Option, false, false>, 'options' | 'value'> {
value: RelationshipToHoH | null;
showDataNotCollected?: boolean;
}
const relationshipToHohOptions: Option[] = (
localResolvePickList('RelationshipToHoH') || []
)
.filter(({ code }) => code !== RelationshipToHoH.SelfHeadOfHousehold) // Exclude HoH from option list
.map(({ code, label }) => ({
value: code as RelationshipToHoH,
label: label as string,
}));

const RelationshipToHohSelect = ({
disabled,
value,
showDataNotCollected = false,
textInputProps,
...props
}: Props) => {
const relationshipToHohOptions = useMemo(() => {
const excluded = [
RelationshipToHoH.SelfHeadOfHousehold,
RelationshipToHoH.Invalid,
];
if (!showDataNotCollected)
excluded.push(RelationshipToHoH.DataNotCollected);

const filtered = omit(HmisEnums.RelationshipToHoH, excluded);
const options = Object.entries(filtered).map(
([value, label]) =>
({
value,
label,
}) as Option
);
return options;
}, [showDataNotCollected]);

// disabled if HoH is selected
const isHoH = value === RelationshipToHoH.SelfHeadOfHousehold;
const isDisabled = disabled || isHoH;
Expand All @@ -52,15 +39,12 @@ const RelationshipToHohSelect = ({
</Typography>
);
}

return (
<GenericSelect<Option, false, false>
options={relationshipToHohOptions}
disabled={isDisabled}
textInputProps={{
placeholder: isHoH
? HmisEnums.RelationshipToHoH[value]
: 'Select relationship',
}}
textInputProps={{ placeholder: 'Select Relationship', ...textInputProps }}
value={
value && !isHoH
? relationshipToHohOptions.find((el) => el.value === value) || null
Expand Down

0 comments on commit f860bba

Please sign in to comment.