Skip to content

Commit ff100eb

Browse files
committed
second round of frontend changes
1 parent 3687f5f commit ff100eb

11 files changed

Lines changed: 36 additions & 49 deletions

File tree

src/backend/src/routes/parts.routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import PartReviewController from '../controllers/part-review.controllers';
1313
import { Review_Status } from 'shared';
1414
import multer, { memoryStorage } from 'multer';
1515

16-
const upload = multer({ limits: { fileSize: 30000000 }, storage: memoryStorage() });
16+
//limit uploads to 5 mb per file
17+
const upload = multer({ limits: { fileSize: 5 * 1024 * 1024 }, storage: memoryStorage() });
1718

1819
const partsRouter = express.Router();
1920

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const PDFViewer: React.FC<FileDisplayProps> = ({ submission, review, hasNext, ne
130130
pdfjs.GlobalWorkerOptions.workerPort.terminate();
131131
}
132132
};
133-
}, []);
133+
});
134134

135135
const { mutateAsync: addPopupToDb } = useCreateReviewPopup();
136136
const { mutateAsync: addCommonMistake } = useCreateCommonMistake();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PartPreview, Review_Status } from 'shared';
1+
import { PartPreview } from 'shared';
22
import { useCreatePartReview } from '../../../../../../hooks/part-review.hooks';
33
import ReviewFormModal from './ReviewFormModal';
44

