Skip to content

Commit 0d28470

Browse files
authored
Merge pull request #3963 from Northeastern-Electric-Racing/new-project-diff
Fix Diff for New Project Change Requests
2 parents b8c9f3c + a19203c commit 0d28470

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

src/backend/src/transformers/change-requests.transformer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
WbsElementStatus,
99
WorkPackageProposedChanges,
1010
WorkPackageStage,
11-
isProjectWbs,
12-
BudgetChangeRequest
11+
BudgetChangeRequest,
12+
isWorkPackageWbs
1313
} from 'shared';
1414
import { wbsNumOf } from '../utils/utils.js';
1515
import { calculateChangeRequestStatus, convertCRScopeWhyType } from '../utils/change-requests.utils.js';
@@ -132,7 +132,7 @@ const changeRequestTransformer = (
132132
const status = calculateChangeRequestStatus(changeRequest);
133133

134134
const wbsName = changeRequest.wbsElement
135-
? isProjectWbs(changeRequest.wbsElement)
135+
? !isWorkPackageWbs(changeRequest.wbsElement)
136136
? changeRequest.wbsElement?.name
137137
: `${changeRequest.wbsElement?.workPackage?.project.wbsElement.name} - ${changeRequest.wbsElement?.name}`
138138
: undefined;

src/frontend/src/pages/ChangeRequestDetailPage/DiffSection/DiffSection.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Box } from '@mui/system';
22
import InfoBlock from '../../../components/InfoBlock';
3-
import { StandardChangeRequest } from 'shared';
3+
import { isProjectWbs, StandardChangeRequest } from 'shared';
44
import ProjectDiffSection from './ProjectDiffSection';
55
import WorkPackageDiffSection from './WorkPackageDiffSection';
66
import LoadingIndicator from '../../../components/LoadingIndicator';
77
import DiffSectionEdit from './DiffSectionEdit';
88
import { getChangesForWorkPackage } from '../../../utils/diff-page.utils';
9+
import NewProjectDiffSection from './NewProjectDiffSection';
10+
911
interface DiffSectionProps {
1012
changeRequest: StandardChangeRequest;
1113
}
@@ -18,7 +20,11 @@ const DiffSection: React.FC<DiffSectionProps> = ({ changeRequest }) => {
1820
<InfoBlock title={`Proposed Changes`} />
1921
{wbsNum ? (
2022
projectProposedChanges ? (
21-
<ProjectDiffSection projectProposedChanges={projectProposedChanges} wbsNum={wbsNum} />
23+
isProjectWbs(wbsNum) ? (
24+
<ProjectDiffSection projectProposedChanges={projectProposedChanges} wbsNum={wbsNum} />
25+
) : (
26+
<NewProjectDiffSection projectProposedChanges={projectProposedChanges} />
27+
)
2228
) : workPackageProposedChanges ? (
2329
wbsNum.workPackageNumber === 0 ? (
2430
<DiffSectionEdit collections={[getChangesForWorkPackage(undefined, workPackageProposedChanges)]} />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ProjectProposedChanges } from 'shared';
2+
import DiffSectionEdit from './DiffSectionEdit';
3+
import { ComparableCollection, getChangesForProject } from '../../../utils/diff-page.utils';
4+
import { useEffect, useState } from 'react';
5+
6+
const NewProjectDiffSection = ({ projectProposedChanges }: { projectProposedChanges: ProjectProposedChanges }) => {
7+
const [collections, setCollections] = useState<ComparableCollection[]>([]);
8+
9+
useEffect(() => {
10+
setCollections(getChangesForProject(projectProposedChanges, undefined));
11+
}, [projectProposedChanges, setCollections]);
12+
13+
return <DiffSectionEdit collections={collections} />;
14+
};
15+
16+
export default NewProjectDiffSection;

src/frontend/src/pages/ChangeRequestDetailPage/DiffSection/ProjectDiffSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const ProjectDiffSection = ({
1818

1919
useEffect(() => {
2020
if (originalProject) {
21-
setCollections(getChangesForProject(originalProject, projectProposedChanges));
21+
setCollections(getChangesForProject(projectProposedChanges, originalProject));
2222
}
2323
}, [originalProject, projectProposedChanges, setCollections]);
2424

src/frontend/src/utils/diff-page.utils.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,25 @@ export const getWbsChanges = (
199199
};
200200

201201
export const getChangesForProject = (
202-
originalProject: Project,
203-
proposedChanges: ProjectProposedChanges
202+
proposedChanges: ProjectProposedChanges,
203+
originalProject?: Project
204204
): ComparableCollection[] => {
205205
const projectLines: ComparableLine[] = [...getWbsChanges(originalProject, proposedChanges)];
206206

207207
projectLines.push(
208208
genChange(
209209
'Summary',
210-
originalProject.summary !== proposedChanges.summary,
211-
originalProject.summary,
210+
originalProject?.summary !== proposedChanges.summary,
211+
originalProject ? originalProject.summary : '',
212212
proposedChanges.summary
213213
)
214214
);
215215

216216
projectLines.push(
217217
genChange(
218218
'Budget',
219-
originalProject.budget !== proposedChanges.budget,
220-
`$${originalProject.budget}`,
219+
originalProject?.budget !== proposedChanges.budget,
220+
originalProject ? `$${originalProject.budget}` : '',
221221
`$${proposedChanges.budget}`
222222
)
223223
);
@@ -226,9 +226,11 @@ export const getChangesForProject = (
226226
genListChange(
227227
'Teams',
228228
'',
229-
originalProject.teams
230-
.map((team) => ({ ...team, value: team.teamName }))
231-
.sort((a, b) => a.teamName.localeCompare(b.teamName)),
229+
originalProject
230+
? originalProject.teams
231+
.map((team) => ({ ...team, value: team.teamName }))
232+
.sort((a, b) => a.teamName.localeCompare(b.teamName))
233+
: [],
232234
proposedChanges.teams
233235
.map((team) => ({ ...team, value: team.teamName }))
234236
.sort((a, b) => a.teamName.localeCompare(b.teamName)),
@@ -238,7 +240,7 @@ export const getChangesForProject = (
238240

239241
const workPackageCollections: ComparableCollection[] = [];
240242

241-
originalProject.workPackages.forEach((workPackage) => {
243+
originalProject?.workPackages.forEach((workPackage) => {
242244
const newWorkPackage = proposedChanges.workPackageProposedChanges.find((wp) => wp.name === workPackage.name); // TODO ideally do this based on something unique, maybe add a reference to original wbsElementid or something this also just doesnt work if the name has changed so... I dont see another way to identify them though
243245
if (newWorkPackage) {
244246
const workPackageLines = getChangesForWorkPackage(workPackage, newWorkPackage);
@@ -253,7 +255,7 @@ export const getChangesForProject = (
253255
workPackageCollections.push(getChangesForWorkPackage(undefined, wp));
254256
});
255257

256-
return [{ label: originalProject.name, lines: projectLines }, ...workPackageCollections];
258+
return [{ label: originalProject ? originalProject.name : '', lines: projectLines }, ...workPackageCollections];
257259
};
258260

259261
export const getChangesForWorkPackage = (

0 commit comments

Comments
 (0)