Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Citizen Filter With Other Categories #767

Merged
merged 6 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions src/Assets/citizenshipFilterFormControlLabels.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormattedMessage } from 'react-intl';
import { FormattedMessageType } from '../Types/Questions';

export type CitizenLabels =
| 'non_citizen'
Expand All @@ -7,9 +8,19 @@ export type CitizenLabels =
| 'gc_5plus'
| 'gc_18plus_no5'
| 'gc_under18_no5'
| 'gc_under19_pregnant_no5';
| 'other'
| 'otherWithWorkPermission'
| 'otherHealthCareUnder19'
| 'otherHealthCarePregnant';

const citizenshipFilterFormControlLabels = {
export const filterNestedMap = new Map<CitizenLabels, CitizenLabels[]>([
['non_citizen', []],
['green_card', ['gc_5plus', 'gc_18plus_no5', 'gc_under18_no5']],
['refugee', []],
['other', ['otherWithWorkPermission', 'otherHealthCareUnder19', 'otherHealthCarePregnant']],
]);

const citizenshipFilterFormControlLabels: Record<CitizenLabels, FormattedMessageType> = {
non_citizen: (
<FormattedMessage
id="citizenshipFCtrlLabel-non_citizen"
Expand All @@ -30,18 +41,31 @@ const citizenshipFilterFormControlLabels = {
defaultMessage="younger than 18 without a 5-year waiting period"
/>
),
gc_under19_pregnant_no5: (
<FormattedMessage
id="citizenshipFCtrlLabel-gc_under19_pregnant_no5"
defaultMessage="for health care benefits - younger than 19 or pregnant without a 5-year waiting period"
/>
),
refugee: (
<FormattedMessage
id="citizenshipFCtrlLabel-refugee"
defaultMessage="Refugees or asylees (special rules or waiting periods may apply)"
/>
),
other: <FormattedMessage id="citizenshipFCtrlLabel-other" defaultMessage="Other lawfully present noncitizens" />,
otherWithWorkPermission: (
<FormattedMessage
id="citizenshipFCtrlLabel-other_work_permission"
defaultMessage="with permission to live or work in the U.S. (other rules may apply)"
/>
),
otherHealthCareUnder19: (
<FormattedMessage
id="citizenshipFCtrlLabel-other_health_care_under19"
defaultMessage="for health care benefits - younger than 19"
/>
),
otherHealthCarePregnant: (
<FormattedMessage
id="citizenshipFCtrlLabel-other_health_care_pregnant"
defaultMessage="for health care benefits - pregnant"
/>
),
Comment on lines +50 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added these labels to the production translations api.

};

export default citizenshipFilterFormControlLabels;
4 changes: 4 additions & 0 deletions src/Components/FilterSection/CitizenshipPopover.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.MuiFormControlLabel-root.gc-subcitizen-indentation {
margin-left: 1.25rem;
}

.MuiFormControlLabel-label {
padding: 0.5rem 0;
}
82 changes: 27 additions & 55 deletions src/Components/FilterSection/CitizenshipPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IconButton from '@mui/material/IconButton';
import { Checkbox, Stack } from '@mui/material';
import { GridFilterItem, GridFilterOperator } from '@mui/x-data-grid';
import { UpdateFilterArg } from '../Results/Results';
import citizenshipFilterFormControlLabels from '../../Assets/citizenshipFilterFormControlLabels';
import citizenshipFilterFormControlLabels, { filterNestedMap } from '../../Assets/citizenshipFilterFormControlLabels';
import type { CitizenLabels } from '../../Assets/citizenshipFilterFormControlLabels';
import './CitizenshipPopover.css';

Expand Down Expand Up @@ -56,22 +56,16 @@ const CitizenshipPopover = ({
const handleFilterSelect = (citizenshipType: CitizenLabels) => {
const isChecked = citizenshipFilterIsChecked[citizenshipType];

let updatedCitizenshipFilterIsChecked: Record<CitizenLabels, boolean> = {
const updatedCitizenshipFilterIsChecked: Record<CitizenLabels, boolean> = {
...citizenshipFilterIsChecked,
[citizenshipType]: !isChecked,
};

if (citizenshipType === 'green_card') {
// if the citizenshipType is `green_card`, then set green_card and all the gc_options to true or false
// i.e. green_card and all the gc_options should be the same when citizenshipType is `green_card`
updatedCitizenshipFilterIsChecked = {
...updatedCitizenshipFilterIsChecked,
gc_5plus: !isChecked,
gc_18plus_no5: !isChecked,
gc_under18_no5: !isChecked,
gc_under19_pregnant_no5: !isChecked,
};
for (const nestedFilter of filterNestedMap.get(citizenshipType) ?? []) {
// if a parent is not checked, then set its children to false, and if a parent becomes checked, then set its children to true
updatedCitizenshipFilterIsChecked[nestedFilter] = !isChecked;
}

const typedUpdatedCitizenshipFilterIsChecked = Object.keys(updatedCitizenshipFilterIsChecked) as CitizenLabels[];
const selectedCitizenshipFilters = typedUpdatedCitizenshipFilterIsChecked.filter((citizenshipType) => {
return updatedCitizenshipFilterIsChecked[citizenshipType];
Expand Down Expand Up @@ -105,56 +99,34 @@ const CitizenshipPopover = ({
setCitizenshipFilterIsChecked(updatedCitizenshipFilterIsChecked);
};

const typedCitizenshipFilterIsChecked = Object.keys(citizenshipFilterIsChecked) as CitizenLabels[];

const renderMainAndSubFilters = (citizenshipFilters: Record<CitizenLabels, boolean>) => {
return typedCitizenshipFilterIsChecked.map((citizenshipType) => {
//here we need to add an sx prop to indent them if they're the gc_filters
const isGreenCardSubCitizenshipType = [
'gc_5plus',
'gc_18plus_no5',
'gc_under18_no5',
'gc_under19_pregnant_no5',
].includes(citizenshipType);

return (
const renderCitizenshipFilters = (citizenshipFilters: Record<CitizenLabels, boolean>) => {
const filters: JSX.Element[] = [];
filterNestedMap.forEach((children, parentLabel) => {
filters.push(
<FormControlLabel
key={citizenshipType}
className={isGreenCardSubCitizenshipType ? 'gc-subcitizen-indentation' : ''}
label={citizenshipFilterFormControlLabels[citizenshipType]}
key={parentLabel}
label={citizenshipFilterFormControlLabels[parentLabel]}
control={
<Checkbox
checked={citizenshipFilters[citizenshipType]}
onChange={() => handleFilterSelect(citizenshipType)}
/>
<Checkbox checked={citizenshipFilters[parentLabel]} onChange={() => handleFilterSelect(parentLabel)} />
}
/>
/>,
);
});
};

const renderMainFilters = (citizenshipFilters: Record<CitizenLabels, boolean>) => {
//green_card is false
const initialThreeFilters: CitizenLabels[] = ['non_citizen', 'green_card', 'refugee'];
return initialThreeFilters.map((initialFilter) => {
return (
<FormControlLabel
key={initialFilter}
label={citizenshipFilterFormControlLabels[initialFilter]}
control={
<Checkbox checked={citizenshipFilters[initialFilter]} onChange={() => handleFilterSelect(initialFilter)} />
}
/>
);
if (citizenshipFilters[parentLabel]) {
children.forEach((label) => {
filters.push(
<FormControlLabel
key={label}
className="gc-subcitizen-indentation"
label={citizenshipFilterFormControlLabels[label]}
control={<Checkbox checked={citizenshipFilters[label]} onChange={() => handleFilterSelect(label)} />}
/>,
);
});
}
});
};

const renderCitizenshipFilters = (citizenshipFilters: Record<CitizenLabels, boolean>) => {
if (citizenshipFilters.green_card) {
return renderMainAndSubFilters(citizenshipFilters);
} else {
return renderMainFilters(citizenshipFilters);
}
return filters;
};

return (
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {
gc_5plus: false,
gc_18plus_no5: false,
gc_under18_no5: false,
gc_under19_pregnant_no5: false,
refugee: false,
other: false,
otherWithWorkPermission: false,
otherHealthCareUnder19: false,
otherHealthCarePregnant: false,
});
const categoryState = useState('All Categories');
const eligibilityState = useState('eligibleBenefits');
Expand Down
Loading