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: display details of single cbc project #3273

Merged
merged 35 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
47945f7
feat: add cbc projects and data tables
rafasdc May 8, 2024
d9f9b29
chore: rename tables, recreate schema
rafasdc May 8, 2024
80210c5
feat: import cbc data separately into two tables
rafasdc May 8, 2024
f466169
chore: use all cbc data (row separated)
rafasdc May 9, 2024
72a54a1
feat: display cbc data page
rafasdc May 9, 2024
7266751
chore: add expand and collapse all
rafasdc May 9, 2024
0f52c62
feat: cbc header edit, update mutation
rafasdc May 14, 2024
ef6ec40
feat: cbc rework view, initial quick edit
rafasdc May 14, 2024
9d03cd9
chore: correct typo
rafasdc May 14, 2024
0f94bcb
chore: separate edit and review ui schema, add missing fields
rafasdc May 14, 2024
6cc4266
feat: add link to cbc view page on all dashboard
rafasdc May 14, 2024
c62018b
feat: placeholder history page
rafasdc May 14, 2024
4b28adf
chore: update form title
rafasdc May 14, 2024
e39d2e8
chore: cleanup
rafasdc May 14, 2024
6dba2e9
chore: cleanup
rafasdc May 14, 2024
c0fe36a
feat: extend header banner, add cbc beta banner
rafasdc May 14, 2024
467c475
feat: feature flag cbc view and edit
rafasdc May 14, 2024
1d4a87e
chore: add feature flag to cbc header edits
rafasdc May 14, 2024
b292bfa
chore: correct revert for cbc_data table
rafasdc May 14, 2024
792bc6a
chore: properly escape background
rafasdc May 14, 2024
8747ab9
test: update dashboard test data for cbc
rafasdc May 14, 2024
1d79147
test: update mock perform query
rafasdc May 14, 2024
13b3826
test: update mocked performQuery
rafasdc May 15, 2024
8831917
chore: merge conflicts
rafasdc May 15, 2024
74471ee
chore: revert local dev commit
rafasdc May 15, 2024
e4b3186
test: initial cbc page tests
rafasdc May 15, 2024
921afd1
test: add base history page test
rafasdc May 15, 2024
36f84a1
test: add expand and collapse test
rafasdc May 15, 2024
79a0887
test: add cbc change status tests
rafasdc May 15, 2024
f922495
test(e2e): cbc single view
rafasdc May 16, 2024
9283300
chore: remove analyst insert and update to cbc
rafasdc May 16, 2024
a477637
test(db): add cbc new tables tests
rafasdc May 16, 2024
257c122
test(e2e): add missing schema to insert
rafasdc May 16, 2024
49ed0e4
test(db): correct db unit tests
rafasdc May 16, 2024
7991640
Merge branch 'main' into NDT-307-Display-details-of-single-CBC-project
rafasdc May 22, 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
107 changes: 106 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,50 @@ const createCbcProjectMutation = `
}
`;

const findCbcQuery = `
query findCbc($projectNumber: Int!) {
cbcByProjectNumber (projectNumber: $projectNumber) {
rowId
cbcDataByProjectNumber {
nodes {
jsonData
id
projectNumber
rowId
sharepointTimestamp
}
}
}
}
`;

const createCbcMutation = `
mutation createCbcMutation($input: CreateCbcInput!) {
createCbc(input: $input) {
clientMutationId
cbc {
rowId
}
}
}
`;

const createCbcDataMutation = `
mutation createCbcDataMutation($input: CreateCbcDataInput!) {
createCbcData(input: $input) {
clientMutationId
}
}
`;

const updateCbcDataMutation = `
mutation updateCbcDataMutation($input: UpdateCbcDataByRowIdInput!) {
updateCbcDataByRowId(input: $input) {
clientMutationId
}
}
`;

const cbcErrorList = [];

