11import React from 'react' ;
22import { Typography } from '@mui/material' ;
33import { DataGrid , GridColDef , GridSelectionModel } from '@mui/x-data-grid' ;
4+ import { useState } from 'react' ;
45import { ProjectPreview } from 'shared' ;
56import LoadingIndicator from '../../../../../components/LoadingIndicator' ;
67import { useGetAssembliesForWbsElement , useGetMaterialsForWbsElement } from '../../../../../hooks/bom.hooks' ;
78import ErrorPage from '../../../../ErrorPage' ;
89
910interface CopyBOMProjectSectionProps {
1011 selectedProject : ProjectPreview ;
11- selectionModel : GridSelectionModel ;
12- setSelectionModel : ( model : GridSelectionModel ) => void ;
12+ onSelectionChange : ( materialIds : string [ ] ) => void ;
1313}
1414
1515const columns : GridColDef [ ] = [
@@ -21,9 +21,9 @@ const columns: GridColDef[] = [
2121
2222const 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 = { {
0 commit comments