diff --git a/superset-frontend/src/components/Chart/Chart.tsx b/superset-frontend/src/components/Chart/Chart.tsx index a65ee1912f9..a9797f4f56a 100644 --- a/superset-frontend/src/components/Chart/Chart.tsx +++ b/superset-frontend/src/components/Chart/Chart.tsx @@ -26,6 +26,7 @@ import { SqlaFormData, ClientErrorObject, DataRecordFilters, + type FilterState, type JsonObject, type AgGridChartState, } from '@superset-ui/core'; @@ -89,6 +90,7 @@ export interface ChartProps { onChartStateChange?: (chartState: AgGridChartState) => void; /** Whether to suppress the loading spinner (during auto-refresh) */ suppressLoadingSpinner?: boolean; + filterState?: FilterState; } export type Actions = { diff --git a/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.test.tsx b/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.test.tsx index 7ef19dce5fb..0012830ed09 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.test.tsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.test.tsx @@ -29,6 +29,15 @@ import chartQueries, { } from 'spec/fixtures/mockChartQueries'; import Chart from './Chart'; +let capturedChartContainerProps: Record = {}; +jest.mock('src/components/Chart/ChartContainer', () => { + const MockChartContainer = (props: Record) => { + capturedChartContainerProps = props; + return
; + }; + return { __esModule: true, default: MockChartContainer }; +}); + const props = { id: queryId, width: 100, @@ -452,3 +461,24 @@ test('should merge base ownState with converted chart state', () => { expect(getByTestId('chart-container')).toBeInTheDocument(); }); + +test('should pass filterState from dataMask to ChartContainer', () => { + const mockFilterState = { value: ['bar'], selectedValues: ['bar'] }; + + setup( + {}, + { + ...defaultState, + dataMask: { + [queryId]: { + filterState: mockFilterState, + }, + }, + }, + ); + + expect(capturedChartContainerProps).toHaveProperty( + 'filterState', + mockFilterState, + ); +}); diff --git a/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx b/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx index 0dda657a02d..cbf930183be 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx @@ -761,6 +761,7 @@ const Chart = (props: ChartProps) => { emitCrossFilters={emitCrossFilters} onChartStateChange={handleChartStateChange} suppressLoadingSpinner={suppressLoadingSpinner} + filterState={dataMask[props.id]?.filterState} />