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

[Prod] Minimize data flows when saving goals on the activity report, correct monitoring configuration, fix bug in create goals hook #2254

Merged
merged 19 commits into from
Jul 9, 2024
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
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