33 * See the LICENSE file in the repository root folder for details.
44 */
55
6- import { DataGrid , GridColDef , GridFilterModel , GridRow , GridRowProps , GridToolbar } from '@mui/x-data-grid' ;
6+ import {
7+ DataGrid ,
8+ GridColDef ,
9+ GridFilterModel ,
10+ GridRow ,
11+ GridRowProps ,
12+ GridToolbarContainer ,
13+ GridToolbarFilterButton ,
14+ GridToolbarQuickFilter
15+ } from '@mui/x-data-grid' ;
716import { routes } from '../../utils/routes' ;
817import { datePipe , fullNamePipe , wbsPipe } from '../../utils/pipes' ;
918import { useAllChangeRequests } from '../../hooks/change-requests.hooks' ;
1019import LoadingIndicator from '../../components/LoadingIndicator' ;
1120import ErrorPage from '../ErrorPage' ;
12- import { useTheme } from '@mui/system' ;
13- import { useState } from 'react' ;
21+ import { Box , useTheme } from '@mui/system' ;
22+ import { useEffect , useState } from 'react' ;
1423import { ChangeRequest , ChangeRequestType , validateWBS , WbsNumber } from 'shared' ;
1524import { GridColDefStyle } from '../../utils/tables' ;
1625import { Link } from '@mui/material' ;
1726import { Link as RouterLink } from 'react-router-dom' ;
1827
28+ const CustomToolbar = ( ) => (
29+ < GridToolbarContainer >
30+ < GridToolbarQuickFilter />
31+ < GridToolbarFilterButton />
32+ </ GridToolbarContainer >
33+ ) ;
34+
1935const ChangeRequestsTable : React . FC = ( ) => {
36+ const [ windowSize , setWindowSize ] = useState ( window . innerWidth ) ;
2037 const { isLoading, isError, data, error } = useAllChangeRequests ( ) ;
2138 if ( localStorage . getItem ( 'cr-table-row-count' ) === null ) {
2239 localStorage . setItem ( 'cr-table-row-count' , '50' ) ;
@@ -32,10 +49,71 @@ const ChangeRequestsTable: React.FC = () => {
3249
3350 const theme = useTheme ( ) ;
3451
52+ useEffect ( ( ) => {
53+ function handleResize ( ) {
54+ setWindowSize ( window . innerWidth ) ;
55+ }
56+
57+ // Attach the event listener to the window object
58+ window . addEventListener ( 'resize' , handleResize ) ;
59+
60+ // Remove the event listener when the component unmounts
61+ return ( ) => {
62+ window . removeEventListener ( 'resize' , handleResize ) ;
63+ } ;
64+ } , [ ] ) ;
65+
3566 if ( isLoading || ! data ) return < LoadingIndicator /> ;
3667
3768 if ( isError ) return < ErrorPage message = { error ?. message } /> ;
3869
70+ const smallColumns : GridColDef [ ] = [
71+ {
72+ ...baseColDef ,
73+ field : 'crId' ,
74+ type : 'number' ,
75+ headerName : 'ID' ,
76+ maxWidth : 75
77+ } ,
78+ {
79+ ...baseColDef ,
80+ field : 'dateReviewed' ,
81+ headerName : 'Date Reviewed' ,
82+ type : 'date' ,
83+ valueFormatter : ( params ) => ( params . value ? datePipe ( params . value ) : '' ) ,
84+ maxWidth : 200
85+ } ,
86+ {
87+ ...baseColDef ,
88+ field : 'wbs' ,
89+ headerName : 'WBS' ,
90+ filterable : true ,
91+ sortable : true ,
92+ maxWidth : 300 ,
93+ valueGetter : ( params ) => `${ wbsPipe ( params . value . wbsNum ) } - ${ params . value . name } ` ,
94+ sortComparator : ( _v1 , _v2 , param1 , param2 ) => {
95+ const wbs1 : WbsNumber = validateWBS ( ( param1 . value as string ) . split ( ' ' ) [ 0 ] ) ;
96+ const wbs2 : WbsNumber = validateWBS ( ( param2 . value as string ) . split ( ' ' ) [ 0 ] ) ;
97+
98+ if ( wbs1 . carNumber !== wbs2 . carNumber ) {
99+ return wbs1 . carNumber - wbs2 . carNumber ;
100+ } else if ( wbs1 . projectNumber !== wbs2 . projectNumber ) {
101+ return wbs1 . projectNumber - wbs2 . projectNumber ;
102+ } else if ( wbs1 . workPackageNumber !== wbs2 . workPackageNumber ) {
103+ return wbs1 . workPackageNumber - wbs2 . workPackageNumber ;
104+ } else {
105+ return 0 ;
106+ }
107+ }
108+ } ,
109+ {
110+ ...baseColDef ,
111+ field : 'submitter' ,
112+ headerName : 'Submitter' ,
113+ maxWidth : 200
114+ }
115+ ] ;
116+
39117 const columns : GridColDef [ ] = [
40118 {
41119 ...baseColDef ,
@@ -141,7 +219,15 @@ const ChangeRequestsTable: React.FC = () => {
141219 ) ;
142220
143221 return (
144- < div >
222+ < Box
223+ sx = { {
224+ '& .Mui-even' : {
225+ backgroundColor : theme . palette . background . paper ,
226+ border : `1px solid ${ theme . palette . mode === 'light' ? '#f0f0f0' : '#303030' } `
227+ } ,
228+ '& .Mui-odd' : { border : `1px solid ${ theme . palette . mode === 'light' ? '#f0f0f0' : '#303030' } ` }
229+ } }
230+ >
145231 < DataGrid
146232 autoHeight
147233 disableSelectionOnClick
@@ -164,11 +250,27 @@ const ChangeRequestsTable: React.FC = () => {
164250 reviewer : fullNamePipe ( v . reviewer )
165251 } ) ) || [ ]
166252 }
167- columns = { columns }
253+ columns = { windowSize < 1000 ? smallColumns : columns }
168254 getRowId = { ( row ) => row . crId }
169- sx = { { background : theme . palette . background . paper } }
255+ sx = { {
256+ border : 0 ,
257+ '& .MuiDataGrid-row:hover' : {
258+ backgroundColor : '#ef4345'
259+ } ,
260+ '& .MuiDataGrid-columnHeader' : {
261+ borderRight : `1px solid ${ theme . palette . mode === 'light' ? '#f0f0f0' : '#303030' } ` ,
262+ borderLeft : `1px solid ${ theme . palette . mode === 'light' ? '#f0f0f0' : '#303030' } `
263+ } ,
264+ '& .MuiDataGrid-columnHeaders' : {
265+ border : `1px solid ${ theme . palette . mode === 'light' ? '#f0f0f0' : '#303030' } `
266+ } ,
267+ '.MuiDataGrid-columnSeparator' : {
268+ display : 'none'
269+ }
270+ } }
271+ getRowClassName = { ( params ) => ( params . indexRelativeToCurrentPage % 2 === 0 ? 'Mui-even' : 'Mui-odd' ) }
170272 components = { {
171- Toolbar : GridToolbar ,
273+ Toolbar : CustomToolbar ,
172274 Row : ( props : GridRowProps & { row : ChangeRequest } ) => {
173275 return (
174276 < Link
@@ -213,7 +315,7 @@ const ChangeRequestsTable: React.FC = () => {
213315 }
214316 } }
215317 />
216- </ div >
318+ </ Box >
217319 ) ;
218320} ;
219321
0 commit comments