Skip to content

Commit

Permalink
chore: move change request pending to cbc header
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed May 27, 2024
1 parent fc77383 commit da1e542
Show file tree
Hide file tree
Showing 16 changed files with 23,584 additions and 22,088 deletions.
58 changes: 57 additions & 1 deletion app/backend/lib/excel_import/cbc_project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ const createCbcProjectMutation = `
}
`;

const createPendingChangeRequestMutation = `
mutation createPendingChangeRequestMutation(
$input: CreatePendingChangeRequestInput!
) {
createPendingChangeRequest(input: $input) {
applicationPendingChangeRequest {
isPending
comment
}
}
}`;

const findCbcQuery = `
query findCbc($projectNumber: Int!) {
cbcByProjectNumber (projectNumber: $projectNumber) {
Expand All @@ -32,6 +44,16 @@ const findCbcQuery = `
sharepointTimestamp
}
}
applicationPendingChangeRequestsByCbcId(
orderBy: CREATED_AT_DESC
first: 1
) {
nodes {
isPending
updatedAt
cbcId
}
}
}
}
`;
Expand Down Expand Up @@ -308,6 +330,7 @@ const LoadCbcProjectData = async (wb, sheet, sharepointTimestamp, req) => {
},
req
);
let createCbcResult = null;
if (
findCbcProject.data?.cbcByProjectNumber?.cbcDataByProjectNumber?.nodes
.length > 0
Expand All @@ -329,7 +352,7 @@ const LoadCbcProjectData = async (wb, sheet, sharepointTimestamp, req) => {
);
} else {
// create cbc
const createCbcResult = await performQuery(
createCbcResult = await performQuery(
createCbcMutation,
{
input: {
Expand Down Expand Up @@ -357,6 +380,39 @@ const LoadCbcProjectData = async (wb, sheet, sharepointTimestamp, req) => {
req
);
}
let changeRequestInput = null;
const existingChangeRequest =
findCbcProject.data?.cbcByProjectNumber
?.applicationPendingChangeRequestsByCbcId?.nodes?.[0];

if (existingChangeRequest) {
// If existing change request is different from the spreadsheet import override
if (
existingChangeRequest.isPending !==
(project.changeRequestPending === 'Yes')
) {
changeRequestInput = {
_cbcId: existingChangeRequest.cbcId,
_isPending: project.changeRequestPending === 'Yes',
_comment: null,
};
}
} else if (project.changeRequestPending === 'Yes') {
// Only persist change request if it is pending
changeRequestInput = {
_cbcId: createCbcResult.data.createCbc?.cbc?.rowId,
_isPending: true,
_comment: null,
};
}
if (changeRequestInput !== null)
await performQuery(
createPendingChangeRequestMutation,
{
input: changeRequestInput,
},
req
);
});

return {
Expand Down
2 changes: 1 addition & 1 deletion app/components/Analyst/ApplicationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const ApplicationHeader: React.FC<Props> = ({ query }) => {
...AssignPackage_query
...EditProjectDescription_query
...AssignProjectType_query
...PendingChangeRequest_query
...PendingChangeRequest_query_application
}
...AssignLead_query
allApplicationStatusTypes(
Expand Down
14 changes: 13 additions & 1 deletion app/components/Analyst/CBC/CbcHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styled from 'styled-components';
import { graphql, useFragment } from 'react-relay';
import CbcChangeStatus from './CbcChangeStatus';
import AssignField from './AssignField';
import PendingChangeRequest from '../PendingChangeRequest/PendingChangeRequest';

const StyledCallout = styled.div`
margin-bottom: 0.5em;
Expand Down Expand Up @@ -33,7 +34,7 @@ const StyledDiv = styled.div`
`;

