From 76e4a7cba09c92072f842c5f4bf806263221acd1 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Tue, 14 Sep 2021 14:58:59 +0300 Subject: [PATCH] fix(explore): make clicked dnd filters unique --- .../src/explore/components/DatasourcePanel/types.ts | 4 ++++ .../DndColumnSelectControl/DndFilterSelect.tsx | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/explore/components/DatasourcePanel/types.ts b/superset-frontend/src/explore/components/DatasourcePanel/types.ts index 22904776fa6f3..e2c6dc4000985 100644 --- a/superset-frontend/src/explore/components/DatasourcePanel/types.ts +++ b/superset-frontend/src/explore/components/DatasourcePanel/types.ts @@ -31,3 +31,7 @@ export function isDatasourcePanelDndItem( ): item is DatasourcePanelDndItem { return item?.value && item?.type; } + +export function isDndItemValue(item: any): item is DndItemValue { + return item?.value && item?.type; +} diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx index f9a142b665d6b..7e2a49c9d6c5a 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx @@ -45,10 +45,12 @@ import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetr import { DatasourcePanelDndItem, DndItemValue, + isDndItemValue, } from 'src/explore/components/DatasourcePanel/types'; import { DndItemType } from 'src/explore/components/DndItemType'; import { ControlComponentProps } from 'src/explore/components/Control'; +const EMPTY_OBJECT = {}; const DND_ACCEPTED_TYPES = [ DndItemType.Column, DndItemType.Metric, @@ -78,7 +80,9 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => { ); const [partitionColumn, setPartitionColumn] = useState(undefined); const [newFilterPopoverVisible, setNewFilterPopoverVisible] = useState(false); - const [droppedItem, setDroppedItem] = useState(null); + const [droppedItem, setDroppedItem] = useState< + DndItemValue | typeof EMPTY_OBJECT + >({}); const optionsForSelect = ( columns: ColumnMeta[], @@ -342,12 +346,12 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => { ); const handleClickGhostButton = useCallback(() => { - setDroppedItem(null); + setDroppedItem({}); togglePopover(true); }, [togglePopover]); const adhocFilter = useMemo(() => { - if (droppedItem?.metric_name) { + if (isDndItemValue(droppedItem) && droppedItem?.metric_name) { return new AdhocFilter({ expressionType: EXPRESSION_TYPES.SQL, clause: CLAUSES.HAVING,