Skip to content

Commit

Permalink
optimize logic
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rajat19 committed Dec 12, 2024
1 parent 5481d03 commit 4304555
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,22 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
const filterModelItem = filterModel?.items.find(
(it) => it.field === colDef.field && it.operator !== 'isAnyOf',
);
const defaultCachedItem = filterItemsCache[colDef.field];
if (filterModelItem != null) {
// there's a valid `filterModelItem` for this column
if (defaultCachedItem != null) {
// operator for this column has changed
if (defaultCachedItem.operator !== filterModelItem.operator) {
defaultCachedItem.operator = filterModelItem.operator;
}
return filterModelItem;
}
const defaultItem = getGridFilter(colDef);
filterItemsCache[colDef.field] = defaultItem;
filterItemsCache[colDef.field].operator = filterModelItem.operator;
return filterModelItem;
}
const defaultCachedItem = filterItemsCache[colDef.field];

if (defaultCachedItem != null) {
// there's a cached `defaultItem` for this column
return defaultCachedItem;
Expand Down

0 comments on commit 4304555

Please sign in to comment.