@@ -11,16 +11,7 @@ interface CreateReviewModalProps {
1111
const CreateReviewModal = ({ open, handleClose, partsInProject }: CreateReviewModalProps) => {
1212
const { mutateAsync: createReview } = useCreatePartReview();
1313

14-
const onSubmit = async (data: { submissionId: string; status: Review_Status; notes?: string; fileIds: string[] }) => {
15-
await createReview({
16-
submissionId: data.submissionId,
17-
notes: data.notes,
18-
fileIds: data.fileIds,
19-
status: data.status
20-
});
21-
};
22-
23-
return <ReviewFormModal open={open} handleClose={handleClose} onSubmit={onSubmit} partsInProject={partsInProject} />;
14+
return <ReviewFormModal open={open} handleClose={handleClose} onSubmit={createReview} partsInProject={partsInProject} />;
2415
};
2516

2617
export default CreateReviewModal;

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/CreateSubmissionModal.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,11 @@ interface CreateSubmissionModalProps {
1212
const CreateSubmissionModal = ({ open, handleClose, partsInProject, currentPart }: CreateSubmissionModalProps) => {
1313
const { mutateAsync: createSubmission } = useCreatePartSubmission();
1414

15-
const onSubmit = async (data: { partId: string; name: string; notes?: string; fileIds: string[] }) => {
16-
await createSubmission({
17-
partId: data.partId,
18-
name: data.name,
19-
fileIds: data.fileIds,
20-
notes: data.notes
21-
});
22-
};
23-
2415
return (
2516
<SubmissionFormModal
2617
open={open}
2718
handleClose={handleClose}
28-
onSubmit={onSubmit}
19+
onSubmit={createSubmission}
2920
partsInProject={partsInProject}
3021
currentPart={currentPart}
3122
/>

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/PartFormModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ const PartFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInProj
3939
wbsNum: yup.string().required(),
4040
index: yup
4141
.number()
42+
.integer()
4243
.lessThan(99999, 'Index must be less than 5 digits')
44+
.positive()
4345
.required()
4446
.test({
4547
name: 'unique-index',
@@ -74,14 +76,14 @@ const PartFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInProj
7476

7577
const onFormSubmit = async (data: PartPayload) => {
7678
try {
77-
closeForm();
7879
await onSubmit({
7980
...data,
8081
reviewStatus: defaultValues ? defaultValues.status : Review_Status.IN_PROGRESS,
8182
tagIds,
8283
assigneeIds,
8384
reviewerIds
8485
});
86+
closeForm();
8587
toast.success(!!defaultValues ? 'Part Successfully Edited' : 'Part Successfully Created');
8688
} catch (error: unknown) {
8789
if (error instanceof Error) {

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/ReviewFormModal.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FormControl, FormHelperText, FormLabel, TextField } from '@mui/material
1010
import ReactHookTextField from '../../../../../../components/ReactHookTextField';
1111
import { Delete, FileUpload } from '@mui/icons-material';
1212
import { useUploadFile } from '../../../../../../hooks/part-review.hooks';
13+
import { MAX_PART_FILE_SIZE } from '../../../../../../utils/part.utils';
1314

1415
interface ReviewFormModalProps {
1516
open: boolean;
@@ -19,8 +20,6 @@ interface ReviewFormModalProps {
1920
partsInProject: PartPreview[];
2021
}
2122

22-
const MAX_FILE_SIZE = 5 * 1024 * 1024;
23-
2423
const ReviewFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInProject }: ReviewFormModalProps) => {
2524
const toast = useToast();
2625
const [files, setFiles] = useState<File[]>([]);
@@ -57,7 +56,7 @@ const ReviewFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInPr
5756
name: 'fileIds'
5857
});
5958

60-
const [selectedPartIndex, setSelectedPartIndex] = useState<number | null>(null);
59+
const [selectedPartIndex, setSelectedPartIndex] = useState<number>();
6160

6261
const onFormSubmit = async (data: { submissionId: string; status: Review_Status; notes?: string; fileIds: string[] }) => {
6362
try {
@@ -109,7 +108,7 @@ const ReviewFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInPr
109108
renderInput={(params) => (
110109
<TextField {...params} variant="outlined" placeholder="Select a Part" error={false} />
111110
)}
112-
onChange={(_event, newValue) => setSelectedPartIndex(newValue ? newValue.index : null)}
111+
onChange={(_event, newValue) => setSelectedPartIndex(newValue?.index)}
113112
/>
114113
</FormControl>
115114
</Grid>
@@ -164,8 +163,10 @@ const ReviewFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInPr
164163
}
165164
setUploading(true);
166165
[...e.target.files]?.forEach(async (file, index) => {
167-
if (file.size > MAX_FILE_SIZE) {
168-
toast.error(`File "${file.name}" exceeds the maximum size limit of ${MAX_FILE_SIZE} bytes`);
166+
if (file.size > MAX_PART_FILE_SIZE) {
167+
toast.error(
168+
`File "${file.name}" exceeds the maximum size limit of ${MAX_PART_FILE_SIZE / (1024 * 2014)} mbs`
169+
);
169170
checkLast(index);
170171
return;
171172
}

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/SubmissionFormModal.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FormControl, FormHelperText, FormLabel, TextField } from '@mui/material
1010
import ReactHookTextField from '../../../../../../components/ReactHookTextField';
1111
import { Delete, FileUpload } from '@mui/icons-material';
1212
import { useUploadFile } from '../../../../../../hooks/part-review.hooks';
13+
import { getFileUploadDisplayName, MAX_PART_FILE_SIZE } from '../../../../../../utils/part.utils';
1314

1415
interface SubmissionFormModalProps {
1516
open: boolean;
@@ -20,8 +21,6 @@ interface SubmissionFormModalProps {
2021
partsInProject: PartPreview[];
2122
}
2223

23-
const MAX_FILE_SIZE = 5 * 1024 * 1024;
24-
2524
const isPdf = (fileName: string) => {
2625
const extension = fileName.split('.').pop()?.toLowerCase();
2726
return extension === 'pdf';
@@ -100,10 +99,6 @@ const SubmissionFormModal = ({
10099
reset();
101100
};
102101

103-
const displayName = (name: string) => {
104-
return name.length <= 15 ? name : name.slice(0, 14) + '...';
105-
};
106-
107102
return (
108103
<NERFormModal
109104
open={open}
@@ -148,7 +143,7 @@ const SubmissionFormModal = ({
148143
fileIds.map((file, index) => {
149144
return (
150145
<ListItem key={file.id}>
151-
<Typography>{displayName(files[index].name)}</Typography>
146+
<Typography>{getFileUploadDisplayName(files[index].name)}</Typography>
152147
<IconButton
153148
onClick={() => {
154149
setFiles((prevFiles) => [...prevFiles.slice(0, index), ...prevFiles.slice(index + 1)]);
@@ -191,8 +186,10 @@ const SubmissionFormModal = ({
191186
}
192187
setUploading(true);
193188
[...e.target.files]?.forEach(async (file, index) => {
194-
if (file.size > MAX_FILE_SIZE) {
195-
toast.error(`File "${file.name}" exceeds the maximum size limit of ${MAX_FILE_SIZE} bytes`);
189+
if (file.size > MAX_PART_FILE_SIZE) {
190+
toast.error(
191+
`File "${file.name}" exceeds the maximum size limit of ${MAX_PART_FILE_SIZE / (1024 * 1024)} mbs`
192+
);
196193
checkLast(index);
197194
return;
198195
}

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/SubmissionGuide.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const SubmissionGuide: React.FC = () => {
5959
mx: 3,
6060
my: 1
6161
}}
62-
alt="Apply Interest"
62+
alt="Part Submission Sample Image"
6363
src={sampleImageUrl}
6464
/>
6565
) : (

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartsReviewPage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ const PartsReviewPage = ({ project }: { project: Project }) => {
5959
// filtering state
6060
const [showFilters, setShowFilters] = useState(false);
6161
const [searchValue, setSearchValue] = useState<string>('');
62+
//empty array means filter is not in use, therefore every value should pass
6263
const [statuses, setStatuses] = useState<Review_Status[]>([]);
6364
const [assigneeIds, setAssigneeIds] = useState<string[]>([]);
6465
const [reviewerIds, setReviewerIds] = useState<string[]>([]);
6566
const [tagIds, setTagIds] = useState<string[]>([]);
6667

6768
const filteredParts = useMemo(() => {
69+
//length checks ensure that non-used filters aren't checked against
6870
return parts?.filter((part) => {
6971
if (statuses.length !== 0 && !statuses.includes(part.status)) return false;
7072
if (assigneeIds.length !== 0 && !assigneeIds.some((id) => part.assignees.some((assignee) => assignee.userId === id)))
@@ -309,23 +311,23 @@ const PartsReviewPage = ({ project }: { project: Project }) => {
309311
{(partsForMeToReview ?? []).length > 0 && (
310312
<PartsToReview
311313
project={project}
312-
parts={partsForMeToReview}
314+
parts={partsForMeToReview ?? []}
313315
formatStyle={formatStyle}
314316
title={'Parts For Me To Review'}
315317
/>
316318
)}
317319
{(myPartsUnderReview ?? []).length > 0 && (
318320
<PartsToReview
319321
project={project}
320-
parts={myPartsUnderReview}
322+
parts={myPartsUnderReview ?? []}
321323
formatStyle={formatStyle}
322324
title={'My Parts Under Review'}
323325
/>
324326
)}
325327
{(allPartsUnderReview ?? []).length > 0 && (
326328
<PartsToReview
327329
project={project}
328-
parts={allPartsUnderReview}
330+
parts={allPartsUnderReview ?? []}
329331
formatStyle={formatStyle}
330332
title={'All Parts Under Review'}
331333
/>

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartsToReview.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ import PartDisplay from '../../../PartPage/PartPageComponents/PartDisplay';
66

77
interface PartsToReviewProps {
88
project: Project;
9-
parts: PartPreview[] | undefined;
9+
parts: PartPreview[];
1010
formatStyle: 'compact' | 'standard' | 'full';
1111
title: string;
1212
}
1313

1414
const MyPartsUnderReview: React.FC<PartsToReviewProps> = ({ project, parts, formatStyle, title }) => {
15-
// Show the list only if there are items to show
16-
if (!parts) {
17-
return null;
18-
}
19-
2015
return (
2116
<Grid item xs={12} md={formatStyle === 'full' ? 12 : formatStyle === 'standard' ? 6 : 4}>
2217
<Typography variant="h5" sx={{ mb: 1 }}>

0 commit comments

Comments
 (0)