Skip to content

Commit

Permalink
feat(explore): each control can define its own canDrop for dnd (apach…
Browse files Browse the repository at this point in the history
…e#16090)

* feat(explore): each control can define its own canDrop for dnd

* Make canDropValue optional

* Add onDropValue
  • Loading branch information
kgabryje authored Aug 10, 2021
1 parent 1c81572 commit 81753e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export default function DndSelectLabel<T, O>({

drop: (item: DatasourcePanelDndItem) => {
props.onDrop(item);
props.onDropValue?.(item.value);
},

canDrop: (item: DatasourcePanelDndItem) => props.canDrop(item),
canDrop: (item: DatasourcePanelDndItem) =>
props.canDrop(item) && (props.canDropValue?.(item.value) ?? true),

collect: monitor => ({
isOver: monitor.isOver(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import { ReactNode } from 'react';
import { Metric } from '@superset-ui/core';
import { ColumnMeta } from '@superset-ui/chart-controls';
import { DatasourcePanelDndItem } from '../../DatasourcePanel/types';
import {
DatasourcePanelDndItem,
DndItemValue,
} from '../../DatasourcePanel/types';
import { DndItemType } from '../../DndItemType';

export interface OptionProps {
Expand Down Expand Up @@ -53,6 +56,8 @@ export interface DndColumnSelectProps<
> extends LabelProps<T> {
onDrop: (item: DatasourcePanelDndItem) => void;
canDrop: (item: DatasourcePanelDndItem) => boolean;
canDropValue?: (value: DndItemValue) => boolean;
onDropValue?: (value: DndItemValue) => void;
valuesRenderer: () => ReactNode;
accept: DndItemType | DndItemType[];
ghostButtonText?: string;
Expand Down

0 comments on commit 81753e5

Please sign in to comment.