@@ -27,6 +27,7 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
2727 const theme = useTheme ( ) ;
2828
2929 const rows : BomRow [ ] = noAssemblyMaterials . map ( ( material : Material , idx : number ) => materialToRow ( material , idx ) ) ;
30+
3031 const isAssemblyOpen = ( row : BomRow ) => {
3132 return ! row . assemblyId || row . assemblyId === '' || openRows . includes ( row . assemblyId ) || row . id . startsWith ( 'assembly' ) ;
3233 } ;
@@ -44,6 +45,7 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
4445
4546 assemblies . forEach ( ( assembly ) => {
4647 const assemblyMaterials = materials . filter ( ( material ) => material . assemblyId === assembly . assemblyId ) ;
48+
4749 materialsWithAssemblies . push ( {
4850 reimbursementRequestId : undefined ,
4951 id : `assembly-${ assembly . name } ` ,
@@ -63,11 +65,10 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
6365 notes : '' ,
6466 assemblyId : assembly . assemblyId
6567 } ) ;
68+
6669 assemblyMaterials . forEach ( ( material , indx ) => materialsWithAssemblies . push ( materialToRow ( material , indx ) ) ) ;
6770 } ) ;
6871
69- // drag and drop mechanics
70-
7172 const handleDragStart = ( materialId : string ) => {
7273 const material = materials . find ( ( m ) => m . materialId === materialId ) ;
7374 if ( material ) {
@@ -82,6 +83,7 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
8283 const handleDrop = ( event : React . DragEvent , targetAssemblyId ?: string ) => {
8384 event . preventDefault ( ) ;
8485 if ( ! draggedMaterial ) return ;
86+
8587 assignMaterial ( draggedMaterial . materialId , targetAssemblyId ) ( ) . finally ( ( ) => {
8688 setDraggedMaterial ( null ) ;
8789 } ) ;
@@ -95,32 +97,30 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
9597 '& .super-app-theme--header' : {
9698 backgroundColor : '#ef4345'
9799 } ,
98- '& .super-app-theme--assembly' : {
99- backgroundColor : theme . palette . grey [ 600 ] ,
100- '&:hover' : {
101- backgroundColor : theme . palette . grey [ 700 ]
102- } ,
103- '&:focus' : {
104- backgroundColor : '#997570'
105- }
100+ '& .super-app-theme--even' : {
101+ backgroundColor : theme . palette . grey [ 400 ]
102+ } ,
103+ '& .super-app-theme--odd' : {
104+ backgroundColor : 'transparent'
106105 }
107106 } }
108107 >
109108 < BomStyledDataGrid
110109 onColumnVisibilityModelChange = { ( model : GridColumnVisibilityModel ) => {
111- //store a state inside a parent array (array in a parent class), and then every time the state changes, update the parent state, add another part that, on reload, we check the parent state and update the child state
112110 const tempColumns : boolean [ ] = [ ] ;
113111 Object . keys ( model ) . forEach ( ( toDelete ) => {
114112 tempColumns . push ( ! model [ toDelete ] ) ;
115113 } ) ;
114+
116115 setHideColumn ( tempColumns ) ;
117116 localStorage . setItem ( 'hideColumn' , JSON . stringify ( tempColumns ) ) ;
118117 } }
119118 columns = { columns as GridColumns < GridValidRowModel > }
120119 rows = { rows . concat ( materialsWithAssemblies . filter ( isAssemblyOpen ) ) }
121- getRowClassName = { ( params ) =>
122- `super-app-theme--${ String ( params . row . id ) . includes ( 'assembly' ) ? 'assembly' : 'material' } `
123- }
120+ getRowClassName = { ( params ) => {
121+ const stripe = params . indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd' ;
122+ return `super-app-theme--${ stripe } ` ;
123+ } }
124124 rowsPerPageOptions = { [ 100 ] }
125125 sx = { bomTableStyles . datagrid }
126126 disableSelectionOnClick
@@ -142,6 +142,7 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
142142 const rowIndex = parseInt ( event . currentTarget . getAttribute ( 'data-rowindex' ) || '0' ) ;
143143 const materials = rows . concat ( materialsWithAssemblies . filter ( isAssemblyOpen ) ) ;
144144 const { assemblyId } = materials [ rowIndex ] ;
145+
145146 if ( assemblyId === 'assembly-misc' ) {
146147 handleDrop ( event ) ;
147148 } else {
@@ -164,4 +165,5 @@ const BOMTable: React.FC<BOMTableProps> = ({ setHideColumn, assignMaterial, colu
164165 </ Box >
165166 ) ;
166167} ;
168+
167169export default BOMTable ;
0 commit comments