Skip to content

Commit 69c32f3

Browse files
authored
Merge pull request #3940 from Northeastern-Electric-Racing/fix_diff_page
Fix Rendering of Lists In Diff Page
2 parents afe126b + ed61021 commit 69c32f3

3 files changed

Lines changed: 58 additions & 27 deletions

File tree

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,26 @@ const DiffPanel: React.FC<ProjectDiffPanelProps> = ({ comparableObjects, origina
2525
return (
2626
<List sx={{ listStyleType: 'disc', pl: 6, pb: 1, pt: 0 }}>
2727
{detail.map((bullet) => {
28-
return <ListItem sx={{ display: 'list-item', py: 0 }}>{renderDetailText(bullet.value)}</ListItem>;
28+
return (
29+
<ListItem sx={{ display: 'list-item', py: 0 }}>
30+
{!bullet.changed ? (
31+
<Typography>{renderDetailText(bullet.value)}</Typography>
32+
) : (
33+
<Box
34+
sx={{
35+
backgroundColor: getPotentialChangeBackground(
36+
original ? PotentialChangeType.REMOVED : PotentialChangeType.ADDED,
37+
theme
38+
),
39+
borderRadius: '5px',
40+
mb: '3px'
41+
}}
42+
>
43+
{renderDetailText(bullet.value)}
44+
</Box>
45+
)}
46+
</ListItem>
47+
);
2948
})}
3049
</List>
3150
);
@@ -44,13 +63,13 @@ const DiffPanel: React.FC<ProjectDiffPanelProps> = ({ comparableObjects, origina
4463
<>
4564
<Typography>{changeSection.label}</Typography>
4665
<List>
47-
{changeSection.objects.map((changeBullet) => {
66+
{changeSection.objects.map((bullet) => {
4867
return (
4968
<ListItem>
50-
{!changeBullet.changed ? (
69+
{!bullet.changed ? (
5170
<Typography>
5271
<Box pl={2}>
53-
{labelPipe(changeBullet.key)}: {renderDetailText(changeBullet.value)}
72+
{labelPipe(bullet.key)}: {renderDetailText(bullet.value)}
5473
</Box>
5574
</Typography>
5675
) : (
@@ -74,11 +93,11 @@ const DiffPanel: React.FC<ProjectDiffPanelProps> = ({ comparableObjects, origina
7493
display="inline"
7594
>
7695
<Typography fontWeight="bold" padding="3px" display="inline">
77-
{labelPipe(changeBullet.key)}:
96+
{labelPipe(bullet.key)}:
7897
</Typography>
7998
</Box>
8099
<Box component="span" display="inline">
81-
{renderDetailText(changeBullet.value)}
100+
{renderDetailText(bullet.value)}
82101
</Box>
83102
</Box>
84103
)}

src/frontend/src/pages/HomePage/components/ScrollablePageBlock.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const ScrollablePageBlock: React.FC<ScrollablePageBlockProps> = ({ children, tit
3535
mt: 2,
3636
flexDirection: horizontal ? 'row' : 'column',
3737
flexWrap: 'nowrap',
38+
display: 'flex',
3839
gap: 2,
3940
alignItems: 'start',
4041
overflowX: horizontal ? 'auto' : 'hidden',

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,25 @@ export const genListChange = <T extends DisplayableObejct>(
126126
defaultValue: string,
127127
originalValues: T[],
128128
newValues: T[],
129-
comparator: (a: T, b: T) => boolean
129+
comparator: (a: T | undefined, b: T | undefined) => boolean
130130
): ComparableLine => {
131-
const isOriginalLarger = originalValues.length > newValues.length;
132131
return {
133132
original: {
134133
key,
135134
changed: false,
136-
value: (isOriginalLarger ? newValues : originalValues).map((_, i) => ({
135+
value: originalValues.map((db, i) => ({
137136
key,
138-
changed: comparator(originalValues[i], newValues[i]),
139-
value: originalValues[i].value ?? defaultValue
137+
changed: comparator(db, newValues[i]),
138+
value: db.value ?? defaultValue
140139
}))
141140
},
142141
new: {
143142
key,
144143
changed: false,
145-
value: (isOriginalLarger ? newValues : originalValues).map((_, i) => ({
144+
value: newValues.map((db, i) => ({
146145
key,
147-
changed: comparator(originalValues[i], newValues[i]),
148-
value: newValues[i].value ?? defaultValue
146+
changed: comparator(originalValues[i], db),
147+
value: db.value ?? defaultValue
149148
}))
150149
}
151150
};
@@ -160,9 +159,6 @@ export const getWbsChanges = (
160159
const namesChanged = originalElement?.name !== proposedChanges?.name;
161160
lines.push(genChange('Title', namesChanged, originalElement?.name ?? '', proposedChanges?.name ?? ''));
162161

163-
const statusChanged = originalElement?.status !== proposedChanges?.status;
164-
lines.push(genChange('Status', statusChanged, originalElement?.status ?? '', proposedChanges?.status ?? ''));
165-
166162
const leadChanged = originalElement?.lead?.userId !== proposedChanges?.lead?.userId;
167163
lines.push(genChange('Lead', leadChanged, fullNamePipe(originalElement?.lead), fullNamePipe(proposedChanges?.lead)));
168164

@@ -175,19 +171,27 @@ export const getWbsChanges = (
175171
genListChange(
176172
'Links',
177173
'',
178-
originalElement?.links.map((link) => ({ ...link, value: link.url })) ?? [],
179-
proposedChanges?.links.map((link) => ({ ...link, value: link.url })) ?? [],
180-
(a, b) => a.linkId === b.linkId
174+
(originalElement?.links.map((link) => ({ ...link, value: link.linkType.name + ' - ' + link.url })) ?? []).sort(
175+
(a, b) => a.value.localeCompare(b.value)
176+
),
177+
(proposedChanges?.links.map((link) => ({ ...link, value: link.linkType.name + ' - ' + link.url })) ?? []).sort(
178+
(a, b) => a.value.localeCompare(b.value)
179+
),
180+
(a, b) => a?.url !== b?.url || a?.linkType.name !== b?.linkType.name
181181
)
182182
);
183183

184184
lines.push(
185185
genListChange(
186186
'Description Bullets',
187187
'',
188-
originalElement?.descriptionBullets.map((db) => ({ ...db, value: db.detail })) ?? [],
189-
proposedChanges?.descriptionBullets.map((db) => ({ ...db, value: db.detail })) ?? [],
190-
(a, b) => a.id === b.id
188+
(originalElement?.descriptionBullets.map((db) => ({ ...db, value: db.type + ' - ' + db.detail })) ?? []).sort((a, b) =>
189+
a.value.localeCompare(b.value)
190+
),
191+
(proposedChanges?.descriptionBullets.map((db) => ({ ...db, value: db.type + ' - ' + db.detail })) ?? []).sort((a, b) =>
192+
a.value.localeCompare(b.value)
193+
),
194+
(a, b) => a?.value !== b?.value
191195
)
192196
);
193197

@@ -222,9 +226,13 @@ export const getChangesForProject = (
222226
genListChange(
223227
'Teams',
224228
'',
225-
originalProject.teams.map((team) => ({ ...team, value: team.teamName })),
226-
proposedChanges.teams.map((team) => ({ ...team, value: team.teamName })),
227-
(a, b) => a.teamId === b.teamId
229+
originalProject.teams
230+
.map((team) => ({ ...team, value: team.teamName }))
231+
.sort((a, b) => a.teamName.localeCompare(b.teamName)),
232+
proposedChanges.teams
233+
.map((team) => ({ ...team, value: team.teamName }))
234+
.sort((a, b) => a.teamName.localeCompare(b.teamName)),
235+
(a, b) => a?.teamId !== b?.teamId
228236
)
229237
);
230238

@@ -273,6 +281,9 @@ export const getChangesForWorkPackage = (
273281
)
274282
);
275283

284+
const statusChanged = originalWorkPackage?.status !== proposedChanges?.status;
285+
lines.push(genChange('Status', statusChanged, originalWorkPackage?.status ?? '', proposedChanges?.status ?? ''));
286+
276287
let proposedChangesEndDate;
277288

278289
if (proposedChanges) {
@@ -297,7 +308,7 @@ export const getChangesForWorkPackage = (
297308
'',
298309
originalWorkPackage?.blockedBy.map((wbsNum) => ({ ...wbsNum, value: wbsPipe(wbsNum) })) ?? [],
299310
proposedChanges?.blockedBy.map((wbsNum) => ({ ...wbsNum, value: wbsPipe(wbsNum) })) ?? [],
300-
(a, b) => equalsWbsNumber(a, b)
311+
(a, b) => a !== undefined && b !== undefined && equalsWbsNumber(a, b)
301312
)
302313
);
303314

0 commit comments

Comments
 (0)