Skip to content

Commit

Permalink
feat: add calculated values diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepehr-Sobhani authored and dleard committed May 26, 2023
1 parent c84f34f commit e462a44
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 11 deletions.
77 changes: 70 additions & 7 deletions app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
edges {
node {
calculatedEiPerformance
paymentPercentage
holdbackAmountToDate
actualPerformanceMilestoneAmount
newFormData
operation
isPristine
formChangeByPreviousFormChangeId {
newFormData
calculatedEiPerformance
paymentPercentage
holdbackAmountToDate
actualPerformanceMilestoneAmount
}
}
}
Expand All @@ -87,6 +94,10 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
edges {
node {
newFormData
calculatedEiPerformance
paymentPercentage
holdbackAmountToDate
actualPerformanceMilestoneAmount
}
}
}
Expand All @@ -104,6 +115,42 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
const summaryEmissionIntensityReport =
summaryEmissionIntensityReportFormChange?.edges[0]?.node;

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

const latestCommittedData = {
...latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.newFormData,
//calculated values
calculatedEiPerformance:
latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.calculatedEiPerformance,
paymentPercentage:
latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.paymentPercentage,
holdbackAmountToDate:
latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.holdbackAmountToDate,
actualPerformanceMilestoneAmount:
latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.actualPerformanceMilestoneAmount,
};

// Set the formSchema and formData based on showing the diff or not
const reportingRequirementDiffObject = !renderDiff
? {
Expand All @@ -121,7 +168,21 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
formData: summaryEmissionIntensityReport?.newFormData,
}
: getFilteredEmissionIntensitySchema(
emissionIntensityReportSchema as JSONSchema7,
{
...emissionIntensityReportSchema,
properties: {
...emissionIntensityReportSchema.properties,
// Add calculatedEiPerformance to the schema since this field is using `AdjustableCalculatedValueWidget` and is not directly in the schema
calculatedValues: {
properties: {
calculatedEiPerformance: {
type: "number",
title: "GHG Emission Intensity Performance (Calculated)",
},
},
},
},
} as JSONSchema7,
summaryEmissionIntensityReport || {}
);

Expand Down Expand Up @@ -231,13 +292,15 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC<Props> = ({
formContext={{
calculatedEiPerformance:
summaryEmissionIntensityReport?.calculatedEiPerformance ?? 0,
paymentPercentageOfPerformanceMilestoneAmount:
summaryEmissionIntensityReport?.paymentPercentage,
maximumPerformanceMilestoneAmount:
summaryEmissionIntensityReport?.holdbackAmountToDate,
actualPerformanceMilestoneAmount:
summaryEmissionIntensityReport?.actualPerformanceMilestoneAmount,
operation: summaryEmissionIntensityReport?.operation,
oldData:
summaryEmissionIntensityReport?.formChangeByPreviousFormChangeId
?.newFormData,
latestCommittedData:
latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node
?.newFormData,
oldData,
latestCommittedData,
isAmendmentsAndOtherRevisionsSpecific:
isOnAmendmentsAndOtherRevisionsPage,
}}
Expand Down
16 changes: 12 additions & 4 deletions app/data/jsonSchemaForm/projectEmissionIntensitySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export const emissionIntensityReportSchema = {
title: "Date Invoice Sent to CSNR",
default: undefined,
},
paymentPercentageOfPerformanceMilestoneAmount: {
paymentPercentage: {
type: "number",
title: "Payment Percentage of Performance Milestone Amount (%)",
default: undefined,
},
maximumPerformanceMilestoneAmount: {
holdbackAmountToDate: {
type: "number",
title: "Maximum Performance Milestone Amount",
default: undefined,
Expand Down Expand Up @@ -152,7 +152,7 @@ export const emissionIntensityReportUiSchema = {
hideOptional: true,
calculatedValueFormContextProperty: "teimpPaymentPercentage",
},
paymentPercentageOfPerformanceMilestoneAmount: {
paymentPercentage: {
"ui:widget": "CalculatedValueWidget",
calculatedValueFormContextProperty:
"paymentPercentageOfPerformanceMilestoneAmount",
Expand All @@ -166,7 +166,7 @@ export const emissionIntensityReportUiSchema = {
isMoney: true,
hideOptional: true,
},
maximumPerformanceMilestoneAmount: {
holdbackAmountToDate: {
"ui:widget": "CalculatedValueWidget",
calculatedValueFormContextProperty: "maximumPerformanceMilestoneAmount",
isMoney: true,
Expand All @@ -176,6 +176,14 @@ export const emissionIntensityReportUiSchema = {
"ui:widget": "DateWidget",
},
},
calculatedValues: {
calculatedEiPerformance: {
"ui:widget": "NumberWidget",
hideOptional: true,
isPercentage: true,
numberOfDecimalPlaces: 2,
},
},
};

export const emissionIntensityReportingRequirementUiSchema = {
Expand Down

0 comments on commit e462a44

Please sign in to comment.