Skip to content

Commit 5b05d7d

Browse files
committed
#1168: Added persistent filters for CR table
1 parent 4b86fc2 commit 5b05d7d

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/frontend/src/pages/ChangeRequestsPage/ChangeRequestsTable.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import { DataGrid, GridColDef, GridRow, GridRowProps, GridToolbar } from '@mui/x-data-grid';
6+
import { DataGrid, GridColDef, GridFilterModel, GridRow, GridRowProps, GridToolbar } from '@mui/x-data-grid';
77
import { routes } from '../../utils/routes';
88
import { datePipe, fullNamePipe, wbsPipe } from '../../utils/pipes';
99
import { useAllChangeRequests } from '../../hooks/change-requests.hooks';
@@ -135,6 +135,11 @@ const ChangeRequestsTable: React.FC = () => {
135135
}
136136
];
137137

138+
const filterValues = JSON.parse(
139+
// sets filter to a default value if no filter is stored in local storage
140+
localStorage.getItem('changeRequestsTableFilter') ?? '{"columnField": "crId", "operatorValue": "=", "value": ""}'
141+
);
142+
138143
return (
139144
<div>
140145
<DataGrid
@@ -182,7 +187,21 @@ const ChangeRequestsTable: React.FC = () => {
182187
quickFilterProps: { debounceMs: 500 }
183188
}
184189
}}
190+
onFilterModelChange={(filterModel: GridFilterModel) => {
191+
localStorage.setItem('changeRequestsTableFilter', JSON.stringify(filterModel.items[0]));
192+
}}
185193
initialState={{
194+
filter: {
195+
filterModel: {
196+
items: [
197+
{
198+
columnField: filterValues.columnField,
199+
operatorValue: filterValues.operatorValue,
200+
value: filterValues.value
201+
}
202+
]
203+
}
204+
},
186205
sorting: {
187206
sortModel: [{ field: 'crId', sort: 'desc' }]
188207
},

0 commit comments

Comments
 (0)