Fully remove source component from client tree while dragging
This commit is contained in:
parent
c5b36863d2
commit
90172ec2a1
|
@ -210,8 +210,10 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out source component from consideration
|
// Filter out source component and placeholder from consideration
|
||||||
const children = parent._children?.filter(x => x._id !== sourceId)
|
const children = parent._children?.filter(
|
||||||
|
x => x._id !== "placeholder" && x._id !== sourceId
|
||||||
|
)
|
||||||
|
|
||||||
// Use inside if no existing children
|
// Use inside if no existing children
|
||||||
if (!children?.length) {
|
if (!children?.length) {
|
||||||
|
|
|
@ -3,10 +3,7 @@ import { routeStore } from "./routes"
|
||||||
import { builderStore } from "./builder"
|
import { builderStore } from "./builder"
|
||||||
import { appStore } from "./app"
|
import { appStore } from "./app"
|
||||||
import { RoleUtils } from "@budibase/frontend-core"
|
import { RoleUtils } from "@budibase/frontend-core"
|
||||||
import {
|
import { findComponentById, findComponentParent } from "../utils/components.js"
|
||||||
findComponentById,
|
|
||||||
findComponentPathById,
|
|
||||||
} from "../utils/components.js"
|
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
|
|
||||||
const createScreenStore = () => {
|
const createScreenStore = () => {
|
||||||
|
@ -51,11 +48,16 @@ const createScreenStore = () => {
|
||||||
const { dndParent, dndIndex, selectedComponentId } = $builderStore
|
const { dndParent, dndIndex, selectedComponentId } = $builderStore
|
||||||
const insert = true
|
const insert = true
|
||||||
if (insert && activeScreen && dndParent && dndIndex != null) {
|
if (insert && activeScreen && dndParent && dndIndex != null) {
|
||||||
let selectedComponent = findComponentById(
|
// Remove selected component from tree
|
||||||
|
let selectedParent = findComponentParent(
|
||||||
activeScreen.props,
|
activeScreen.props,
|
||||||
selectedComponentId
|
selectedComponentId
|
||||||
)
|
)
|
||||||
delete selectedComponent._component
|
selectedParent._children = selectedParent._children?.filter(
|
||||||
|
x => x._id !== selectedComponentId
|
||||||
|
)
|
||||||
|
|
||||||
|
// Insert placeholder
|
||||||
const placeholder = {
|
const placeholder = {
|
||||||
_component: "placeholder",
|
_component: "placeholder",
|
||||||
_id: "placeholder",
|
_id: "placeholder",
|
||||||
|
|
|
@ -60,3 +60,25 @@ export const findChildrenByType = (component, type, children = []) => {
|
||||||
findChildrenByType(child, type, children)
|
findChildrenByType(child, type, children)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively searches for the parent component of a specific component ID
|
||||||
|
*/
|
||||||
|
export const findComponentParent = (rootComponent, id, parentComponent) => {
|
||||||
|
if (!rootComponent || !id) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (rootComponent._id === id) {
|
||||||
|
return parentComponent
|
||||||
|
}
|
||||||
|
if (!rootComponent._children) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
for (const child of rootComponent._children) {
|
||||||
|
const childResult = findComponentParent(child, id, rootComponent)
|
||||||
|
if (childResult) {
|
||||||
|
return childResult
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue