From 194d62cf23e30ae2b429f5d0e47fcb8f447a1bf2 Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Fri, 12 Nov 2021 08:19:18 +0100 Subject: [PATCH] fix(plugin-chart-pivot-table): cross filtering by adhoc column (#1465) --- .../src/PivotTableChart.tsx | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx b/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx index aab9575561..446c3929c8 100644 --- a/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx +++ b/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx @@ -23,6 +23,7 @@ import { DataRecordValue, getColumnLabel, getNumberFormatter, + isPhysicalColumn, NumberFormatter, styled, useTheme, @@ -35,6 +36,7 @@ import { // @ts-ignore } from '@superset-ui/react-pivottable/Utilities'; import '@superset-ui/react-pivottable/pivottable.css'; +import { isAdhocColumn } from '@superset-ui/chart-controls'; import { FilterType, MetricsLayoutEnum, @@ -192,14 +194,25 @@ export default function PivotTableChart(props: PivotTableProps) { const handleChange = useCallback( (filters: SelectedFiltersType) => { - const groupBy = Object.keys(filters); + const filterKeys = Object.keys(filters); + const groupby = [...groupbyRowsRaw, ...groupbyColumnsRaw]; setDataMask({ extraFormData: { filters: - groupBy.length === 0 + filterKeys.length === 0 ? undefined - : groupBy.map(col => { - const val = filters?.[col]; + : filterKeys.map(key => { + const val = filters?.[key]; + const col = + groupby.find(item => { + if (isPhysicalColumn(item)) { + return item === key; + } + if (isAdhocColumn(item)) { + return item.label === key; + } + return false; + }) ?? ''; if (val === null || val === undefined) return { col,