Skip to content

Commit

Permalink
Merge pull request #1910 from bcgov/feat/clearer-diffs
Browse files Browse the repository at this point in the history
Feat/clearer diffs
  • Loading branch information
mikevespi authored May 24, 2024
2 parents b508184 + 9c065d0 commit 74fdbe9
Show file tree
Hide file tree
Showing 26 changed files with 556 additions and 888 deletions.
8 changes: 8 additions & 0 deletions app/components/Attachment/AttachmentTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props {
formChangeRowId: number;
hideDelete?: boolean;
isFirstRevision: boolean;
operation?: string;
}

const AttachmentTableRow: React.FC<Props> = ({
Expand All @@ -21,6 +22,7 @@ const AttachmentTableRow: React.FC<Props> = ({
formChangeRowId,
hideDelete,
isFirstRevision,
operation,
}) => {
const [
discardProjectAttachmentFormChange,
Expand Down Expand Up @@ -65,6 +67,12 @@ const AttachmentTableRow: React.FC<Props> = ({
return (
<>
<tr>
{operation && (
<td>
{operation.charAt(0).toUpperCase() +
operation.slice(1).toLowerCase()}
</td>
)}
<td>{fileName}</td>
<td>{fileType}</td>
<td>{fileSize}</td>
Expand Down
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
37 changes: 23 additions & 14 deletions app/components/Form/ProjectAnnualReportFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
isPristine
newFormData
operation
formChangeByPreviousFormChangeId {
newFormData
}
formByJsonSchemaName {
jsonSchema
}
Expand Down Expand Up @@ -93,6 +90,21 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
return [filteredReports];
}, [annualReportFormChanges]);

let latestCommittedReports = latestCommittedAnnualReportFormChanges.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]);

const allFormChangesPristine = useMemo(
() =>
!annualReportFormChanges.some(
Expand All @@ -103,6 +115,10 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({

const annualReportsJSX = useMemo(() => {
return sortedAnnualReports.map((annualReport, index) => {
const latestCommittedData =
latestCommittedReportMap[
annualReport.newFormData.reportingRequirementIndex
];
if (!annualReport) return;
// Set the formSchema and formData based on showing the diff or not
const { formSchema, formData } = !renderDiff
Expand All @@ -112,7 +128,8 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
}
: getFilteredSchema(
annualReport.formByJsonSchemaName.jsonSchema.schema as JSONSchema7,
annualReport
annualReport,
latestCommittedData
);

if (
Expand All @@ -122,13 +139,6 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
)
return null;

const latestCommittedData =
latestCommittedAnnualReportFormChanges?.edges?.find(
({ node }) =>
node.newFormData.reportingRequirementIndex ===
annualReport.newFormData.reportingRequirementIndex
)?.node?.newFormData;

return (
<div key={index} className="reportContainer">
<header>
Expand Down Expand Up @@ -162,9 +172,7 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
uiSchema={reportingRequirementUiSchema}
formContext={{
operation: annualReport.operation,
oldData:
annualReport.formChangeByPreviousFormChangeId?.newFormData,
latestCommittedData,
latestCommittedData: latestCommittedData?.newFormData,
isAmendmentsAndOtherRevisionsSpecific:
isOnAmendmentsAndOtherRevisionsPage,
}}
Expand All @@ -183,6 +191,7 @@ const ProjectAnnualReportFormSummary: React.FC<Props> = ({
isOnAmendmentsAndOtherRevisionsPage,
renderDiff,
sortedAnnualReports,
latestCommittedReportMap,
]);

// Update the hasDiff state in the CollapsibleFormWidget to define if the form has diffs to show
Expand Down
3 changes: 2 additions & 1 deletion app/components/Form/ProjectAttachmentsFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FormNotAddedOrUpdated } from "./SummaryFormCommonComponents";
import { useEffect, useMemo } from "react";

const tableFilters = [
new TextFilter("Operation", "operation"),
new TextFilter("File Name", "fileName"),
new TextFilter("Type", "type"),
new TextFilter("Size", "size"),
Expand Down Expand Up @@ -36,7 +37,6 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
summaryProjectAttachmentFormChanges: formChangesFor(
first: 500
formDataTableName: "project_attachment"
filter: { operation: { notEqualTo: ARCHIVE } }
) @connection(key: "connection_summaryProjectAttachmentFormChanges") {
__id
totalCount
Expand Down Expand Up @@ -115,6 +115,7 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
({ node }) => (
<AttachmentTableRow
key={node.id}
operation={node.operation}
attachment={node.asProjectAttachment.attachmentByAttachmentId}
formChangeRowId={node.rowId}
connectionId={revision.summaryProjectAttachmentFormChanges.__id}
Expand Down
22 changes: 1 addition & 21 deletions app/components/Form/ProjectContactFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ const ProjectContactFormSummary: React.FC<Props> = ({
...ContactDetails_contact
}
}
formChangeByPreviousFormChangeId {
newFormData
asProjectContact {
contactByContactId {
fullName
}
}
}
formByJsonSchemaName {
jsonSchema
}
Expand Down Expand Up @@ -181,11 +173,6 @@ const ProjectContactFormSummary: React.FC<Props> = ({
formData={node.newFormData}
formContext={{
operation: node.operation,
oldData: node.formChangeByPreviousFormChangeId?.newFormData,
oldUiSchema: createProjectContactUiSchema(
node?.formChangeByPreviousFormChangeId?.asProjectContact
?.contactByContactId?.fullName
),
latestCommittedData:
latestCommittedContactNode?.node?.newFormData,
latestCommittedUiSchema,
Expand All @@ -205,7 +192,7 @@ const ProjectContactFormSummary: React.FC<Props> = ({
secondaryContacts,
renderDiff,
isOnAmendmentsAndOtherRevisionsPage,
summaryContactFormChanges,
lastCommittedSecondaryContacts,
]);

// Update the hasDiff state in the CollapsibleFormWidget to define if the form has diffs to show
Expand Down Expand Up @@ -260,13 +247,6 @@ const ProjectContactFormSummary: React.FC<Props> = ({
formData={primaryContact ? primaryContact.node.newFormData : null}
formContext={{
operation: primaryContact?.node.operation,
oldData:
primaryContact?.node.formChangeByPreviousFormChangeId
?.newFormData,
oldUiSchema: createProjectContactUiSchema(
primaryContact?.node?.formChangeByPreviousFormChangeId
?.asProjectContact?.contactByContactId?.fullName
),
latestCommittedData:
lastCommittedPrimaryContact?.node?.newFormData,
latestCommittedUiSchema: createProjectContactUiSchema(
Expand Down
31 changes: 3 additions & 28 deletions app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,12 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
formByJsonSchemaName {
jsonSchema
}
formChangeByPreviousFormChangeId {
newFormData
calculatedEiPerformance
paymentPercentage
maximumPerformanceMilestoneAmount
actualPerformanceMilestoneAmount
}
}
}
}
latestCommittedEmissionIntensityReportFormChange: latestCommittedFormChangesFor(
formDataTableName: "emission_intensity_report"
formDataTableName: "reporting_requirement"
reportType: "TEIMP"
) {
edges {
node {
Expand Down Expand Up @@ -97,24 +91,6 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
summaryReportingRequirement?.actualPerformanceMilestoneAmount,
};

const oldData = {
...summaryReportingRequirement?.formChangeByPreviousFormChangeId
?.newFormData,
//calculated values
calculatedEiPerformance:
summaryReportingRequirement?.formChangeByPreviousFormChangeId
?.calculatedEiPerformance,
paymentPercentage:
summaryReportingRequirement?.formChangeByPreviousFormChangeId
?.paymentPercentage,
maximumPerformanceMilestoneAmount:
summaryReportingRequirement?.formChangeByPreviousFormChangeId
?.maximumPerformanceMilestoneAmount,
actualPerformanceMilestoneAmount:
summaryReportingRequirement?.formChangeByPreviousFormChangeId
?.actualPerformanceMilestoneAmount,
};

const latestCommittedData = {
...latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.newFormData,
Expand Down Expand Up @@ -147,7 +123,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
const filteredSchema = getSchemaAndDataIncludingCalculatedValues(
emissionIntensityFormBySlug.jsonSchema.schema as JSONSchema7,
newData,
oldData,
latestCommittedData,
{
// This is only to add the (Adjusted) to the title of the field to differentiate it from the calculated field
adjustedEmissionsIntensityPerformance: {
Expand Down Expand Up @@ -265,7 +241,6 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
actualPerformanceMilestoneAmount:
summaryReportingRequirement?.actualPerformanceMilestoneAmount,
operation: summaryReportingRequirement?.operation,
oldData,
latestCommittedData,
isAmendmentsAndOtherRevisionsSpecific:
isOnAmendmentsAndOtherRevisionsPage,
Expand Down
51 changes: 8 additions & 43 deletions app/components/Form/ProjectFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ const ProjectFormSummary: React.FC<Props> = ({
name
}
}
formChangeByPreviousFormChangeId {
rank
newFormData
asProject {
operatorByOperatorId {
legalName
bcRegistryId
}
fundingStreamRfpByFundingStreamRfpId {
year
fundingStreamByFundingStreamId {
description
}
}
projectStatusByProjectStatusId {
name
}
}
}
}
latestCommittedProjectFormChanges: latestCommittedFormChangesFor(
formDataTableName: "project"
Expand Down Expand Up @@ -110,30 +91,16 @@ const ProjectFormSummary: React.FC<Props> = ({
// Show diff if it is not the first revision and not view only (rendered from the overview page)
const renderDiff = !isFirstRevision && !viewOnly;

const oldData = {
...projectFormChange.formChangeByPreviousFormChangeId?.newFormData,
rank: projectFormChange.formChangeByPreviousFormChangeId?.rank,
};

const newDataAsProject = projectFormChange.asProject;
const previousDataAsProject =
projectFormChange.formChangeByPreviousFormChangeId?.asProject;

const oldUiSchema = previousDataAsProject
? createProjectUiSchema(
previousDataAsProject.operatorByOperatorId.legalName,
`${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`,
previousDataAsProject.operatorByOperatorId.bcRegistryId,
previousDataAsProject.projectStatusByProjectStatusId.name
)
: null;

const latestCommittedUiSchema = latestCommittedData?.asProject
const latestCommittedAsProject =
latestCommittedProjectFormChanges?.edges[0]?.node?.asProject;
const latestCommittedUiSchema = latestCommittedAsProject
? createProjectUiSchema(
latestCommittedData.asProject.operatorByOperatorId.legalName,
`${latestCommittedData.asProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${latestCommittedData.asProject?.fundingStreamRfpByFundingStreamRfpId?.year}`,
latestCommittedData.asProject.operatorByOperatorId.bcRegistryId,
latestCommittedData.asProject.projectStatusByProjectStatusId.name
latestCommittedAsProject.operatorByOperatorId.legalName,
`${latestCommittedAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${latestCommittedAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`,
latestCommittedAsProject.operatorByOperatorId.bcRegistryId,
latestCommittedAsProject.projectStatusByProjectStatusId.name
)
: null;

Expand All @@ -148,7 +115,7 @@ const ProjectFormSummary: React.FC<Props> = ({
projectSchema as JSONSchema7,

{ ...projectFormChange?.newFormData, rank: projectFormChange.rank },
oldData,
latestCommittedData,
{
rank: {
type: "number",
Expand Down Expand Up @@ -199,8 +166,6 @@ const ProjectFormSummary: React.FC<Props> = ({
formData={formData}
formContext={{
calculatedRank: projectFormChange.rank,
oldData,
oldUiSchema,
latestCommittedData,
latestCommittedUiSchema,
operation: projectFormChange.operation,
Expand Down
Loading

0 comments on commit 74fdbe9

Please sign in to comment.