Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Add default emitFilter for BoxPlot. Check emit filter before handle c…
Browse files Browse the repository at this point in the history
…rossFilter
  • Loading branch information
maloun96 committed Mar 19, 2021
1 parent 3839f9a commit f1630df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions plugins/plugin-chart-echarts/src/BoxPlot/EchartsBoxPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export default function EchartsBoxPlot({
labelMap,
groupby,
selectedValues,
formData,
}: BoxPlotChartTransformedProps) {
const handleChange = useCallback(
(values: string[]) => {
if (!formData.emitFilter) {
return;
}

const groupbyValues = values.map(value => labelMap[value]);

setDataMask({
Expand All @@ -57,12 +62,12 @@ export default function EchartsBoxPlot({
},
},
currentState: {
value: groupbyValues ?? null,
value: groupbyValues.length ? groupbyValues : null,
},
},
ownFilters: {
currentState: {
selectedValues: values,
selectedValues: values.length ? values : null,
},
},
});
Expand Down
5 changes: 4 additions & 1 deletion plugins/plugin-chart-echarts/src/BoxPlot/controlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {
formatSelectOptions,
sections,
} from '@superset-ui/chart-controls';
import { DEFAULT_FORM_DATA } from '../Pie/types';

const { emitFilter } = DEFAULT_FORM_DATA;

export default {
controlPanelSections: [
Expand Down Expand Up @@ -69,7 +72,7 @@ export default {
config: {
type: 'CheckboxControl',
label: t('Enable emitting filters'),
default: false,
default: emitFilter,
renderTrigger: true,
description: t('Enable emmiting filters.'),
},
Expand Down
6 changes: 6 additions & 0 deletions plugins/plugin-chart-echarts/src/BoxPlot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type BoxPlotQueryFormData = QueryFormData & {
numberFormat?: string;
whiskerOptions?: BoxPlotFormDataWhiskerOptions;
xTickLayout?: BoxPlotFormXTickLayout;
emitFilter: boolean;
};

export type BoxPlotFormDataWhiskerOptions =
Expand All @@ -40,6 +41,11 @@ export type BoxPlotFormDataWhiskerOptions =

export type BoxPlotFormXTickLayout = '45°' | '90°' | 'auto' | 'flat' | 'staggered';

// @ts-ignore
export const DEFAULT_FORM_DATA: BoxPlotQueryFormData = {
emitFilter: false,
};

export interface EchartsBoxPlotChartProps extends ChartProps {
formData: BoxPlotQueryFormData;
queriesData: ChartDataResponseResult[];
Expand Down
9 changes: 7 additions & 2 deletions plugins/plugin-chart-echarts/src/Pie/EchartsPie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export default function EchartsPie({
labelMap,
groupby,
selectedValues,
formData,
}: PieChartTransformedProps) {
const handleChange = useCallback(
(values: string[]) => {
if (!formData.emitFilter) {
return;
}

const groupbyValues = values.map(value => labelMap[value]);

setDataMask({
Expand All @@ -57,12 +62,12 @@ export default function EchartsPie({
},
},
currentState: {
value: groupbyValues ?? null,
value: groupbyValues.length ? groupbyValues : null,
},
},
ownFilters: {
currentState: {
selectedValues: values,
selectedValues: values.length ? values : null,
},
},
});
Expand Down

0 comments on commit f1630df

Please sign in to comment.