From d86e5718d56e58b0de7eba38c6ba89ea8bf02d7a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 16 Sep 2021 07:35:19 +0100 Subject: [PATCH] Prevent DND if target is a child of source --- .../design/AppPreview/CurrentItemPreview.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index 422eba73b0..a8f1b507f4 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -8,7 +8,7 @@ import ConfirmDialog from "components/common/ConfirmDialog.svelte" import { ProgressCircle, Layout, Heading, Body } from "@budibase/bbui" import ErrorSVG from "assets/error.svg?raw" - import { findComponent } from "builderStore/storeUtils" + import { findComponent, findComponentPath } from "builderStore/storeUtils" let iframe let layout @@ -123,6 +123,17 @@ get(currentAsset).props, data.destinationComponentId ) + + // Stop if the target is a child of source + const path = findComponentPath( + sourceComponent, + data.destinationComponentId + ) + const ids = path.map(component => component._id) + if (ids.includes(data.destinationComponentId)) { + return + } + if (sourceComponent && destinationComponent) { store.actions.components.copy(sourceComponent, true) store.actions.components.paste(destinationComponent, data.mode)