Skip to content

Commit c81a96d

Browse files
committed
#1637: abstracted type and status chips
1 parent 6e6a811 commit c81a96d

2 files changed

Lines changed: 79 additions & 30 deletions

File tree

src/frontend/src/components/ChangeRequestDetailCard.tsx

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { Card, CardContent, Grid, Typography } from '@mui/material';
6+
import { Card, CardContent, Grid, TextField, Typography } from '@mui/material';
77
import Chip from '@mui/material/Chip';
8-
import { green, blue, red, grey, orange } from '@mui/material/colors';
8+
import { green, blue, red, grey, orange, purple } from '@mui/material/colors';
99
import { Box, Stack } from '@mui/system';
1010
import { Link } from '@mui/material';
1111
import {
1212
ActivationChangeRequest,
1313
ChangeRequest,
14+
ChangeRequestStatus,
1415
ChangeRequestType,
1516
StageGateChangeRequest,
1617
StandardChangeRequest,
@@ -20,7 +21,7 @@ import { routes } from '../utils/routes';
2021
import { Link as RouterLink } from 'react-router-dom';
2122
import { datePipe, fullNamePipe } from '../utils/pipes';
2223
import { Cancel, Construction, DateRange, Description, DoneAll, Person, Start, Work } from '@mui/icons-material';
23-
import { ChangeRequestTypeTextPipe } from '../utils/enum-pipes';
24+
import { ChangeRequestTypeTextPipe, ChangeRequestStatusTextPipe } from '../utils/enum-pipes';
2425

2526
const determineChangeRequestTypeView = (cr: ChangeRequest) => {
2627
switch (cr.type) {
@@ -33,7 +34,7 @@ const determineChangeRequestTypeView = (cr: ChangeRequest) => {
3334
}
3435
};
3536

36-
const determineChangeRequestPillColor = (type: ChangeRequestType) => {
37+
const determineChangeRequestTypePillColor = (type: ChangeRequestType) => {
3738
switch (type) {
3839
case 'STAGE_GATE':
3940
return orange[900];
@@ -48,6 +49,21 @@ const determineChangeRequestPillColor = (type: ChangeRequestType) => {
4849
}
4950
};
5051

52+
const determineChangeRequestStatusPillColor = (status: ChangeRequestStatus) => {
53+
switch (status) {
54+
case 'Implemented':
55+
return blue[600];
56+
case 'Accepted':
57+
return green[600];
58+
case 'Denied':
59+
return red[400];
60+
case 'Open':
61+
return purple[400];
62+
default:
63+
return grey[500];
64+
}
65+
};
66+
5167
const StandardCardDetails = ({ cr }: { cr: StandardChangeRequest }) => {
5268
return (
5369
<Grid container mt={1} ml={'2px'}>
@@ -97,53 +113,73 @@ const ActivationCardDetails = ({ cr }: { cr: ActivationChangeRequest }) => {
97113
);
98114
};
99115

116+
const ChangeRequestTypePill = ({ type }: { type: ChangeRequestType }) => {
117+
return (
118+
<Chip
119+
size="small"
120+
label={ChangeRequestTypeTextPipe(type)}
121+
variant="filled"
122+
sx={{
123+
fontSize: 12,
124+
color: 'white',
125+
backgroundColor: red[600],
126+
mb: 0.5
127+
}}
128+
/>
129+
);
130+
};
131+
132+
const ChangeRequestStatusPill = ({ status }: { status: ChangeRequestStatus }) => {
133+
const statusPillColor = determineChangeRequestStatusPillColor(status);
134+
return (
135+
<Chip
136+
size="small"
137+
label={ChangeRequestStatusTextPipe(status)}
138+
variant="filled"
139+
sx={{
140+
fontSize: 12,
141+
color: 'white',
142+
backgroundColor: statusPillColor,
143+
mb: 0.5
144+
}}
145+
/>
146+
);
147+
};
148+
100149
interface ChangeRequestDetailCardProps {
101150
changeRequest: ChangeRequest;
102151
}
103152

104153
// Convert work package stage into badge for display
105154
const ChangeRequestDetailCard: React.FC<ChangeRequestDetailCardProps> = ({ changeRequest }) => {
106155
const ChangeRequestTypeView = () => determineChangeRequestTypeView(changeRequest);
107-
const pillColor = determineChangeRequestPillColor(changeRequest.type);
108156
return (
109157
<Card sx={{ width: 300, mr: 1, mb: 1, borderRadius: 5 }}>
110158
<CardContent>
111-
<Grid container justifyContent="space-between" alignItems="center">
159+
<Grid container justifyContent="space-between" alignItems="flex-start">
112160
<Grid item>
113161
<Link component={RouterLink} to={`${routes.CHANGE_REQUESTS}/${changeRequest.crId}`} noWrap>
114162
<Typography variant="h6" sx={{ mb: 0.5 }}>
115-
{'CR #' + changeRequest.crId}
163+
{'Change Request #' + changeRequest.crId}
116164
</Typography>
117165
</Link>
118-
</Grid>
119-
<Grid item display="flex" justifyContent="flex-end">
120166
<Chip
121-
size="small"
122-
label={ChangeRequestTypeTextPipe(changeRequest.type)}
123-
variant="outlined"
124-
sx={{
125-
fontSize: 12,
126-
color: pillColor,
127-
borderColor: pillColor,
128-
mb: 0.5
129-
}}
167+
label={`From: ${fullNamePipe(changeRequest.submitter)}`}
168+
sx={{ mr: 2, ml: -1.5, backgroundColor: 'transparent', maxWidth: '150', fontWeight: 'bold' }}
130169
/>
131170
</Grid>
171+
<Grid item display="flex" justifyContent="flex-end">
172+
<Stack direction={'column'} spacing={1}>
173+
<ChangeRequestTypePill type={changeRequest.type} />
174+
<ChangeRequestStatusPill status={changeRequest.status} />
175+
</Stack>
176+
</Grid>
132177
</Grid>
133-
<Stack direction="row">
134-
<Chip
135-
icon={<Person />}
136-
label={fullNamePipe(changeRequest.submitter)}
137-
sx={{ mr: 2, ml: -1, backgroundColor: 'transparent', maxWidth: '150' }}
138-
/>
139-
<Chip icon={<DateRange />} label={datePipe(changeRequest.dateSubmitted)} sx={{ backgroundColor: 'transparent' }} />
140-
</Stack>
141-
<Typography fontWeight={'regular'} variant="h6" fontSize={16} noWrap>
178+
<Typography fontWeight={'bold'} variant="h5" fontSize={16} noWrap>
142179
<Link component={RouterLink} to={`${routes.PROJECTS}/${wbsPipe(changeRequest.wbsNum)}`}>
143-
{wbsPipe(changeRequest.wbsNum)} - {changeRequest.wbsName}
180+
WBS: {wbsPipe(changeRequest.wbsNum)} - {changeRequest.wbsName}
144181
</Link>
145182
</Typography>
146-
<ChangeRequestTypeView />
147183
</CardContent>
148184
</Card>
149185
);

src/frontend/src/utils/enum-pipes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { yellow, green, blue, purple, grey } from '@mui/material/colors';
7-
import { ChangeRequestType, WorkPackageStage } from 'shared';
7+
import { ChangeRequestStatus, ChangeRequestType, WorkPackageStage } from 'shared';
88

99
// maps stage to the desired color
1010
export const WorkPackageStageColorPipe: (stage: WorkPackageStage | undefined) => string = (stage) => {
@@ -52,3 +52,16 @@ export const ChangeRequestTypeTextPipe: (type: ChangeRequestType) => string = (t
5252
return 'Other';
5353
}
5454
};
55+
56+
export const ChangeRequestStatusTextPipe: (status: ChangeRequestStatus) => string = (status) => {
57+
switch (status) {
58+
case ChangeRequestStatus.Implemented:
59+
return 'Implemented';
60+
case ChangeRequestStatus.Accepted:
61+
return 'Accepted';
62+
case ChangeRequestStatus.Denied:
63+
return 'Denied';
64+
case ChangeRequestStatus.Open:
65+
return 'Open';
66+
}
67+
};

0 commit comments

Comments
 (0)