remove node collapsing magic string

This commit is contained in:
Gerard Burns 2024-03-14 13:24:34 +00:00
parent ece7060b6b
commit 89371c5f5f
3 changed files with 14 additions and 11 deletions

View File

@ -63,11 +63,11 @@
}
}
const isOpen = (component, openNodes) => {
const isOpen = (component) => {
if (!component?._children?.length) {
return false
}
return openNodes[`nodeOpen-${component._id}`]
return componentTreeNodesStore.isNodeExpanded(component._id)
}
const isChildOfSelectedComponent = component => {

View File

@ -1,3 +1,4 @@
import { get } from 'svelte/store'
import { createSessionStorageStore } from "@budibase/frontend-core"
const baseStore = createSessionStorageStore("openNodes", {})
@ -36,12 +37,18 @@ const collapseNode = componentId => {
})
}
const isNodeExpanded = componentId => {
const openNodes = get(baseStore);
return !!openNodes[`nodeOpen-${componentId}`]
}
const store = {
subscribe: baseStore.subscribe,
toggleNode,
expandNode,
expandNodes,
collapseNode,
isNodeExpanded
}
export default store

View File

@ -675,7 +675,6 @@ export class ComponentStore extends BudiStore {
const screen = get(selectedScreen)
const parent = findComponentParent(screen.props, componentId)
const index = parent?._children.findIndex(x => x._id === componentId)
const componentTreeNodes = get(componentTreeNodesStore)
// Check for screen and navigation component edge cases
const screenComponentId = `${screen._id}-screen`
@ -696,12 +695,12 @@ export class ComponentStore extends BudiStore {
const previousSibling = parent._children[index - 1]
if (
previousSibling._children?.length &&
componentTreeNodes[`nodeOpen-${previousSibling._id}`]
componentTreeNodesStore.isNodeExpanded(previousSibling._id)
) {
let target = previousSibling
while (
target._children?.length &&
componentTreeNodes[`nodeOpen-${target._id}`]
componentTreeNodesStore.isNodeExpanded(target._id)
) {
target = target._children[target._children.length - 1]
}
@ -723,7 +722,6 @@ export class ComponentStore extends BudiStore {
const screen = get(selectedScreen)
const parent = findComponentParent(screen.props, componentId)
const index = parent?._children.findIndex(x => x._id === componentId)
const componentTreeNodes = get(componentTreeNodesStore)
// Check for screen and navigation component edge cases
const screenComponentId = `${screen._id}-screen`
@ -736,7 +734,7 @@ export class ComponentStore extends BudiStore {
if (
component._children?.length &&
(state.selectedComponentId === navComponentId ||
componentTreeNodes[`nodeOpen-${component._id}`])
componentTreeNodesStore.isNodeExpanded(component._id))
) {
return component._children[0]._id
} else if (!parent) {
@ -796,7 +794,6 @@ export class ComponentStore extends BudiStore {
await screenStore.patch(screen => {
const componentId = component?._id
const parent = findComponentParent(screen.props, componentId)
const componentTreeNodes = get(componentTreeNodesStore)
// Check we aren't right at the top of the tree
const index = parent?._children.findIndex(x => x._id === componentId)
@ -818,7 +815,7 @@ export class ComponentStore extends BudiStore {
const definition = this.getDefinition(previousSibling._component)
if (
definition.hasChildren &&
componentTreeNodes[`nodeOpen-${previousSibling._id}`]
componentTreeNodesStore.isNodeExpanded(previousSibling._id)
) {
previousSibling._children.push(originalComponent)
}
@ -845,7 +842,6 @@ export class ComponentStore extends BudiStore {
await screenStore.patch(screen => {
const componentId = component?._id
const parent = findComponentParent(screen.props, componentId)
const componentTreeNodes = get(componentTreeNodesStore)
// Sanity check parent is found
if (!parent?._children?.length) {
@ -874,7 +870,7 @@ export class ComponentStore extends BudiStore {
const definition = this.getDefinition(nextSibling._component)
if (
definition.hasChildren &&
componentTreeNodes[`nodeOpen-${nextSibling._id}`]
componentTreeNodesStore.isNodeExpanded(nextSibling._id)
) {
nextSibling._children.splice(0, 0, originalComponent)
}