Skip to content

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Feb 13, 2025
1 parent dc03191 commit 046922c
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export const useGridPaginationModel = (
>,
) => {
const logger = useGridLogger(apiRef, 'useGridPaginationModel');

const filterModel = useGridSelector(apiRef, gridFilterModelSelector);
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
const previousFilterModel = React.useRef<GridFilterModel>(filterModel);
const previousFilterModel = React.useRef<GridFilterModel>(gridFilterModelSelector(apiRef));

const rowHeight = Math.floor(props.rowHeight * densityFactor);
apiRef.current.registerControlState({
Expand Down Expand Up @@ -276,24 +274,27 @@ export const useGridPaginationModel = (
* because of and update of the operator from an item that does not have the value
* or reseting when the filter panel is just opened
*/
const handleFilterModelChange = React.useCallback(() => {
const paginationModel = gridPaginationModelSelector(apiRef);
const currentActiveFilters = {
...filterModel,
// replace items with the active items
items: gridFilterActiveItemsSelector(apiRef),
};
const handleFilterModelChange = React.useCallback<GridEventListener<'filterModelChange'>>(
(filterModel) => {
const paginationModel = gridPaginationModelSelector(apiRef);
const currentActiveFilters = {
...filterModel,
// replace items with the active items
items: gridFilterActiveItemsSelector(apiRef),
};

if (isDeepEqual(currentActiveFilters, previousFilterModel.current)) {
return;
}
if (isDeepEqual(currentActiveFilters, previousFilterModel.current)) {
return;
}

previousFilterModel.current = currentActiveFilters;
previousFilterModel.current = currentActiveFilters;

if (paginationModel.page !== 0) {
apiRef.current.setPage(0);
}
}, [apiRef, filterModel]);
if (paginationModel.page !== 0) {
apiRef.current.setPage(0);
}
},
[apiRef],
);

useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
Expand Down

0 comments on commit 046922c

Please sign in to comment.