Skip to content

Commit 78b9811

Browse files
committed
#3884 addressed PR feedback
1 parent 69ee63d commit 78b9811

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/CopyBOM/CopyBOMModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CopyBOMModal: React.FC<CopyBOMModalProps> = ({ open, onHide, destinationWb
2020
const { data: projects, isLoading: isLoadingProjects, isError: projectsIsError, error: projectsError } = useAllProjects();
2121
const { mutateAsync: copyMaterials } = useCopyMaterialsToProject();
2222

23-
if (isLoadingCars || isLoadingProjects) return <LoadingIndicator />;
23+
if (isLoadingCars || !cars || isLoadingProjects || !projects) return <LoadingIndicator />;
2424
if (carsIsError) return <ErrorPage message={carsError?.message} />;
2525
if (projectsIsError) return <ErrorPage message={projectsError?.message} />;
2626

@@ -36,8 +36,8 @@ const CopyBOMModal: React.FC<CopyBOMModalProps> = ({ open, onHide, destinationWb
3636
<CopyBOMView
3737
open={open}
3838
onHide={onHide}
39-
cars={cars ?? []}
40-
projects={projects ?? []}
39+
cars={cars}
40+
projects={projects}
4141
selectedProject={selectedProject}
4242
setSelectedProject={setSelectedProject}
4343
onCopy={handleCopy}

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/CopyBOM/CopyBOMProjectSection.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
22
import { Typography } from '@mui/material';
33
import { DataGrid, GridColDef, GridSelectionModel } from '@mui/x-data-grid';
4+
import { useState } from 'react';
45
import { ProjectPreview } from 'shared';
56
import LoadingIndicator from '../../../../../components/LoadingIndicator';
67
import { useGetAssembliesForWbsElement, useGetMaterialsForWbsElement } from '../../../../../hooks/bom.hooks';
78
import ErrorPage from '../../../../ErrorPage';
89

910
interface CopyBOMProjectSectionProps {
1011
selectedProject: ProjectPreview;
11-
selectionModel: GridSelectionModel;
12-
setSelectionModel: (model: GridSelectionModel) => void;
12+
onSelectionChange: (materialIds: string[]) => void;
1313
}
1414

1515
const columns: GridColDef[] = [
@@ -21,9 +21,9 @@ const columns: GridColDef[] = [
2121

2222
const CopyBOMProjectSection: React.FC<CopyBOMProjectSectionProps> = ({
2323
selectedProject,
24-
selectionModel,
25-
setSelectionModel
24+
onSelectionChange
2625
}) => {
26+
const [selectionModel, setSelectionModel] = useState<GridSelectionModel>([]);
2727
const {
2828
data: materials,
2929
isLoading: isLoadingMaterials,
@@ -40,9 +40,11 @@ const CopyBOMProjectSection: React.FC<CopyBOMProjectSectionProps> = ({
4040

4141
React.useEffect(() => {
4242
if (materials) {
43-
setSelectionModel(materials.map((m) => m.materialId));
43+
const allIds = materials.map((m) => m.materialId);
44+
setSelectionModel(allIds);
45+
onSelectionChange(allIds);
4446
}
45-
}, [materials, setSelectionModel]);
47+
}, [materials]);
4648

4749
if (isLoadingMaterials || isLoadingAssemblies || !materials || !assemblies) return <LoadingIndicator />;
4850
if (isErrorMaterials) return <ErrorPage message={materialsError?.message} />;
@@ -67,7 +69,10 @@ const CopyBOMProjectSection: React.FC<CopyBOMProjectSectionProps> = ({
6769
checkboxSelection
6870
autoHeight
6971
selectionModel={selectionModel}
70-
onSelectionModelChange={(newModel) => setSelectionModel(newModel)}
72+
onSelectionModelChange={(newModel) => {
73+
setSelectionModel(newModel);
74+
onSelectionChange(newModel as string[]);
75+
}}
7176
rowsPerPageOptions={[100]}
7277
hideFooterPagination
7378
sx={{

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/CopyBOM/CopyBOMView.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState } from 'react';
22
import { Grid } from '@mui/material';
3-
import { GridSelectionModel } from '@mui/x-data-grid';
43
import { Car, ProjectPreview, wbsPipe } from 'shared';
54
import NERModal from '../../../../../components/NERModal';
65
import NERAutocomplete from '../../../../../components/NERAutocomplete';
@@ -26,7 +25,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
2625
onCopy
2726
}) => {
2827
const [selectedCar, setSelectedCar] = useState<Car | null>(null);
29-
const [selectionModel, setSelectionModel] = useState<GridSelectionModel>([]);
28+
const [selectedMaterialIds, setSelectedMaterialIds] = useState<string[]>([]);
3029

3130
const carOptions = cars.map((car) => ({
3231
label: `${car.wbsNum.carNumber} - ${car.name}`,
@@ -43,7 +42,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
4342
}));
4443

4544
const handleSubmit = async () => {
46-
await onCopy(selectionModel as string[]);
45+
await onCopy(selectedMaterialIds);
4746
};
4847

4948
return (
@@ -54,7 +53,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
5453
submitText="Copy BOM"
5554
cancelText="Cancel"
5655
onSubmit={handleSubmit}
57-
disabled={selectionModel.length === 0}
56+
disabled={selectedMaterialIds.length === 0}
5857
showCloseButton
5958
paperProps={{ minWidth: '700px' }}
6059
>
@@ -101,8 +100,7 @@ const CopyBOMView: React.FC<CopyBOMViewProps> = ({
101100
<Grid item xs={12}>
102101
<CopyBOMProjectSection
103102
selectedProject={selectedProject}
104-
selectionModel={selectionModel}
105-
setSelectionModel={setSelectionModel}
103+
onSelectionChange={setSelectedMaterialIds}
106104
/>
107105
</Grid>
108106
)}

0 commit comments

Comments
 (0)