You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by kg...@apache.org on 2021/08/10 15:06:39 UTC

[superset] branch master updated: feat(explore): each control can define its own canDrop for dnd (#16090)

This is an automated email from the ASF dual-hosted git repository.

kgabryje pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e1d16d  feat(explore): each control can define its own canDrop for dnd (#16090)
6e1d16d is described below

commit 6e1d16d9568d2545c95744b8ed035a6e7eb11b28
Author: Kamil Gabryjelski <ka...@gmail.com>
AuthorDate: Tue Aug 10 17:04:42 2021 +0200

    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
---
 .../components/controls/DndColumnSelectControl/DndSelectLabel.tsx  | 4 +++-
 .../explore/components/controls/DndColumnSelectControl/types.ts    | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx
index 7ffdb17..d5d365f 100644
--- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx
+++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx
@@ -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(),
diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts
index f11bb1d..8826762 100644
--- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts
+++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts
@@ -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;