const readSummary = async (wb, sheet) => {
Expand Down Expand Up @@ -55,7 +99,7 @@ const readSummary = async (wb, sheet) => {

const cbcProject = {
projectNumber: project['A'],
orignalProjectNumber: project['B'],
originalProjectNumber: project['B'],
phase: project['C'],
intake: project['D'],
projectStatus: project['E'],
Expand Down Expand Up @@ -254,6 +298,67 @@ const LoadCbcProjectData = async (wb, sheet, sharepointTimestamp, req) => {
return { error: [e] };
});

// persist into DB individually
data._jsonData.forEach(async (project) => {
// console.log(project);
const findCbcProject = await performQuery(
findCbcQuery,
{
projectNumber: project.projectNumber,
},
req
);
if (
findCbcProject.data?.cbcByProjectNumber?.cbcDataByProjectNumber?.nodes
.length > 0
) {
// update cbc data
await performQuery(
updateCbcDataMutation,
{
input: {
cbcDataPatch: {
jsonData: project,
},
rowId:
findCbcProject.data.cbcByProjectNumber.cbcDataByProjectNumber
.nodes[0].rowId,
},
},
req
);
} else {
// create cbc
const createCbcResult = await performQuery(
createCbcMutation,
{
input: {
cbc: {
projectNumber: project.projectNumber,
sharepointTimestamp,
},
},
},
req
);
// create cbc data
await performQuery(
createCbcDataMutation,
{
input: {
cbcData: {
jsonData: project,
projectNumber: project.projectNumber,
cbcId: createCbcResult.data.createCbc.cbc.rowId,
sharepointTimestamp,
},
},
},
req
);
}
});

return {
...result,
errorLog: cbcErrorList,
Expand Down
94 changes: 94 additions & 0 deletions app/components/Analyst/CBC/AssignField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { useFeature } from '@growthbook/growthbook-react';
import { useState } from 'react';
import { graphql, useFragment } from 'react-relay';
import { useUpdateCbcDataByRowIdMutation } from 'schema/mutations/cbc/updateCbcData';
import styled from 'styled-components';

const StyledDropdown = styled.select`
text-overflow: ellipsis;
color: ${(props) => props.theme.color.links};
background-color: ${(props) => props.theme.color.white};
border: 1px solid ${(props) => props.theme.color.borderGrey};
padding: 0 8px;
max-width: 100%;
border-radius: 4px;
`;

const AssignField = ({ fieldName, fieldOptions, fieldType, cbc }) => {
const queryFragment = useFragment(
graphql`
fragment AssignField_query on Cbc {
cbcDataByCbcId {
edges {
node {
jsonData
sharepointTimestamp
rowId
projectNumber
updatedAt
updatedBy
}
}
}
}
`,
cbc
);
const { jsonData } = queryFragment.cbcDataByCbcId.edges[0].node;

const [updateField] = useUpdateCbcDataByRowIdMutation();
const [fieldValue, setFieldValue] = useState(
fieldType === 'string'
? jsonData[fieldName].toString() || null
: jsonData[fieldName] || null
);

const allowEdit = useFeature('show_cbc_edit').value ?? false;

const handleChange = (e) => {
const { rowId } = queryFragment.cbcDataByCbcId.edges[0].node;
updateField({
variables: {
input: {
rowId,
cbcDataPatch: {
jsonData: {
...jsonData,
[fieldName]:
fieldType === 'number'
? parseInt(e.target.value, 10)
: e.target.value,
},
},
},
},
onCompleted: () => {
setFieldValue(e.target.value);
},
debounceKey: 'cbc_assign_field',
});
};

return (
<StyledDropdown
id={`assign-${fieldName}`}
onChange={(e) => handleChange(e)}
data-testid={`assign-${fieldName}`}
>
{fieldOptions.map((option) => {
return (
<option
key={option}
value={option}
selected={fieldValue === option}
disabled={!allowEdit}
>
{option}
</option>
);
})}
</StyledDropdown>
);
};

export default AssignField;
47 changes: 47 additions & 0 deletions app/components/Analyst/CBC/CbcAnalystLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import styled from 'styled-components';
import { graphql, useFragment } from 'react-relay';
import FormDiv from 'components/FormDiv';
import NavigationSidebar from './NavigationSidebar';
import CbcHeader from './CbcHeader';

const StyledContainer = styled.div`
display: flex;
flex-direction: column;
margin: 0 auto;
width: 100%;
`;

const StyledFlex = styled.div`
display: flex;
`;

const StyledFormDiv = styled(FormDiv)`
max-width: 100%;
`;

interface Props {
children: JSX.Element[] | JSX.Element;
query: any;
}

const CbcAnalystLayout: React.FC<Props> = ({ children, query }) => {
const queryFragment = useFragment(
graphql`
fragment CbcAnalystLayout_query on Query {
...CbcHeader_query
}
`,
query
);
return (
<StyledContainer>
<CbcHeader query={queryFragment} />
<StyledFlex>
<NavigationSidebar />
<StyledFormDiv>{children}</StyledFormDiv>
</StyledFlex>
</StyledContainer>
);
};

export default CbcAnalystLayout;
Loading
Loading