From 9f4899306cca279da0bc571a4721272cf4dfe6ae Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 1 Apr 2022 18:02:34 +0100 Subject: [PATCH] Fix issue where changing the role of a screen did not correctly update screen list --- .../ComponentNavigationTree/index.svelte | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte index 1c108f164e..ed064f8307 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ComponentNavigationTree/index.svelte @@ -3,13 +3,14 @@ import PathTree from "./PathTree.svelte" let routes = {} - $: paths = Object.keys(routes || {}).sort() + let paths = [] - $: { - const allRoutes = $store.routes + $: allRoutes = $store.routes + $: selectedScreenId = $store.selectedScreenId + $: updatePaths(allRoutes, $selectedAccessRole, selectedScreenId) + + const updatePaths = (allRoutes, selectedRoleId, selectedScreenId) => { const sortedPaths = Object.keys(allRoutes || {}).sort() - const selectedRoleId = $selectedAccessRole - const selectedScreenId = $store.selectedScreenId let found = false let firstValidScreenId @@ -41,11 +42,15 @@ }) }) }) - routes = filteredRoutes + routes = { ...filteredRoutes } + paths = Object.keys(routes || {}).sort() // Select the correct role for the current screen ID if (!found && screenRoleId) { selectedAccessRole.set(screenRoleId) + if (screenRoleId !== selectedRoleId) { + updatePaths(allRoutes, screenRoleId, selectedScreenId) + } } // If the selected screen isn't in this filtered list, select the first one