Skip to content

Commit

Permalink
chore: update for code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
AntBush committed Jun 5, 2024
1 parent 6348284 commit 795328c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 150 deletions.
79 changes: 10 additions & 69 deletions app/pages/analyst/cbc/[cbcId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import reviewUiSchema from 'formSchema/uiSchema/cbc/reviewUiSchema';
import editUiSchema from 'formSchema/uiSchema/cbc/editUiSchema';
import { useFeature } from '@growthbook/growthbook-react';
import CbcTheme from 'components/Analyst/CBC/CbcTheme';
import { createCbcSchemaData } from 'utils/schemaUtils';

const getCbcQuery = graphql`
query CbcIdQuery($rowId: Int!) {
Expand Down Expand Up @@ -78,76 +79,16 @@ const Cbc = ({
const { edges } = cbcDataByCbcId;
const cbcData = edges[0].node;
const { jsonData } = cbcData;
const tombstone = {
projectNumber: jsonData.projectNumber,
originalProjectNumber: jsonData.originalProjectNumber,
phase: jsonData.phase,
intake: jsonData.intake,
projectStatus: jsonData.projectStatus,
projectTitle: jsonData.projectTitle,
projectDescription: jsonData.projectDescription,
applicantContractualName: jsonData.applicantContractualName,
currentOperatingName: jsonData.currentOperatingName,
eightThirtyMillionFunding: jsonData.eightThirtyMillionFunding,
federalFundingSource: jsonData.federalFundingSource,
federalProjectNumber: jsonData.federalProjectNumber,
};

const projectType = {
projectType: jsonData.projectType,
transportProjectType: jsonData.transportProjectType,
highwayProjectType: jsonData.highwayProjectType,
lastMileProjectType: jsonData.lastMileProjectType,
lastMileMinimumSpeed: jsonData.lastMileMinimumSpeed,
connectedCoastNetworkDependant: jsonData.connectedCoastNetworkDependant,
};
const locationsAndCounts = {
projectLocations: jsonData.projectLocations,
communitiesAndLocalesCount: jsonData.communitiesAndLocalesCount,
indigenousCommunities: jsonData.indigenousCommunities,
householdCount: jsonData.householdCount,
transportKm: jsonData.transportKm,
highwayKm: jsonData.highwayKm,
restAreas: jsonData.restAreas,
};

const funding = {
bcFundingRequest: jsonData.bcFundingRequest,
federalFunding: jsonData.federalFunding,
applicantAmount: jsonData.applicantAmount,
otherFunding: jsonData.otherFunding,
totalProjectBudget: jsonData.totalProjectBudget,
};

const eventsAndDates = {
nditConditionalApprovalLetterSent:
jsonData.nditConditionalApprovalLetterSent,
bindingAgreementSignedNditRecipient:
jsonData.bindingAgreementSignedNditRecipient,
announcedByProvince: jsonData.announcedByProvince,
dateApplicationReceived: jsonData.dateApplicationReceived,
dateConditionallyApproved: jsonData.dateConditionallyApproved,
dateAgreementSigned: jsonData.dateAgreementSigned,
proposedStartDate: jsonData.proposedStartDate,
proposedCompletionDate: jsonData.proposedCompletionDate,
reportingCompletionDate: jsonData.reportingCompletionDate,
dateAnnounced: jsonData.dateAnnounced,
};

const miscellaneous = {
projectMilestoneCompleted: jsonData.projectMilestoneCompleted,
constructionCompletedOn: jsonData.constructionCompletedOn,
milestoneComments: jsonData.milestoneComments,
primaryNewsRelease: jsonData.primaryNewsRelease,
secondaryNewsRelease: jsonData.secondaryNewsRelease,
notes: jsonData.notes,
};

const projectDataReviews = {
locked: jsonData.locked,
lastReviewed: jsonData.lastReviewed,
reviewNotes: jsonData.reviewNotes,
};
const {
tombstone,
projectType,
locationsAndCounts,
funding,
eventsAndDates,
miscellaneous,
projectDataReviews,
} = createCbcSchemaData(jsonData);

setFormData({
tombstone,
Expand Down
83 changes: 2 additions & 81 deletions app/pages/analyst/cbc/[cbcId]/edit/[section].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { RJSFSchema } from '@rjsf/utils';
import useModal from 'lib/helpers/useModal';
import { ChangeModal } from 'components/Analyst';
import { useUpdateCbcDataAndInsertChangeRequest } from 'schema/mutations/cbc/updateCbcDataAndInsertChangeReason';
import { createCbcSchemaData } from 'utils/schemaUtils';

const getCbcSectionQuery = graphql`
query SectionCbcDataQuery($rowId: Int!) {
Expand Down Expand Up @@ -57,87 +58,7 @@ const EditCbcSection = ({
const { cbcDataByCbcId, rowId } = cbcByRowId;
const { jsonData, rowId: cbcDataRowId } = cbcDataByCbcId.edges[0].node;

const tombstone = {
projectNumber: jsonData.projectNumber,
originalProjectNumber: jsonData.originalProjectNumber,
phase: jsonData.phase,
intake: jsonData.intake,
projectStatus: jsonData.projectStatus,
changeRequestPending: jsonData.changeRequestPending,
projectTitle: jsonData.projectTitle,
projectDescription: jsonData.projectDescription,
applicantContractualName: jsonData.applicantContractualName,
currentOperatingName: jsonData.currentOperatingName,
eightThirtyMillionFunding: jsonData.eightThirtyMillionFunding,
federalFundingSource: jsonData.federalFundingSource,
federalProjectNumber: jsonData.federalProjectNumber,
};

const projectType = {
projectType: jsonData.projectType,
transportProjectType: jsonData.transportProjectType,
highwayProjectType: jsonData.highwayProjectType,
lastMileProjectType: jsonData.lastMileProjectType,
lastMileMinimumSpeed: jsonData.lastMileMinimumSpeed,
connectedCoastNetworkDependant: jsonData.connectedCoastNetworkDependant,
};
const locationsAndCounts = {
projectLocations: jsonData.projectLocations,
communitiesAndLocalesCount: jsonData.communitiesAndLocalesCount,
indigenousCommunities: jsonData.indigenousCommunities,
householdCount: jsonData.householdCount,
transportKm: jsonData.transportKm,
highwayKm: jsonData.highwayKm,
restAreas: jsonData.restAreas,
};

const funding = {
bcFundingRequest: jsonData.bcFundingRequest,
federalFunding: jsonData.federalFunding,
applicantAmount: jsonData.applicantAmount,
otherFunding: jsonData.otherFunding,
totalProjectBudget: jsonData.totalProjectBudget,
};

const eventsAndDates = {
nditConditionalApprovalLetterSent:
jsonData.nditConditionalApprovalLetterSent,
bindingAgreementSignedNditRecipient:
jsonData.bindingAgreementSignedNditRecipient,
announcedByProvince: jsonData.announcedByProvince,
dateApplicationReceived: jsonData.dateApplicationReceived,
dateConditionallyApproved: jsonData.dateConditionallyApproved,
dateAgreementSigned: jsonData.dateAgreementSigned,
proposedStartDate: jsonData.proposedStartDate,
proposedCompletionDate: jsonData.proposedCompletionDate,
reportingCompletionDate: jsonData.reportingCompletionDate,
dateAnnounced: jsonData.dateAnnounced,
};

const miscellaneous = {
projectMilestoneCompleted: jsonData.projectMilestoneCompleted,
constructionCompletedOn: jsonData.constructionCompletedOn,
milestoneComments: jsonData.milestoneComments,
primaryNewsRelease: jsonData.primaryNewsRelease,
secondaryNewsRelease: jsonData.secondaryNewsRelease,
notes: jsonData.notes,
};

const projectDataReviews = {
locked: jsonData.locked,
lastReviewed: jsonData.lastReviewed,
reviewNotes: jsonData.reviewNotes,
};

const dataBySection = {
tombstone,
projectType,
locationsAndCounts,
funding,
eventsAndDates,
miscellaneous,
projectDataReviews,
};
const dataBySection = createCbcSchemaData(jsonData);

const changeModal = useModal();

Expand Down
1 change: 1 addition & 0 deletions app/tests/pages/analyst/cbc/[cbcId].test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe('Cbc', () => {
intake: 1,
projectStatus: 'Reporting Complete',
projectTitle: 'Project 1',
changeRequestPending: 'No',
projectDescription: 'Description 1',
applicantContractualName: 'Internet company 1',
currentOperatingName: 'Internet company 1',
Expand Down
98 changes: 98 additions & 0 deletions app/utils/schemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,101 @@ export const getSectionNameFromPageNumber = (
): keyof typeof uiSchema => {
return uiSchema['ui:order'][pageNumber - 1] as keyof typeof uiSchema;
};

export const createCbcSchemaData = (jsonData) => {
if (jsonData === null || jsonData === undefined) {
return {
tombstone: null,
projectType: null,
locationsAndCounts: null,
funding: null,
eventsAndDates: null,
miscellaneous: null,
projectDataReviews: null,
};
}

const tombstone = {
projectNumber: jsonData.projectNumber,
originalProjectNumber: jsonData.originalProjectNumber,
phase: jsonData.phase,
intake: jsonData.intake,
projectStatus: jsonData.projectStatus,
changeRequestPending: jsonData.changeRequestPending,
projectTitle: jsonData.projectTitle,
projectDescription: jsonData.projectDescription,
applicantContractualName: jsonData.applicantContractualName,
currentOperatingName: jsonData.currentOperatingName,
eightThirtyMillionFunding: jsonData.eightThirtyMillionFunding,
federalFundingSource: jsonData.federalFundingSource,
federalProjectNumber: jsonData.federalProjectNumber,
};

const projectType = {
projectType: jsonData.projectType,
transportProjectType: jsonData.transportProjectType,
highwayProjectType: jsonData.highwayProjectType,
lastMileProjectType: jsonData.lastMileProjectType,
lastMileMinimumSpeed: jsonData.lastMileMinimumSpeed,
connectedCoastNetworkDependant: jsonData.connectedCoastNetworkDependant,
};
const locationsAndCounts = {
projectLocations: jsonData.projectLocations,
communitiesAndLocalesCount: jsonData.communitiesAndLocalesCount,
indigenousCommunities: jsonData.indigenousCommunities,
householdCount: jsonData.householdCount,
transportKm: jsonData.transportKm,
highwayKm: jsonData.highwayKm,
restAreas: jsonData.restAreas,
};

const funding = {
bcFundingRequest: jsonData.bcFundingRequest,
federalFunding: jsonData.federalFunding,
applicantAmount: jsonData.applicantAmount,
otherFunding: jsonData.otherFunding,
totalProjectBudget: jsonData.totalProjectBudget,
};

const eventsAndDates = {
nditConditionalApprovalLetterSent:
jsonData.nditConditionalApprovalLetterSent,
bindingAgreementSignedNditRecipient:
jsonData.bindingAgreementSignedNditRecipient,
announcedByProvince: jsonData.announcedByProvince,
dateApplicationReceived: jsonData.dateApplicationReceived,
dateConditionallyApproved: jsonData.dateConditionallyApproved,
dateAgreementSigned: jsonData.dateAgreementSigned,
proposedStartDate: jsonData.proposedStartDate,
proposedCompletionDate: jsonData.proposedCompletionDate,
reportingCompletionDate: jsonData.reportingCompletionDate,
dateAnnounced: jsonData.dateAnnounced,
};

const miscellaneous = {
projectMilestoneCompleted: jsonData.projectMilestoneCompleted,
constructionCompletedOn: jsonData.constructionCompletedOn,
milestoneComments: jsonData.milestoneComments,
primaryNewsRelease: jsonData.primaryNewsRelease,
secondaryNewsRelease: jsonData.secondaryNewsRelease,
notes: jsonData.notes,
};

const projectDataReviews = {
locked: jsonData.locked,
lastReviewed: jsonData.lastReviewed,
reviewNotes: jsonData.reviewNotes,
};

const dataBySection = {
tombstone,
projectType,
locationsAndCounts,
funding,
eventsAndDates,
miscellaneous,
projectDataReviews,
};

return dataBySection;
};

0 comments on commit 795328c

Please sign in to comment.