From abfb7279c44b10bc3df1a1493046d9db6da39199 Mon Sep 17 00:00:00 2001 From: Lukas Harbarth Date: Tue, 27 May 2025 16:51:27 +0200 Subject: [PATCH] fix(AnalyticalTable): prevent error if `onFilter` is not defined --- .../src/components/AnalyticalTable/index.tsx | 8 ++++++-- .../AnalyticalTable/tableReducer/stateReducer.ts | 16 ++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/main/src/components/AnalyticalTable/index.tsx b/packages/main/src/components/AnalyticalTable/index.tsx index 6c95a6f705b..5345e434964 100644 --- a/packages/main/src/components/AnalyticalTable/index.tsx +++ b/packages/main/src/components/AnalyticalTable/index.tsx @@ -188,10 +188,14 @@ const AnalyticalTable = forwardRef(null); const scrollContainerRef = useRef(null); - const dedupedOnFilter = useMemo(() => debounce(onFilter, 0), [onFilter]); + const dedupedOnFilter = useMemo( + () => (typeof onFilter === 'function' ? debounce(onFilter, 0) : undefined), + [onFilter], + ); + useEffect( () => () => { - dedupedOnFilter.cancel(); + dedupedOnFilter?.cancel(); }, [dedupedOnFilter], ); diff --git a/packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts b/packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts index 83341bd6707..fa8dba41345 100644 --- a/packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts +++ b/packages/main/src/components/AnalyticalTable/tableReducer/stateReducer.ts @@ -28,13 +28,17 @@ export const stateReducer = (state, action, _prevState, instance: TableInstance) }; } switch (action.type) { - case 'setFilter': - instance.webComponentsReactProperties.onFilter({ - filters: state.filters, - value: action.filterValue, - columnId: action.columnId, - }); + case 'setFilter': { + const { onFilter } = instance.webComponentsReactProperties; + if (typeof onFilter === 'function') { + instance.webComponentsReactProperties.onFilter({ + filters: state.filters, + value: action.filterValue, + columnId: action.columnId, + }); + } return state; + } case 'toggleRowExpanded': // this flag disables scrolling to the top of the table if a table is collapsed if (!state.expanded[action.id]) {