Skip to content

Commit

Permalink
chore: use latest committed data to filter milestone schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevespi committed May 19, 2024
1 parent 934b5a5 commit 71a3dfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/components/Form/Functions/getMilestoneFilteredSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { JSONSchema7 } from "json-schema";
*/
export const getMilestoneFilteredSchema = (
formSchema: JSONSchema7,
formChange
formChange,
latestCommittedFormChange
) => {
const properties = formSchema.properties;
// schema dependencies
Expand All @@ -37,7 +38,7 @@ export const getMilestoneFilteredSchema = (
for (const key of Object.keys(filteredSchema.properties)) {
const [updatedFormData, prevFormData] = [
formChange?.newFormData?.[key],
formChange?.formChangeByPreviousFormChangeId?.newFormData?.[key],
latestCommittedFormChange?.newFormData?.[key],
];
if (
updatedFormData === prevFormData ||
Expand Down
20 changes: 19 additions & 1 deletion app/components/Form/ProjectMilestoneReportFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ const ProjectMilestoneReportFormSummary: React.FC<Props> = ({
({ node }) => node.operation !== "ARCHIVE"
);

let latestCommittedReports = latestCommittedMilestoneFormChanges.edges;
const latestCommittedReportMap = useMemo(() => {
const filteredReports = latestCommittedReports.map(({ node }) => node);

const reportMap = filteredReports.reduce(
(reports, current) => (
(reports[current.newFormData.reportingRequirementIndex] = current),
reports
),
{}
);

return reportMap;
}, [latestCommittedReports]);

// Sort consolidated milestone form change records
const [sortedMilestoneReports] = useMemo(() => {
return getSortedReports(milestoneReportFormChanges, true);
Expand Down Expand Up @@ -139,7 +154,10 @@ const ProjectMilestoneReportFormSummary: React.FC<Props> = ({
},
{
...milestoneReport,
}
},
latestCommittedReportMap[
milestoneReport.newFormData.reportingRequirementIndex
]
)
: {
formSchema: milestoneReport.formByJsonSchemaName.jsonSchema.schema,
Expand Down

0 comments on commit 71a3dfd

Please sign in to comment.