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

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

* Make canDropValue optional

* Add onDropValue
This commit is contained in:
Kamil Gabryjelski 2021-08-10 17:04:42 +02:00 committed by GitHub
parent a70248736f
commit 6e1d16d956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -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(),

View File

@ -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 {
@ -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;