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

Refactor/childcare cat header value #729

Merged
merged 5 commits into from
Nov 14, 2023
Merged
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
42 changes: 28 additions & 14 deletions src/Components/Results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {
}
});

//used categoryValues(eligiblePrograms) instead of the real total to take into account the preschool category value cap at 8640
const allCategoriesAndValuesObjCappedForPreschool = categoryValues(eligiblePrograms);
//used renderAllCategoryValues(eligiblePrograms) instead of the real total to take into account the preschool/childCare category value cap at 8640
const allCategoriesAndValuesObjCappedForPreschool = renderAllCategoryValues(eligiblePrograms);
const totalCashAndTaxCreditValues = Object.entries(allCategoriesAndValuesObjCappedForPreschool).reduce(
(acc, categoryAndValueArr) => {
const categoryName = categoryAndValueArr[0];
Expand Down Expand Up @@ -190,8 +190,10 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {

//this is only to cap the totalVisibleRowDollarValue for preschool
const typedFiltCategory = filt.category as GridFilterItem;
if (typedFiltCategory.value === preschoolProgramCategoryString && updatedTotalEligibleDollarValue > 8640) {
setTotalVisibleRowDollarValue(8640);
if (typedFiltCategory.value === childCareYouthAndEducationCategoryString) {
const childCareYouthAndEducationDollarValue =
renderAllCategoryValues(eligiblePrograms)[childCareYouthAndEducationCategoryString];
setTotalVisibleRowDollarValue(childCareYouthAndEducationDollarValue);
return;
}

Expand Down Expand Up @@ -247,11 +249,16 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {
});
};

const preschoolProgramCategoryString = 'Child Care, Youth, and Education';
const categoryValues = (programs: Program[]) => {
const preschoolPrograms = { numOfPreSchoolPrograms: 0, totalEstVal: 0 };
const childCareYouthAndEducationCategoryString = 'Child Care, Youth, and Education';

const renderAllCategoryValues = (programs: Program[]) => {
let childCareTotalEstVal = 0;
let youthAndEducationTotalEstVal = 0;
const categoryValues: { [key: string]: number } = {};

for (let program of programs) {
const isPreschoolOrChildCareProgram = ['upk', 'dpp', 'chs', 'cccap'].includes(program.short_name);

//add this category to the categoryValues dictionary if the key doesn't already exist
if (categoryValues[program.category.default_message] === undefined) {
categoryValues[program.category.default_message] = 0;
Expand All @@ -265,18 +272,24 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {
//we add that program's est value to its corresponding categoryValues key
categoryValues[program.category.default_message] += program.estimated_value;

//if the program is a preschoolProgram, we also add it to the preschoolPrograms separately
if (program.category.default_message === preschoolProgramCategoryString) {
preschoolPrograms.numOfPreSchoolPrograms++;
preschoolPrograms.totalEstVal += program.estimated_value;
//if the program is in the preschoolProgramCategory, we also add it to the childCareTotalEstVal or youthAndEducationTotalEstVal separately
if (isPreschoolOrChildCareProgram) {
childCareTotalEstVal += program.estimated_value;
} else if (
program.category.default_message === childCareYouthAndEducationCategoryString &&
isPreschoolOrChildCareProgram === false
) {
youthAndEducationTotalEstVal += program.estimated_value;
}
}
}

if (preschoolPrograms.totalEstVal > 8640 && preschoolPrograms.numOfPreSchoolPrograms > 1) {
categoryValues[preschoolProgramCategoryString] = 8640;
if (childCareTotalEstVal > 8640) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to remove the logic for if there is one preschool program to not cap the value?

childCareTotalEstVal = 8640;
}

categoryValues[childCareYouthAndEducationCategoryString] = childCareTotalEstVal + youthAndEducationTotalEstVal;

return categoryValues;
};

Expand Down Expand Up @@ -719,7 +732,8 @@ const Results = ({ handleTextFieldChange }: ResultsProps) => {
</span>
</Toolbar>
{currentCategory.defaultMessage ===
categories.find((cat) => cat.defaultMessage === preschoolProgramCategoryString)?.defaultMessage && (
categories.find((cat) => cat.defaultMessage === childCareYouthAndEducationCategoryString)
?.defaultMessage && (
<Typography variant="body2" className="child-care-helper-text">
<FormattedMessage
id="benefitCategories.childCareHelperText"
Expand Down
Loading