Skip to content

Commit

Permalink
feat: add project funding agreement form summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepehr-Sobhani committed Jul 8, 2022
1 parent 15163a4 commit 30a6bc3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 74 deletions.
112 changes: 38 additions & 74 deletions app/components/Form/ProjectFundingAgreementFormSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,125 +1,89 @@
import projectSchema from "data/jsonSchemaForm/projectSchema";
import fundingAgreementSchema from "data/jsonSchemaForm/fundingAgreementSchema";
import type { JSONSchema7 } from "json-schema";
import readOnlyTheme from "lib/theme/ReadOnlyTheme";
import { graphql, useFragment } from "react-relay";
import { ProjectFormSummary_projectRevision$key } from "__generated__/ProjectFormSummary_projectRevision.graphql";
import FormBase from "./FormBase";
import { createProjectUiSchema } from "./ProjectForm";

import CUSTOM_DIFF_FIELDS from "lib/theme/CustomDiffFields";
import { utils } from "@rjsf/core";
import { getFilteredSchema } from "lib/theme/getFilteredSchema";
import { ProjectFundingAgreementFormSummary_projectRevision$key } from "__generated__/ProjectFundingAgreementFormSummary_projectRevision.graphql";

const { fields } = utils.getDefaultRegistry();

interface Props {
projectRevision: ProjectFormSummary_projectRevision$key;
projectRevision: ProjectFundingAgreementFormSummary_projectRevision$key;
viewOnly?: boolean;
}

const ProjectFundingAgreementFormSummary: React.FC<Props> = (props) => {
const { projectFormChange, isFirstRevision } = useFragment(
graphql`
fragment ProjectFundingAgreementFormSummary_projectRevision on ProjectRevision {
isFirstRevision
projectFormChange {
newFormData
operation
isPristine
asProject {
operatorByOperatorId {
legalName
bcRegistryId
}
fundingStreamRfpByFundingStreamRfpId {
year
fundingStreamByFundingStreamId {
description
}
}
projectStatusByProjectStatusId {
name
}
}
formChangeByPreviousFormChangeId {
newFormData
asProject {
operatorByOperatorId {
legalName
bcRegistryId
}
fundingStreamRfpByFundingStreamRfpId {
year
fundingStreamByFundingStreamId {
description
const { summaryProjectFundingAgreementFormChanges, isFirstRevision } =
useFragment(
graphql`
fragment ProjectFundingAgreementFormSummary_projectRevision on ProjectRevision {
isFirstRevision
summaryProjectFundingAgreementFormChanges: formChangesFor(
formDataTableName: "funding_parameter"
) {
edges {
node {
newFormData
isPristine
operation
formChangeByPreviousFormChangeId {
newFormData
}
}
projectStatusByProjectStatusId {
name
}
}
}
}
}
`,
props.projectRevision
);
`,
props.projectRevision
);

// Show diff if it is not the first revision and not view only (rendered from the overview page)
const renderDiff = !isFirstRevision && !props.viewOnly;

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

const oldUiSchema = previousDataAsProject
? createProjectUiSchema(
previousDataAsProject.operatorByOperatorId.legalName,
previousDataAsProject.operatorByOperatorId.bcRegistryId,
`${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`,
previousDataAsProject.projectStatusByProjectStatusId.name
)
: null;
const fundingAgreementSummary =
summaryProjectFundingAgreementFormChanges.edges[0]?.node;

// Set the formSchema and formData based on showing the diff or not
const { formSchema, formData } = !renderDiff
? {
formSchema: projectSchema,
formData: projectFormChange.newFormData,
formSchema: fundingAgreementSchema,
formData: fundingAgreementSummary?.newFormData,
}
: getFilteredSchema(projectSchema as JSONSchema7, projectFormChange);
: getFilteredSchema(
fundingAgreementSchema as JSONSchema7,
fundingAgreementSummary
);

// Set custom rjsf fields to display diffs
const customFields = { ...fields, ...CUSTOM_DIFF_FIELDS };

return (
<>
<h3>FIXME: Project Funding Agreement</h3>
{(projectFormChange.isPristine ||
(projectFormChange.isPristine === null &&
Object.keys(projectFormChange.newFormData).length === 0)) &&
<h3>Project Funding Agreement</h3>
{(!fundingAgreementSummary ||
(fundingAgreementSummary?.isPristine === null &&
Object.keys(fundingAgreementSummary?.newFormData).length === 0)) &&
!props.viewOnly ? (
<p>
<em>Project overview not {isFirstRevision ? "added" : "updated"}</em>
<em>Funding agreement not {isFirstRevision ? "added" : "updated"}</em>
</p>
) : (
<FormBase
tagName={"dl"}
theme={readOnlyTheme}
fields={renderDiff ? customFields : fields}
schema={formSchema as JSONSchema7}
uiSchema={createProjectUiSchema(
newDataAsProject?.operatorByOperatorId?.legalName,
newDataAsProject?.operatorByOperatorId?.bcRegistryId,
`${newDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId?.description} - ${newDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`,
newDataAsProject?.projectStatusByProjectStatusId?.name
)}
uiSchema={fundingAgreementSchema}
formData={formData}
formContext={{
operation: fundingAgreementSummary?.operation,
oldData:
projectFormChange.formChangeByPreviousFormChangeId?.newFormData,
oldUiSchema,
operation: projectFormChange.operation,
fundingAgreementSummary?.formChangeByPreviousFormChangeId
?.newFormData,
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const pageQuery = graphql`
...ProjectMilestoneReportFormSummary_projectRevision
...ProjectAnnualReportFormSummary_projectRevision
...ProjectFundingAgreementForm_projectRevision
...ProjectFundingAgreementFormSummary_projectRevision
}
...ProjectForm_query
...ProjectContactForm_query
Expand Down
5 changes: 5 additions & 0 deletions app/pages/cif/project-revision/[projectRevision]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { TaskListMode } from "components/TaskList/types";
import ProjectQuarterlyReportFormSummary from "components/Form/ProjectQuarterlyReportFormSummary";
import ProjectAnnualReportFormSummary from "components/Form/ProjectAnnualReportFormSummary";
import ProjectMilestoneReportFormSummary from "components/Form/ProjectMilestoneReportFormSummary";
import ProjectFundingAgreementFormSummary from "components/Form/ProjectFundingAgreementFormSummary";

const pageQuery = graphql`
query ProjectRevisionQuery($projectRevision: ID!) {
Expand All @@ -49,6 +50,7 @@ const pageQuery = graphql`
...ProjectAnnualReportFormSummary_projectRevision
...TaskList_projectRevision
...ProjectMilestoneReportFormSummary_projectRevision
...ProjectFundingAgreementFormSummary_projectRevision
projectByProjectId {
latestCommittedProjectRevision {
id
Expand Down Expand Up @@ -212,6 +214,9 @@ export function ProjectRevision({
<ProjectFormSummary projectRevision={query.projectRevision} />
<ProjectManagerFormSummary projectRevision={query.projectRevision} />
<ProjectContactFormSummary projectRevision={query.projectRevision} />
<ProjectFundingAgreementFormSummary
projectRevision={query.projectRevision}
/>
<ProjectMilestoneReportFormSummary
projectRevision={query.projectRevision}
/>
Expand Down

0 comments on commit 30a6bc3

Please sign in to comment.