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

Feat/updated citizen filters #650

Merged
merged 26 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
69557fd
Update filter label text
ivonne-hernandez Oct 11, 2023
326b0e5
Add FM msg header to citizen popover
ivonne-hernandez Oct 11, 2023
5313e50
Rm citizen from citizenshipFilterIsChecked state
ivonne-hernandez Oct 11, 2023
daf5744
Add hasAtLeastOneCitizenshipFilter func
ivonne-hernandez Oct 11, 2023
6a747bf
Add if/else case to handleFilterSelect to fix no results table when n…
ivonne-hernandez Oct 11, 2023
9a087c4
Move refugee option to the end of the list
ivonne-hernandez Oct 12, 2023
dc18592
Add renderCitizenshipFilters function
ivonne-hernandez Oct 12, 2023
f3a49c8
Replace citCheckboxFilters call with renderCitFilts
ivonne-hernandez Oct 12, 2023
160af28
Add type to initialThreeFilters
ivonne-hernandez Oct 12, 2023
b947614
Move refugee var down the list to display as requested
ivonne-hernandez Oct 12, 2023
460b0a3
Add css file for citizenship popover
ivonne-hernandez Oct 12, 2023
578a14a
Add indentation to gc sub categories
ivonne-hernandez Oct 12, 2023
6f8dbd5
Add if stmt to handleFilterSelect when citType is green_card
ivonne-hernandez Oct 12, 2023
af89b0a
Refactor isGreenCardSubCitizenshipType variable
ivonne-hernandez Oct 12, 2023
a0e00b3
Fix formatting
ivonne-hernandez Oct 12, 2023
c962729
Refactored renderCitizenshipFilters if/else stmt
ivonne-hernandez Oct 12, 2023
a86c83b
Update the header calculations
ivonne-hernandez Oct 12, 2023
18cbff1
Change variable names
ivonne-hernandez Oct 12, 2023
c887fbf
Add totalVisibleRowDollarValue for categories
ivonne-hernandez Oct 12, 2023
46f2bbb
Refactor initialThreeFilters TS declaration
ivonne-hernandez Oct 13, 2023
9fe8039
Update the categoryValues function
ivonne-hernandez Oct 13, 2023
3a37af4
Remove comment and space
ivonne-hernandez Oct 13, 2023
ea02238
Add cappedCatValuesTotalDollarAmount in useEffect
ivonne-hernandez Oct 13, 2023
57a9ada
Added a cap to total dollar val when filt.category is childcare
ivonne-hernandez Oct 13, 2023
8705a83
Fix formatting
ivonne-hernandez Oct 13, 2023
ecdfd9a
Update and use the preschoolProgramCategory var
ivonne-hernandez Oct 13, 2023
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
41 changes: 12 additions & 29 deletions src/Assets/citizenshipFilterFormControlLabels.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FormattedMessage } from 'react-intl';

export type CitizenLabels =
| 'citizen'
| 'non_citizen'
| 'green_card'
| 'refugee'
Expand All @@ -11,52 +10,36 @@ export type CitizenLabels =
| 'gc_under19_pregnant_no5';

const citizenshipFilterFormControlLabels = {
citizen: (
<FormattedMessage
id="citizenshipFCtrlLabel-citizen"
defaultMessage="Show benefits that require citizenship or lawful U.S. presence"
/>
),
non_citizen: (
<FormattedMessage
id="citizenshipFCtrlLabel-non_citizen"
defaultMessage="Show benefits that do not require citizenship or lawful U.S. presence"
/>
),
green_card: (
<FormattedMessage
id="citizenshipFCtrlLabel-green_card"
defaultMessage="Show benefits available to green card holders"
/>
),
refugee: (
<FormattedMessage
id="citizenshipFCtrlLabel-refugee"
defaultMessage="Show benefits available to refugees or asylees (special rules or waiting periods may apply)"
/>
),
gc_5plus: (
<FormattedMessage
id="citizenshipFCtrlLabel-gc_5plus"
defaultMessage="Show benefits available to green card holders ONLY after 5+ years in the U.S."
defaultMessage="Individuals without citizenship or lawful U.S. presence"
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
/>
),
green_card: <FormattedMessage id="citizenshipFCtrlLabel-green_card" defaultMessage="Green card holders" />,
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
gc_5plus: <FormattedMessage id="citizenshipFCtrlLabel-gc_5plus" defaultMessage="ONLY after 5+ years in the U.S." />,
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
gc_18plus_no5: (
<FormattedMessage
id="citizenshipFCtrlLabel-gc_18plus_no5"
defaultMessage="Show benefits available to green card holders 18 or older without a 5-year waiting period"
defaultMessage="18 or older without a 5-year waiting period"
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
/>
),
gc_under18_no5: (
<FormattedMessage
id="citizenshipFCtrlLabel-gc_under18_no5"
defaultMessage="Show benefits available to green card holders younger than 18 without a 5-year waiting period"
defaultMessage="younger than 18 without a 5-year waiting period"
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
/>
),
gc_under19_pregnant_no5: (
<FormattedMessage
id="citizenshipFCtrlLabel-gc_under19_pregnant_no5"
defaultMessage="Show health care benefits available to green card holders younger than 19 or pregnant without a 5-year waiting period"
defaultMessage="for health care benefits - younger than 19 or pregnant without a 5-year waiting period"
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
/>
),
refugee: (
<FormattedMessage
id="citizenshipFCtrlLabel-refugee"
defaultMessage="Refugees or asylees (special rules or waiting periods may apply)"
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
/>
),
};
Expand Down
3 changes: 3 additions & 0 deletions src/Components/FilterSection/CitizenshipPopover.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.MuiFormControlLabel-root.gc-subcitizen-indentation {
margin-left: 1.25rem;
}
133 changes: 106 additions & 27 deletions src/Components/FilterSection/CitizenshipPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { FormattedMessage } from 'react-intl';
import FormControlLabel from '@mui/material/FormControlLabel';
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 type { CitizenLabels } from '../../Assets/citizenshipFilterFormControlLabels';
import './CitizenshipPopover.css';

