Skip to content

Commit

Permalink
fix(explore): make clicked dnd filters unique (apache#16700)
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro authored Sep 14, 2021
1 parent bb3a11f commit 632e641
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export function isDatasourcePanelDndItem(
): item is DatasourcePanelDndItem {
return item?.value && item?.type;
}

export function isSavedMetric(item: any): item is Metric {
return item?.metric_name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetr
import {
DatasourcePanelDndItem,
DndItemValue,
isSavedMetric,
} 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,
Expand Down Expand Up @@ -78,7 +80,9 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => {
);
const [partitionColumn, setPartitionColumn] = useState(undefined);
const [newFilterPopoverVisible, setNewFilterPopoverVisible] = useState(false);
const [droppedItem, setDroppedItem] = useState<DndItemValue | null>(null);
const [droppedItem, setDroppedItem] = useState<
DndItemValue | typeof EMPTY_OBJECT
>({});

const optionsForSelect = (
columns: ColumnMeta[],
Expand Down Expand Up @@ -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 (isSavedMetric(droppedItem)) {
return new AdhocFilter({
expressionType: EXPRESSION_TYPES.SQL,
clause: CLAUSES.HAVING,
Expand Down

0 comments on commit 632e641

Please sign in to comment.