Skip to content

Commit

Permalink
fix(explore): make clicked dnd filters unique
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Sep 14, 2021
1 parent 5ac8ac0 commit 76e4a7c
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 isDndItemValue(item: any): item is DndItemValue {
return item?.value && item?.type;
}
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,
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,
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 (isDndItemValue(droppedItem) && droppedItem?.metric_name) {
return new AdhocFilter({
expressionType: EXPRESSION_TYPES.SQL,
clause: CLAUSES.HAVING,
Expand Down

0 comments on commit 76e4a7c

Please sign in to comment.