Prevent DND if target is a child of source

This commit is contained in:
Andrew Kingston 2021-09-16 07:35:19 +01:00
parent 0ce0f5c823
commit d86e5718d5
1 changed files with 12 additions and 1 deletions

View File

@ -8,7 +8,7 @@
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { ProgressCircle, Layout, Heading, Body } from "@budibase/bbui" import { ProgressCircle, Layout, Heading, Body } from "@budibase/bbui"
import ErrorSVG from "assets/error.svg?raw" import ErrorSVG from "assets/error.svg?raw"
import { findComponent } from "builderStore/storeUtils" import { findComponent, findComponentPath } from "builderStore/storeUtils"
let iframe let iframe
let layout let layout
@ -123,6 +123,17 @@
get(currentAsset).props, get(currentAsset).props,
data.destinationComponentId 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) { if (sourceComponent && destinationComponent) {
store.actions.components.copy(sourceComponent, true) store.actions.components.copy(sourceComponent, true)
store.actions.components.paste(destinationComponent, data.mode) store.actions.components.paste(destinationComponent, data.mode)