diff --git a/app/components/Form/Functions/getMilestoneFilteredSchema.ts b/app/components/Form/Functions/getMilestoneFilteredSchema.ts index ab9c85991b..f4de801d43 100644 --- a/app/components/Form/Functions/getMilestoneFilteredSchema.ts +++ b/app/components/Form/Functions/getMilestoneFilteredSchema.ts @@ -12,7 +12,8 @@ import { JSONSchema7 } from "json-schema"; */ export const getMilestoneFilteredSchema = ( formSchema: JSONSchema7, - formChange + formChange, + latestCommittedFormChange ) => { const properties = formSchema.properties; // schema dependencies @@ -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 || diff --git a/app/components/Form/ProjectMilestoneReportFormSummary.tsx b/app/components/Form/ProjectMilestoneReportFormSummary.tsx index 8f8e37c3e2..c0c5598990 100644 --- a/app/components/Form/ProjectMilestoneReportFormSummary.tsx +++ b/app/components/Form/ProjectMilestoneReportFormSummary.tsx @@ -83,6 +83,21 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ ({ 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); @@ -139,7 +154,10 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ }, { ...milestoneReport, - } + }, + latestCommittedReportMap[ + milestoneReport.newFormData.reportingRequirementIndex + ] ) : { formSchema: milestoneReport.formByJsonSchemaName.jsonSchema.schema,