mirror of
https://github.com/apache/superset.git
synced 2026-05-09 09:55:19 +00:00
fix(ag-grid-table): fix AND filter conditions not applied (#38369)
(cherry picked from commit ca2d26a1e2)
This commit is contained in:
committed by
Michael S. Molina
parent
825b284492
commit
4baedcc794
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user