From 3b7f59323e3167386db57ce92ab74e5683f0c73a Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 21 Mar 2022 15:17:51 +0000 Subject: [PATCH] Ensure the component tree containing the selected component cannot be hidden --- packages/builder/src/builderStore/index.js | 12 +++++++++++- .../ComponentTree.svelte | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 82556c74cf..504f33861b 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -3,7 +3,7 @@ import { getAutomationStore } from "./store/automation" import { getThemeStore } from "./store/theme" import { derived, writable } from "svelte/store" import { FrontendTypes, LAYOUT_NAMES } from "../constants" -import { findComponent } from "./componentUtils" +import { findComponent, findComponentPath } from "./componentUtils" export const store = getFrontendStore() export const automationStore = getAutomationStore() @@ -29,6 +29,16 @@ export const selectedComponent = derived( } ) +export const selectedComponentPath = derived( + [store, currentAsset], + ([$store, $currentAsset]) => { + return findComponentPath( + $currentAsset.props, + $store.selectedComponentId + ).map(component => component._id) + } +) + export const currentAssetId = derived(store, $store => { return $store.currentFrontEndType === FrontendTypes.SCREEN ? $store.selectedScreenId diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte index ddcc08479b..6b78bc40c1 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/ComponentTree.svelte @@ -5,6 +5,7 @@ import NavItem from "components/common/NavItem.svelte" import { capitalise } from "helpers" import { notifications } from "@budibase/bbui" + import { selectedComponentPath } from "builderStore" export let components = [] export let currentComponent @@ -71,10 +72,20 @@ notifications.error("Error saving component") } } + + const isOpen = (component, selectedComponentPath, closedNodes) => { + if (!component?._children?.length) { + return false + } + if (selectedComponentPath.includes(component._id)) { + return true + } + return !closedNodes[component._id] + }