mirror of
https://github.com/apache/superset.git
synced 2026-04-23 01:55:09 +00:00
fix(table): cross-filtering breaks after renaming column labels via Custom SQL (#38858)
This commit is contained in:
@@ -345,6 +345,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
|
||||
hasServerPageLengthChanged,
|
||||
serverPageLength,
|
||||
slice_id,
|
||||
columnLabelToNameMap = {},
|
||||
} = props;
|
||||
|
||||
const comparisonColumns = useMemo(
|
||||
@@ -457,19 +458,22 @@ export default function TableChart<D extends DataRecord = DataRecord>(
|
||||
groupBy.length === 0
|
||||
? []
|
||||
: groupBy.map(col => {
|
||||
// Resolve adhoc column labels back to original column names
|
||||
// so that cross-filters work on the receiving chart
|
||||
const resolvedCol = columnLabelToNameMap[col] ?? col;
|
||||
const val = ensureIsArray(updatedFilters?.[col]);
|
||||
if (!val.length)
|
||||
return {
|
||||
col,
|
||||
col: resolvedCol,
|
||||
op: 'IS NULL' as const,
|
||||
};
|
||||
return {
|
||||
col,
|
||||
col: resolvedCol,
|
||||
op: 'IN' as const,
|
||||
val: val.map(el =>
|
||||
el instanceof Date ? el.getTime() : el!,
|
||||
),
|
||||
grain: col === DTTM_ALIAS ? timeGrain : undefined,
|
||||
grain: resolvedCol === DTTM_ALIAS ? timeGrain : undefined,
|
||||
};
|
||||
}),
|
||||
},
|
||||
@@ -485,7 +489,13 @@ export default function TableChart<D extends DataRecord = DataRecord>(
|
||||
isCurrentValueSelected: isActiveFilterValue(key, value),
|
||||
};
|
||||
},
|
||||
[filters, isActiveFilterValue, timestampFormatter, timeGrain],
|
||||
[
|
||||
filters,
|
||||
isActiveFilterValue,
|
||||
timestampFormatter,
|
||||
timeGrain,
|
||||
columnLabelToNameMap,
|
||||
],
|
||||
);
|
||||
|
||||
const toggleFilter = useCallback(
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
getNumberFormatter,
|
||||
getTimeFormatter,
|
||||
getTimeFormatterForGranularity,
|
||||
isAdhocColumn,
|
||||
normalizeCurrency,
|
||||
NumberFormats,
|
||||
QueryMode,
|
||||
@@ -532,6 +533,20 @@ const transformProps = (
|
||||
comparison_type,
|
||||
slice_id,
|
||||
} = formData;
|
||||
// Build a mapping from column labels to original column names.
|
||||
// When a user creates an adhoc column with a custom label (e.g. sqlExpression: "state",
|
||||
// label: "State_Renamed"), the query result uses the label as the column name.
|
||||
// Cross-filtering needs the original column name to work on the receiving chart.
|
||||
const columnLabelToNameMap: Record<string, string> = {};
|
||||
const formColumns = ensureIsArray(
|
||||
queryMode === QueryMode.Raw ? formData.all_columns : formData.groupby,
|
||||
);
|
||||
formColumns.forEach(col => {
|
||||
if (isAdhocColumn(col) && col.label && col.label !== col.sqlExpression) {
|
||||
columnLabelToNameMap[col.label] = col.sqlExpression;
|
||||
}
|
||||
});
|
||||
|
||||
const isUsingTimeComparison =
|
||||
!isEmpty(time_compare) &&
|
||||
queryMode === QueryMode.Aggregate &&
|
||||
@@ -791,6 +806,7 @@ const transformProps = (
|
||||
hasServerPageLengthChanged,
|
||||
serverPageLength,
|
||||
slice_id,
|
||||
columnLabelToNameMap,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -124,6 +124,10 @@ export interface TableChartTransformedProps<D extends DataRecord = DataRecord> {
|
||||
hasServerPageLengthChanged: boolean;
|
||||
serverPageLength: number;
|
||||
slice_id: number;
|
||||
// Maps column labels (used as keys in query results) back to original
|
||||
// column names for cross-filtering, so that adhoc columns with custom labels
|
||||
// emit the correct column name in cross-filter data masks
|
||||
columnLabelToNameMap?: Record<string, string>;
|
||||
}
|
||||
|
||||
export default {};
|
||||
|
||||
Reference in New Issue
Block a user