Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disable cross filtering on charts with no dimensions #30176

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import { ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import thumbnail from './images/thumbnail.png';
import transformProps from './transformProps';
import buildQuery from './buildQuery';
Expand All @@ -25,6 +25,7 @@ import example1 from './images/example1.png';
import example2 from './images/example2.png';
import { EchartsBubbleChartProps, EchartsBubbleFormData } from './types';

// TODO: Implement cross filtering
export default class EchartsBubbleChartPlugin extends ChartPlugin<
EchartsBubbleFormData,
EchartsBubbleChartProps
Expand All @@ -35,7 +36,6 @@ export default class EchartsBubbleChartPlugin extends ChartPlugin<
controlPanel,
loadChart: () => import('./EchartsBubble'),
metadata: new ChartMetadata({
behaviors: [Behavior.InteractiveChart],
category: t('Correlation'),
credits: ['https://echarts.apache.org'],
description: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import { ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import buildQuery from './buildQuery';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
Expand All @@ -26,6 +26,7 @@ import example1 from './images/example1.png';
import example2 from './images/example2.png';
import { HistogramChartProps, HistogramFormData } from './types';

// TODO: Implement cross filtering
export default class EchartsHistogramChartPlugin extends ChartPlugin<
HistogramFormData,
HistogramChartProps
Expand All @@ -46,7 +47,6 @@ export default class EchartsHistogramChartPlugin extends ChartPlugin<
controlPanel,
loadChart: () => import('./Histogram'),
metadata: new ChartMetadata({
behaviors: [Behavior.InteractiveChart],
credits: ['https://echarts.apache.org'],
category: t('Distribution'),
description: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,25 @@ export default function EchartsMixedTimeseries({

const handleChange = useCallback(
(seriesName: string, seriesIndex: number) => {
if (!emitCrossFilters) {
const isFirst = isFirstQuery(seriesIndex);
if (
!emitCrossFilters ||
(isFirst && groupby.length === 0) ||
(!isFirst && groupbyB.length === 0)
) {
return;
}

setDataMask(getCrossFilterDataMask(seriesName, seriesIndex).dataMask);
},
[emitCrossFilters, setDataMask, getCrossFilterDataMask],
[
isFirstQuery,
emitCrossFilters,
groupby.length,
groupbyB.length,
setDataMask,
getCrossFilterDataMask,
],
);

const eventHandlers: EventHandlers = {
Expand All @@ -140,7 +152,7 @@ export default function EchartsMixedTimeseries({
const isFirst = isFirstQuery(seriesIndex);
const values = [
...(eventParams.name ? [eventParams.name] : []),
...(isFirst ? labelMap : labelMapB)[eventParams.seriesName],
...((isFirst ? labelMap : labelMapB)[eventParams.seriesName] || []),
];
if (data && xAxis.type === AxisType.Time) {
drillToDetailFilters.push({
Expand Down Expand Up @@ -179,9 +191,14 @@ export default function EchartsMixedTimeseries({
}),
}),
);
const hasCrossFilter =
(isFirst && groupby.length > 0) || (!isFirst && groupbyB.length > 0);

onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
drillToDetail: drillToDetailFilters,
crossFilter: getCrossFilterDataMask(seriesName, seriesIndex),
crossFilter: hasCrossFilter
? getCrossFilterDataMask(seriesName, seriesIndex)
: undefined,
drillBy: {
filters: drillByFilters,
groupbyFieldName: isFirst ? 'groupby' : 'groupby_b',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import { ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import buildQuery from './buildQuery';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
Expand All @@ -26,6 +26,7 @@ import example1 from './images/example1.png';
import example2 from './images/example2.png';
import { SankeyChartProps, SankeyFormData } from './types';

// TODO: Implement cross filtering
export default class EchartsSankeyChartPlugin extends ChartPlugin<
SankeyFormData,
SankeyChartProps
Expand All @@ -46,7 +47,6 @@ export default class EchartsSankeyChartPlugin extends ChartPlugin<
controlPanel,
loadChart: () => import('./Sankey'),
metadata: new ChartMetadata({
behaviors: [Behavior.InteractiveChart],
credits: ['https://echarts.apache.org'],
category: t('Flow'),
description: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function EchartsSunburst(props: SunburstTransformedProps) {

const handleChange = useCallback(
(treePathInfo: TreePathInfo[]) => {
if (!emitCrossFilters) {
if (!emitCrossFilters || !columns?.length) {
return;
}

Expand Down Expand Up @@ -142,7 +142,9 @@ export default function EchartsSunburst(props: SunburstTransformedProps) {
}
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
drillToDetail: drillToDetailFilters,
crossFilter: getCrossFilterDataMask(treePathInfo),
crossFilter: columns?.length
? getCrossFilterDataMask(treePathInfo)
: undefined,
drillBy: { filters: drillByFilters, groupbyFieldName: 'columns' },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default function EchartsTimeseries({
setExtraControlHeight(updatedHeight);
}, [formData.showExtraControls]);

const hasDimensions = ensureIsArray(groupby).length > 0;

const getModelInfo = (target: ViewRootGroup, globalModel: GlobalModel) => {
let el = target;
let model: ComponentModel | null = null;
Expand Down Expand Up @@ -139,6 +141,9 @@ export default function EchartsTimeseries({

const eventHandlers: EventHandlers = {
click: props => {
if (!hasDimensions) {
return;
}
if (clickTimer.current) {
clearTimeout(clickTimer.current);
}
Expand Down Expand Up @@ -215,8 +220,10 @@ export default function EchartsTimeseries({

onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
drillToDetail: drillToDetailFilters,
crossFilter: getCrossFilterDataMask(seriesName),
drillBy: { filters: drillByFilters, groupbyFieldName: 'groupby' },
crossFilter: hasDimensions
? getCrossFilterDataMask(seriesName)
: undefined,
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function EchartsTreemap({

const handleChange = useCallback(
(data, treePathInfo) => {
if (!emitCrossFilters) {
if (!emitCrossFilters || groupby.length === 0) {
return;
}

Expand Down Expand Up @@ -144,7 +144,10 @@ export default function EchartsTreemap({
});
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
drillToDetail: drillToDetailFilters,
crossFilter: getCrossFilterDataMask(data, treePathInfo),
crossFilter:
groupby.length > 0
? getCrossFilterDataMask(data, treePathInfo)
: undefined,
drillBy: { filters: drillByFilters, groupbyFieldName: 'groupby' },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import { ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import buildQuery from './buildQuery';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
Expand All @@ -27,6 +27,7 @@ import example2 from './images/example2.png';
import example3 from './images/example3.png';
import { EchartsWaterfallChartProps, EchartsWaterfallFormData } from './types';

// TODO: Implement cross filtering
export default class EchartsWaterfallChartPlugin extends ChartPlugin<
EchartsWaterfallFormData,
EchartsWaterfallChartProps
Expand All @@ -47,7 +48,6 @@ export default class EchartsWaterfallChartPlugin extends ChartPlugin<
controlPanel,
loadChart: () => import('./EchartsWaterfall'),
metadata: new ChartMetadata({
behaviors: [Behavior.InteractiveChart],
credits: ['https://echarts.apache.org'],
category: t('Evolution'),
description: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getNumberFormatter,
getTimeFormatter,
} from '@superset-ui/core';
import { noop } from 'lodash';

import {
BaseTransformedProps,
Expand Down Expand Up @@ -137,7 +138,8 @@ export const contextMenuEventHandler =
}
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
drillToDetail: drillFilters,
crossFilter: getCrossFilterDataMask(e.name),
crossFilter:
groupby.length > 0 ? getCrossFilterDataMask(e.name) : undefined,
drillBy: { filters: drillFilters, groupbyFieldName: 'groupby' },
});
}
Expand All @@ -157,11 +159,14 @@ export const allEventHandlers = (
formData,
} = transformedProps;
const eventHandlers: EventHandlers = {
click: clickEventHandler(
getCrossFilterDataMask(selectedValues, groupby, labelMap),
setDataMask,
emitCrossFilters,
),
click:
groupby.length > 0
? clickEventHandler(
getCrossFilterDataMask(selectedValues, groupby, labelMap),
setDataMask,
emitCrossFilters,
)
: noop,
contextmenu: contextMenuEventHandler(
groupby,
onContextMenu,
Expand Down
Loading