export const citizenshipFilterOperators: GridFilterOperator[] = [
{
Expand Down Expand Up @@ -39,49 +41,126 @@ const CitizenshipPopover = ({
citizenshipFilterIsChecked,
setCitizenshipFilterIsChecked,
}: CitizenshipPopoverProps) => {
const hasAtLeastOneCitizenshipFilter = (currentCitizenshipFilters: Record<CitizenLabels, boolean>) => {
const citizenshipFilterValues = Object.values(currentCitizenshipFilters);

return citizenshipFilterValues.some((citizenshipFilterValue) => {
return citizenshipFilterValue === true;
});
};

const handleFilterSelect = (citizenshipType: CitizenLabels) => {
const isChecked = citizenshipFilterIsChecked[citizenshipType];

const updatedCitizenshipFilterIsChecked: Record<CitizenLabels, boolean> = {
let 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,
};
}
const typedUpdatedCitizenshipFilterIsChecked = Object.keys(updatedCitizenshipFilterIsChecked) as CitizenLabels[];
const selectedCitizenshipFilters = typedUpdatedCitizenshipFilterIsChecked.filter((citizenshipType) => {
return updatedCitizenshipFilterIsChecked[citizenshipType];
});

updateFilter({
name: 'citizen',
filter: {
id: 1,
columnField: 'citizenship',
operatorValue: 'customCitizenshipOperator',
value: selectedCitizenshipFilters,
},
});
//update the MUI filter that is being passed to the citizenship column
if (hasAtLeastOneCitizenshipFilter(updatedCitizenshipFilterIsChecked)) {
updateFilter({
name: 'citizen',
filter: {
id: 1,
columnField: 'citizenship',
operatorValue: 'customCitizenshipOperator',
value: selectedCitizenshipFilters,
},
});
} else {
// set the citizenship filter back to the default
updateFilter({
name: 'citizen',
filter: {
id: 1,
columnField: 'citizenship',
operatorValue: 'customCitizenshipOperator',
value: ['citizen'],
},
});
}

//update citizenshipFilterIsChecked state
setCitizenshipFilterIsChecked(updatedCitizenshipFilterIsChecked);
};

const typedCitizenshipFilterIsChecked = Object.keys(citizenshipFilterIsChecked) as CitizenLabels[];
const citizenshipCheckboxFilters = typedCitizenshipFilterIsChecked.map((citizenshipType) => {
return (
<FormControlLabel
key={citizenshipType}
className="popover"
label={citizenshipFilterFormControlLabels[citizenshipType]}
control={
<Checkbox
checked={citizenshipFilterIsChecked[citizenshipType]}
onChange={() => handleFilterSelect(citizenshipType)}
/>
}
/>
);
});

return <Stack>{citizenshipCheckboxFilters}</Stack>;

const renderMainAndSubFilters = (citizenshipFilters: Record<CitizenLabels, boolean>) => {
return typedCitizenshipFilterIsChecked.map((citizenshipType) => {
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
//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);

ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
return (
<FormControlLabel
key={citizenshipType}
className={isGreenCardSubCitizenshipType ? 'gc-subcitizen-indentation' : ''}
label={citizenshipFilterFormControlLabels[citizenshipType]}
control={
<Checkbox
checked={citizenshipFilters[citizenshipType]}
onChange={() => handleFilterSelect(citizenshipType)}
/>
}
/>
);
});
};

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)} />
}
/>
);
});
};

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

return (
<Stack sx={{ padding: '0.5rem', gap: '0.25rem', ml: '0.5rem' }}>
<Stack sx={{ color: '#000000', fontWeight: 500, mt: '.5rem' }}>
<FormattedMessage id="citizenshipPopover.showBenefits" defaultMessage="Show benefits available to:" />
ivonne-hernandez marked this conversation as resolved.
Show resolved Hide resolved
</Stack>
<Stack>{renderCitizenshipFilters(citizenshipFilterIsChecked)}</Stack>
</Stack>
);
};

export default CitizenshipPopover;
3 changes: 1 addition & 2 deletions src/Components/FilterSection/FilterSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ const FilterSection = ({
//this resets the radio buttons
setCitizenshipFilterIsChecked({
non_citizen: false,
citizen: true,
green_card: false,
refugee: false,
gc_5plus: false,
gc_18plus_no5: false,
gc_under18_no5: false,
gc_under19_pregnant_no5: false,
refugee: false,
});
categoryState[1]('All Categories');
eligibilityState[1]('eligibleBenefits');
Expand Down
Loading
Loading