Skip to content

Commit

Permalink
fix: show diffs triggered by milestone changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Jul 26, 2023
1 parent 6a9c054 commit 74b7d0c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
67 changes: 39 additions & 28 deletions app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import {
FormNotAddedOrUpdated,
FormRemoved,
} from "./SummaryFormCommonComponents";
import { ProjectEmissionIntensityReportFormSummary_query$key } from "__generated__/ProjectEmissionIntensityReportFormSummary_query.graphql";
const { fields } = utils.getDefaultRegistry();

interface Props
extends SummaryFormProps<ProjectEmissionIntensityReportFormSummary_projectRevision$key> {}
extends SummaryFormProps<ProjectEmissionIntensityReportFormSummary_projectRevision$key> {
query: ProjectEmissionIntensityReportFormSummary_query$key;
}

const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
projectRevision,
viewOnly,
isOnAmendmentsAndOtherRevisionsPage,
setHasDiff,
query,
}) => {
const {
summaryEmissionIntensityReportingRequirementFormChange,
Expand All @@ -44,7 +48,6 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
actualPerformanceMilestoneAmount
newFormData
operation
isPristine
formByJsonSchemaName {
jsonSchema
}
Expand Down Expand Up @@ -129,14 +132,39 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
?.actualPerformanceMilestoneAmount,
};

const allFormChangesPristine = useMemo(() => {
if (
summaryReportingRequirement?.isPristine === false ||
summaryReportingRequirement?.isPristine === null
)
return false;
return true;
}, [summaryReportingRequirement?.isPristine]);
const { emissionIntensityFormBySlug } = useFragment(
graphql`
fragment ProjectEmissionIntensityReportFormSummary_query on Query {
emissionIntensityFormBySlug: formBySlug(slug: "emission_intensity") {
jsonSchema
}
}
`,
query
);

const filteredSchema = getSchemaAndDataIncludingCalculatedValues(
emissionIntensityFormBySlug.jsonSchema.schema as JSONSchema7,
newData,
oldData,
{
// This is only to add the (Adjusted) to the title of the field to differentiate it from the calculated field
adjustedEmissionsIntensityPerformance: {
title: "GHG Emission Intensity Performance (Adjusted)",
type: "number",
},
// Add calculatedEiPerformance to the schema since this field is using `AdjustableCalculatedValueWidget` and is not directly in the schema
calculatedEiPerformance: {
type: "number",
title: "GHG Emission Intensity Performance",
},
}
);

const allFormChangesPristine = useMemo(
() => Object.keys(filteredSchema.formData).length === 0,
[filteredSchema.formData]
);

// Update the hasDiff state in the CollapsibleFormWidget to define if the form has diffs to show
useEffect(
Expand Down Expand Up @@ -167,24 +195,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
.schema as JSONSchema7,
formData: summaryReportingRequirement?.newFormData,
}
: getSchemaAndDataIncludingCalculatedValues(
summaryReportingRequirement.formByJsonSchemaName.jsonSchema
?.schema as JSONSchema7,
newData,
oldData,
{
// This is only to add the (Adjusted) to the title of the field to differentiate it from the calculated field
adjustedEmissionsIntensityPerformance: {
title: "GHG Emission Intensity Performance (Adjusted)",
type: "number",
},
// Add calculatedEiPerformance to the schema since this field is using `AdjustableCalculatedValueWidget` and is not directly in the schema
calculatedEiPerformance: {
type: "number",
title: "GHG Emission Intensity Performance",
},
}
);
: filteredSchema;

// Set custom rjsf fields to display diffs
const customFields = { ...fields, ...CUSTOM_DIFF_FIELDS };
Expand Down
2 changes: 2 additions & 0 deletions app/pages/cif/project-revision/[projectRevision]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const EditProjectRevisionQuery = graphql`
}
# eslint-disable-next-line relay/must-colocate-fragment-spreads
...ProjectFundingAgreementFormSummary_query
# eslint-disable-next-line relay/must-colocate-fragment-spreads
...ProjectEmissionIntensityReportFormSummary_query
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const pageQuery = graphql`
...ProjectFundingAgreementForm_query
...ProjectFundingAgreementFormSummary_query
...ProjectEmissionIntensityReportForm_query
...ProjectEmissionIntensityReportFormSummary_query
...ProjectEmissionIntensityReportFormSummary_query
}
}
`;
Expand Down
2 changes: 2 additions & 0 deletions app/pages/cif/project-revision/[projectRevision]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const pageQuery = graphql`
}
}
...ProjectFundingAgreementFormSummary_query
...ProjectEmissionIntensityReportFormSummary_query
}
}
`;
Expand Down Expand Up @@ -242,6 +243,7 @@ export function ProjectRevision({
/>
<ProjectEmissionsIntensityReportFormSummary
projectRevision={query.projectRevision}
query={query}
/>
<ProjectAnnualReportFormSummary
projectRevision={query.projectRevision}
Expand Down
2 changes: 2 additions & 0 deletions app/pages/cif/project-revision/[projectRevision]/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const ViewProjectRevisionQuery = graphql`
}
# eslint-disable-next-line relay/must-colocate-fragment-spreads
...ProjectFundingAgreementFormSummary_query
# eslint-disable-next-line relay/must-colocate-fragment-spreads
...ProjectEmissionIntensityReportFormSummary_query
}
`;

Expand Down

0 comments on commit 74b7d0c

Please sign in to comment.