Skip to content

Commit

Permalink
Merge pull request #2254 from HHS/main
Browse files Browse the repository at this point in the history
[Prod] Minimize data flows when saving goals on the activity report, correct monitoring configuration, fix bug in create goals hook
  • Loading branch information
Jones-QuarteyDana authored Jul 9, 2024
2 parents 3acb757 + a7c685b commit b9bf534
Show file tree
Hide file tree
Showing 14 changed files with 688 additions and 426 deletions.
24 changes: 1 addition & 23 deletions frontend/src/components/Navigator/ActivityReportNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { saveGoalsForReport, saveObjectivesForReport } from '../../fetchers/acti
import GoalFormContext from '../../GoalFormContext';
import { validateObjectives } from '../../pages/ActivityReport/Pages/components/objectiveValidator';
import AppLoadingContext from '../../AppLoadingContext';
import { convertGoalsToFormData } from '../../pages/ActivityReport/formDataHelpers';
import { convertGoalsToFormData, packageGoals } from '../../pages/ActivityReport/formDataHelpers';
import { objectivesWithValidResourcesOnly, validateListOfResources } from '../GoalForm/constants';
import Navigator from '.';

Expand Down Expand Up @@ -66,28 +66,6 @@ export function getPromptErrors(promptTitles, errors) {

export const formatEndDate = (formEndDate) => ((formEndDate && formEndDate.toLowerCase() !== 'invalid date') ? formEndDate : '');

export const packageGoals = (goals, goal, grantIds, prompts) => {
const packagedGoals = [
// we make sure to mark all the read only goals as "ActivelyEdited: false"
...goals.map((g) => ({
...g,
grantIds,
isActivelyBeingEditing: false,
prompts: grantIds.length < 2 ? g.prompts : [],
})),
];

if (goal && goal.name) {
packagedGoals.push({
...goal,
grantIds,
prompts: grantIds.length < 2 ? prompts : [],
});
}

return packagedGoals;
};

/**
* @summary checks to see if the tta provided field contains the cursor
* if it does, we don't want to update the form data
Expand Down
131 changes: 0 additions & 131 deletions frontend/src/components/Navigator/__tests__/ActivityReportNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useFormContext } from 'react-hook-form';
import Navigator, {
getPrompts,
getPromptErrors,
packageGoals,
shouldUpdateFormData,
formatEndDate,
} from '../ActivityReportNavigator';
Expand Down Expand Up @@ -476,133 +475,3 @@ describe('getPromptErrors', () => {
expect(getPromptErrors(null, errors)).toBe(false);
});
});

describe('packageGoals', () => {
it('correctly formats goals with multiple recipients', () => {
const grantIds = [1, 2];
const packagedGoals = packageGoals(
[
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
},
],
{
name: 'recipient',
endDate: '09/01/2020',
isActivelyBeingEditing: true,
},
grantIds,
[{ fieldName: 'prompt2' }],
);

expect(packagedGoals).toEqual([
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [],
grantIds,
isActivelyBeingEditing: false,
},
{
name: 'recipient',
endDate: '09/01/2020',
isActivelyBeingEditing: true,
grantIds,
prompts: [],
},
]);
});

it('correctly formats goals for a single recipient', () => {
const grantIds = [1];
const packagedGoals = packageGoals(
[
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
},
],
{
name: 'recipient',
endDate: '09/01/2020',
isActivelyBeingEditing: true,
},
grantIds,
[{ fieldName: 'prompt2' }],
);

expect(packagedGoals).toEqual([
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
grantIds,
isActivelyBeingEditing: false,
},
{
name: 'recipient',
endDate: '09/01/2020',
isActivelyBeingEditing: true,
grantIds,
prompts: [{ fieldName: 'prompt2' }],
},
]);
});
it('skips returning edited goal if edited goal is null', () => {
const grantIds = [1];
const packagedGoals = packageGoals(
[
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
},
],
null,
grantIds,
[{ fieldName: 'prompt2' }],
);

expect(packagedGoals).toEqual([
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
grantIds,
isActivelyBeingEditing: false,
},
]);
});
it('skips returning edited goal if edited goal has no name', () => {
const grantIds = [1];
const packagedGoals = packageGoals(
[
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
},
],
{
name: '',
endDate: '',
isActivelyBeingEditing: true,
},
grantIds,
[{ fieldName: 'prompt2' }],
);

expect(packagedGoals).toEqual([
{
name: 'goal name',
endDate: '09/01/2020',
prompts: [{ fieldName: 'prompt' }],
grantIds,
isActivelyBeingEditing: false,
},
]);
});
});
Loading

0 comments on commit b9bf534

Please sign in to comment.