const StyledLabel = styled.label`
min-width: 130px;
min-width: 210px;
color: ${(props) => props.theme.color.components};
padding-right: 1rem;
direction: rtl;
Expand All @@ -49,6 +50,10 @@ const StyledAssign = styled(StyledItem)`
margin: 8px 0 0 0;
`;

const StyledPendingChangeRequests = styled(StyledItem)`
margin: 8px 0;
`;

interface Props {
query: any;
}
Expand All @@ -75,6 +80,7 @@ const CbcHeader: React.FC<Props> = ({ query }) => {
}
...CbcChangeStatus_query
...AssignField_query
...PendingChangeRequest_query_cbc
}
}
`,
Expand Down Expand Up @@ -133,6 +139,12 @@ const CbcHeader: React.FC<Props> = ({ query }) => {
cbc={cbcByRowId}
/>
</StyledAssign>
<StyledPendingChangeRequests>
<StyledLabel htmlFor="assign-project-type">
Pending Change Request
</StyledLabel>
<PendingChangeRequest application={cbcByRowId} isCbc />
</StyledPendingChangeRequests>
</StyledDiv>
</StyledCallout>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { graphql, useFragment } from 'react-relay';
import { useCreatePendingChangeRequestMutation } from 'schema/mutations/application/createPendingChangeRequest';
import styled from 'styled-components';
import { useState } from 'react';
import useModal from 'lib/helpers/useModal';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCommentDots } from '@fortawesome/free-solid-svg-icons';
Expand All @@ -19,39 +19,51 @@ const StyledFontAwesomeIcon = styled(FontAwesomeIcon)`
margin-left: 8px;
`;

const PendingChangeRequest = ({ application }) => {
const queryFragment = useFragment(
graphql`
fragment PendingChangeRequest_query on Application {
rowId
applicationPendingChangeRequestsByApplicationId(
orderBy: CREATED_AT_DESC
first: 1
) {
nodes {
comment
isPending
const PendingChangeRequest = ({ application, isCbc = false }) => {
const fragment = isCbc
? graphql`
fragment PendingChangeRequest_query_cbc on Cbc {
rowId
applicationPendingChangeRequestsByCbcId(
orderBy: CREATED_AT_DESC
first: 1
) {
nodes {
comment
isPending
}
}
}
}
`,
application
);
`
: graphql`
fragment PendingChangeRequest_query_application on Application {
rowId
applicationPendingChangeRequestsByApplicationId(
orderBy: CREATED_AT_DESC
first: 1
) {
nodes {
comment
isPending
}
}
}
`;

const queryFragment = useFragment(fragment, application);

const pendingChangeRequestModal = useModal();
const closePendingRequestModal = useModal();
const { applicationPendingChangeRequestsByApplicationId, rowId } =
queryFragment;
const pendingRequests = isCbc
? queryFragment?.applicationPendingChangeRequestsByCbcId
: queryFragment?.applicationPendingChangeRequestsByApplicationId;

const [isPending, setIsPending] = useState(
applicationPendingChangeRequestsByApplicationId?.nodes?.[0]?.isPending ||
false
pendingRequests?.nodes?.[0]?.isPending || false
);

const [comment, setComment] = useState(
isPending
? applicationPendingChangeRequestsByApplicationId?.nodes?.[0]?.comment
: null
isPending ? pendingRequests?.nodes?.[0]?.comment : null
);

const [isUpdateMode, setIsUpdateMode] = useState(false);
Expand All @@ -68,10 +80,13 @@ const PendingChangeRequest = ({ application }) => {
isPendingRequest: boolean,
reasonForChange: string
) => {
const rowParam = isCbc
? { _cbcId: queryFragment.rowId }
: { _applicationId: queryFragment.rowId };
createPendingChangeRequest({
variables: {
input: {
_applicationId: rowId,
...rowParam,
_isPending: isPendingRequest,
_comment: reasonForChange,
},
Expand Down
4 changes: 0 additions & 4 deletions app/formSchema/analyst/cbc/tombstone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const cbcTombstone: RJSFSchema = {
type: 'string',
title: 'Project Status',
},
changeRequestPending: {
type: 'boolean',
title: 'Change Request Pending',
},
projectTitle: {
type: 'string',
title: 'Project Title',
Expand Down
1 change: 0 additions & 1 deletion app/pages/analyst/cbc/[cbcId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const Cbc = ({
phase: jsonData.phase,
intake: jsonData.intake,
projectStatus: jsonData.projectStatus,
changeRequestPending: jsonData.changeRequestPending,
projectTitle: jsonData.projectTitle,
projectDescription: jsonData.projectDescription,
applicantContractualName: jsonData.applicantContractualName,
Expand Down
Loading

0 comments on commit da1e542

Please sign in to comment.