Skip to content

Commit 4226109

Browse files
committed
status color and name abstraction
1 parent f442c71 commit 4226109

4 files changed

Lines changed: 21 additions & 71 deletions

File tree

src/frontend/src/pages/PartPage/PartPageComponents/PartDisplay.tsx

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11
import React from 'react';
22
import { Link, Box, Typography, Grid } from '@mui/material';
3-
import { Review_Status } from 'shared';
43
import { fullNamePipe } from '../../../utils/pipes';
54
import { useSinglePart } from '../../../hooks/part-review.hooks';
65
import LoadingIndicator from '../../../components/LoadingIndicator';
76
import ErrorPage from '../../ErrorPage';
87
import { Link as RouterLink } from 'react-router-dom';
8+
import { getReviewStatusDisplayName, getStatusColor } from '../../../utils/part.utils';
99

1010
interface PartDisplayProps {
1111
index: number;
1212
wbsNum: string;
1313
formatStyle: 'compact' | 'standard' | 'full';
1414
}
1515

16-
const getReviewStatusColor = (status: Review_Status) => {
17-
return {
18-
IN_PROGRESS: '#959696',
19-
READY_FOR_REVIEW: '#F61517',
20-
IN_REVIEW: '#F57600',
21-
REVIEWED: '#3CA848',
22-
APPROVED: '#D633FF',
23-
default: '#535151'
24-
}[status];
25-
};
26-
27-
const getReviewStatusDisplayName = (status: Review_Status): string => {
28-
return {
29-
IN_PROGRESS: 'In Progress',
30-
READY_FOR_REVIEW: 'Ready for Review',
31-
IN_REVIEW: 'In Review',
32-
REVIEWED: 'Reviewed',
33-
APPROVED: 'Approved',
34-
default: 'Unknown'
35-
}[status];
36-
};
37-
3816
// defined a Pill shape for the review status display
3917
const Pill = ({ label = '', bgColor = 'background.paper' }) => {
4018
return (
@@ -200,7 +178,7 @@ const PartDisplay: React.FC<PartDisplayProps> = ({ index, wbsNum, formatStyle: c
200178
justifyContent: 'center'
201179
}}
202180
>
203-
<Pill label={getReviewStatusDisplayName(part.status)} bgColor={getReviewStatusColor(part.status)} />
181+
<Pill label={getReviewStatusDisplayName(part.status)} bgColor={getStatusColor(part.status)} />
204182
</Grid>
205183
</Grid>
206184
</Link>

src/frontend/src/pages/PartPage/PartPageComponents/PartOverview.tsx

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,14 @@
11
import { Box, Typography, IconButton, Chip, Stack } from '@mui/material';
22
import NotificationsNoneIcon from '@mui/icons-material/NotificationsNone';
33
import { Part, Review_Status, User } from 'shared';
4-
5-
/**
6-
* gets the status color for each status case
7-
*/
8-
const getReviewStatusColor = (status: Review_Status) => {
9-
switch (status) {
10-
case 'IN_PROGRESS':
11-
return '#0000FF';
12-
case 'READY_FOR_REVIEW':
13-
return '#FF0000';
14-
case 'IN_REVIEW':
15-
return '#F57600';
16-
case 'REVIEWED':
17-
return '#3DA848';
18-
case 'APPROVED':
19-
return '#D633FF';
20-
default:
21-
return '#535151';
22-
}
23-
};
24-
25-
/**
26-
* converts a status to a string name format
27-
*/
28-
const getReviewStatusDisplayName = (status: Review_Status) => {
29-
switch (status) {
30-
case 'IN_PROGRESS':
31-
return 'Part In Progress';
32-
case 'READY_FOR_REVIEW':
33-
return 'Ready For Review';
34-
case 'IN_REVIEW':
35-
return 'In Review';
36-
case 'REVIEWED':
37-
return 'Reviewed';
38-
case 'APPROVED':
39-
return 'Approved';
40-
default:
41-
return 'N/A';
42-
}
43-
};
4+
import { getReviewStatusDisplayName, getStatusColor } from '../../../utils/part.utils';
445

456
const PartReviewStatusPill = (status: Review_Status) => {
467
return (
478
<Chip
489
label={getReviewStatusDisplayName(status)}
4910
sx={{
50-
backgroundColor: getReviewStatusColor(status),
11+
backgroundColor: getStatusColor(status),
5112
ml: 1.5,
5213
width: 150
5314
}}

src/frontend/src/pages/PartPage/PartPageComponents/PdfDisplay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ const PDFViewer: React.FC<FileDisplayProps> = ({ submission, review, hasNext, ne
573573
file={pdf}
574574
onLoadSuccess={({ numPages }) => {
575575
setLoadSuccess(true);
576-
setNumPages(numPages);
576+
setNumPages(numPages ?? 0);
577577
}}
578578
onLoadError={() => {
579579
setLoadSuccess(false);

src/frontend/src/utils/part.utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Part, PartReview, PartReviewRequest, PartSubmission, Review_Status, User } from 'shared';
2-
import { yellow, blue, purple, green, grey } from '@mui/material/colors';
2+
import { yellow,purple, green, grey, red } from '@mui/material/colors';
33

44
type HistoryEntry = [Date, string];
55

@@ -145,16 +145,27 @@ export const formatPartStatus = (status: Review_Status): string => {
145145
export const getStatusColor = (status: Review_Status): string => {
146146
switch (status) {
147147
case Review_Status.IN_PROGRESS:
148-
return yellow[700];
148+
return grey[600];
149149
case Review_Status.READY_FOR_REVIEW:
150-
return blue[600];
150+
return red[600];
151151
case Review_Status.IN_REVIEW:
152-
return purple[600];
152+
return yellow[700];
153153
case Review_Status.REVIEWED:
154154
return green[600];
155155
case Review_Status.APPROVED:
156-
return green[800];
156+
return purple[600];
157157
default:
158158
return grey[600];
159159
}
160160
};
161+
162+
export const getReviewStatusDisplayName = (status: Review_Status): string => {
163+
return {
164+
IN_PROGRESS: 'In Progress',
165+
READY_FOR_REVIEW: 'Ready for Review',
166+
IN_REVIEW: 'In Review',
167+
REVIEWED: 'Reviewed',
168+
APPROVED: 'Approved',
169+
default: 'Unknown'
170+
}[status];
171+
};

0 commit comments

Comments
 (0)