Skip to content

Commit d30e2d5

Browse files
authored
fix(AnalyticalTable): prevent error if onFilter is not defined (#7388)
1 parent 1d5031b commit d30e2d5

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
188188
const tableInstanceRef = useRef<TableInstance>(null);
189189
const scrollContainerRef = useRef<HTMLDivElement>(null);
190190

191-
const dedupedOnFilter = useMemo(() => debounce(onFilter, 0), [onFilter]);
191+
const dedupedOnFilter = useMemo(
192+
() => (typeof onFilter === 'function' ? debounce(onFilter, 0) : undefined),
193+
[onFilter],
194+
);
195+
192196
useEffect(
193197
() => () => {
194-
dedupedOnFilter.cancel();
198+
dedupedOnFilter?.cancel();
195199
},
196200
[dedupedOnFilter],
197201
);

packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ export const stateReducer = (state, action, _prevState, instance: TableInstance)
2828
};
2929
}
3030
switch (action.type) {
31-
case 'setFilter':
32-
instance.webComponentsReactProperties.onFilter({
33-
filters: state.filters,
34-
value: action.filterValue,
35-
columnId: action.columnId,
36-
});
31+
case 'setFilter': {
32+
const { onFilter } = instance.webComponentsReactProperties;
33+
if (typeof onFilter === 'function') {
34+
instance.webComponentsReactProperties.onFilter({
35+
filters: state.filters,
36+
value: action.filterValue,
37+
columnId: action.columnId,
38+
});
39+
}
3740
return state;
41+
}
3842
case 'toggleRowExpanded':
3943
// this flag disables scrolling to the top of the table if a table is collapsed
4044
if (!state.expanded[action.id]) {

0 commit comments

Comments
 (0)