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

Feat/clearer diffs #1910

Merged
merged 33 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
daed4ae
feat: switch diff fields to only show the latest committed, and what …
mikevespi May 10, 2024
8c17611
chore: remove the oldData from the summary form pages
mikevespi May 10, 2024
57a8439
test: update test cases, except for 0 handling
mikevespi May 10, 2024
39b5183
chore: fix the project status showing showing Not Entered for enterd …
mikevespi May 11, 2024
028d1a7
test: update form diff tests
mikevespi May 11, 2024
3d8e868
chore: linting
mikevespi May 13, 2024
b2b8e5c
test: update test data in project form summary test to be latest comm…
mikevespi May 13, 2024
6af5a63
test: fix project form summary tests to use latest committed data
mikevespi May 14, 2024
e4e9552
chore: switch contact summary form to use latest committed data only …
mikevespi May 15, 2024
ff88327
test: update manager and contact form summary tests to use latest com…
mikevespi May 15, 2024
333cc25
test: update manager form summary tests
mikevespi May 15, 2024
c148a65
chore: cleanup unused fields
mikevespi May 16, 2024
0e9b401
chore: update getFilteredSchema to require latest committed form change
mikevespi May 16, 2024
d55c607
chore: use latest committed form data with getFilteredSchema in annua…
mikevespi May 16, 2024
5d58192
test: use latest committed data for annual report summary tests
mikevespi May 16, 2024
c8b8790
chore: pre-commit run
mikevespi May 16, 2024
f50cb73
chore: fix incomplete reference in annual report form summary
mikevespi May 16, 2024
3aadc2a
chore: pass latest committed data to getFilteredSchema in quarterly r…
mikevespi May 17, 2024
5f9c67f
test: use latest committed form data in quarterly summary test
mikevespi May 17, 2024
daff5a2
chore: precommit run
mikevespi May 17, 2024
5c44705
chore: add latest committed data to getFilteredSchema call in Project…
mikevespi May 17, 2024
75e45b0
test: use latest committed data in quarterly summary test
mikevespi May 19, 2024
625f2c3
test: use latest committed data in emission intensity summary
mikevespi May 19, 2024
a09a6d9
chore: use latest committed data to filter milestone schemas
mikevespi May 19, 2024
770f85e
test: use latest committed data inmilestone summary tests
mikevespi May 20, 2024
0a50060
test: use latest committed data in collapsible form widget test
mikevespi May 20, 2024
8882143
chore: pre-commit run
mikevespi May 20, 2024
cfe1807
chore: fix filter on TEIMP summary query
mikevespi May 21, 2024
bca9aa1
chore: add attachments being archived to the summary page
mikevespi May 22, 2024
37928cf
chore: linting
mikevespi May 22, 2024
62785eb
test: add test for archived attachments in attachment summary form tests
mikevespi May 22, 2024
29a47b7
chore: missing dependency in useMemo call
mikevespi May 24, 2024
9c065d0
chore: update comments to no longer reflect 3 diffs scenario
mikevespi May 24, 2024
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
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() +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This will help clarify for our users

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"
Comment on lines +58 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug the whole time, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, so these would always have been showing up as new and the previous data in tests was always empty

) {
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
Loading