Merge pull request #8011 from Budibase/fix/enforce-builder-child-checks-drag-drop
Fix to enforce illegalchildren rules when dragging and dropping in th…
This commit is contained in:
commit
bfce63b885
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
let closedNodes = {}
|
let closedNodes = {}
|
||||||
|
|
||||||
|
$: currentScreen = get(selectedScreen)
|
||||||
|
|
||||||
$: filteredComponents = components?.filter(component => {
|
$: filteredComponents = components?.filter(component => {
|
||||||
return (
|
return (
|
||||||
!$store.componentToPaste?.isCut ||
|
!$store.componentToPaste?.isCut ||
|
||||||
|
@ -68,9 +70,27 @@
|
||||||
closedNodes = closedNodes
|
closedNodes = closedNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDrop = async e => {
|
const onDrop = async (e, component) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
try {
|
try {
|
||||||
|
const compDef = store.actions.components.getDefinition(
|
||||||
|
$dndStore.source?._component
|
||||||
|
)
|
||||||
|
const compTypeName = compDef.name.toLowerCase()
|
||||||
|
const path = findComponentPath(currentScreen.props, component._id)
|
||||||
|
|
||||||
|
for (let pathComp of path) {
|
||||||
|
const pathCompDef = store.actions.components.getDefinition(
|
||||||
|
pathComp?._component
|
||||||
|
)
|
||||||
|
if (pathCompDef?.illegalChildren?.indexOf(compTypeName) > -1) {
|
||||||
|
notifications.warning(
|
||||||
|
`${compDef.name} cannot be a child of ${pathCompDef.name} (${pathComp._instanceName})`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await dndStore.actions.drop()
|
await dndStore.actions.drop()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
@ -114,7 +134,9 @@
|
||||||
on:dragstart={() => dndStore.actions.dragstart(component)}
|
on:dragstart={() => dndStore.actions.dragstart(component)}
|
||||||
on:dragover={dragover(component, index)}
|
on:dragover={dragover(component, index)}
|
||||||
on:iconClick={() => toggleNodeOpen(component._id)}
|
on:iconClick={() => toggleNodeOpen(component._id)}
|
||||||
on:drop={onDrop}
|
on:drop={e => {
|
||||||
|
onDrop(e, component)
|
||||||
|
}}
|
||||||
text={getComponentText(component)}
|
text={getComponentText(component)}
|
||||||
icon={getComponentIcon(component)}
|
icon={getComponentIcon(component)}
|
||||||
withArrow={componentHasChildren(component)}
|
withArrow={componentHasChildren(component)}
|
||||||
|
|
Loading…
Reference in New Issue