fix(ag-grid-table): fix AND filter conditions not applied (#38369)

(cherry picked from commit ca2d26a1e2)
This commit is contained in:
amaannawab923
2026-03-13 19:42:14 +05:30
committed by Michael S. Molina
parent 825b284492
commit 4baedcc794
5 changed files with 369 additions and 7 deletions

View File

@@ -34,6 +34,8 @@ import {
SMART_DATE_ID,
TimeFormats,
TimeFormatter,
AgGridChartState,
AgGridFilterModel,
} from '@superset-ui/core';
import { GenericDataType } from '@apache-superset/core/common';
import { isEmpty, isEqual, merge } from 'lodash';
@@ -456,6 +458,9 @@ const getPageSize = (
return numRecords * numColumns > 5000 ? 200 : 0;
};
// Tracks slice_ids that have already applied their saved chartState filter on mount
const savedFilterAppliedSet = new Set<number>();
const transformProps = (
chartProps: TableChartProps,
): AgGridTableChartTransformedProps => {
@@ -710,6 +715,36 @@ const transformProps = (
: totalQuery?.data[0]
: undefined;
// Map saved metric/calculated column labels to their SQL expressions for filter resolution
const metricSqlExpressions: Record<string, string> = {};
chartProps.datasource.metrics.forEach(metric => {
if (metric.metric_name && metric.expression) {
metricSqlExpressions[metric.metric_name] = metric.expression;
}
});
chartProps.datasource.columns.forEach(col => {
if (col.column_name && col.expression) {
metricSqlExpressions[col.column_name] = col.expression;
if (col.verbose_name && col.verbose_name !== col.column_name) {
metricSqlExpressions[col.verbose_name] = col.expression;
}
}
});
// Strip saved filter from chartState after initial application to prevent re-injection
let chartState = serverPaginationData?.chartState as
| AgGridChartState
| undefined;
const chartStateHasFilter = !!(
chartState?.filterModel && Object.keys(chartState.filterModel).length > 0
);
if (chartStateHasFilter && savedFilterAppliedSet.has(slice_id)) {
chartState = { ...chartState!, filterModel: {} as AgGridFilterModel };
} else if (chartStateHasFilter) {
savedFilterAppliedSet.add(slice_id);
}
return {
height,
width,
@@ -742,7 +777,8 @@ const transformProps = (
basicColorColumnFormatters,
basicColorFormatters,
formData,
chartState: serverPaginationData?.chartState,
metricSqlExpressions,
chartState,
onChartStateChange,
};
};