1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

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) { if (!component?._children?.length) {
return false return false
} }
return openNodes[`nodeOpen-${component._id}`] return componentTreeNodesStore.isNodeExpanded(component._id)
} }
const isChildOfSelectedComponent = component => { const isChildOfSelectedComponent = component => {

View file

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

View file

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