From 380a0e7d309de8e1df055959f1af31d4e9a57aff Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 10 Apr 2024 14:19:05 +0100 Subject: [PATCH] Add type and role to automatically created nav links and ensure cleanup from both links and sublinks when deleting screens --- .../NewScreen/CreateScreenModal.svelte | 3 ++- .../builder/src/stores/builder/navigation.js | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte index b49e38d9cd..68d74218c8 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte @@ -79,7 +79,8 @@ // for autoscreens, so it's always safe to do this. await navigationStore.saveLink( screen.routing.route, - capitalise(screen.routing.route.split("/")[1]) + capitalise(screen.routing.route.split("/")[1]), + screenAccessRole ) } diff --git a/packages/builder/src/stores/builder/navigation.js b/packages/builder/src/stores/builder/navigation.js index 0cc4923c56..86e484b0a6 100644 --- a/packages/builder/src/stores/builder/navigation.js +++ b/packages/builder/src/stores/builder/navigation.js @@ -42,7 +42,7 @@ export class NavigationStore extends BudiStore { this.syncAppNavigation(app.navigation) } - async saveLink(url, title) { + async saveLink(url, title, roleId) { const navigation = get(this.store) let links = [...(navigation?.links ?? [])] @@ -54,6 +54,8 @@ export class NavigationStore extends BudiStore { links.push({ text: title, url, + type: "link", + roleId, }) await this.save({ ...navigation, @@ -67,11 +69,20 @@ export class NavigationStore extends BudiStore { if (!links?.length) { return } - - // Filter out the URLs to delete urls = Array.isArray(urls) ? urls : [urls] + + // Filter out top level links pointing to these URLs links = links.filter(link => !urls.includes(link.url)) + // Filter out nested links pointing to these URLs + links.forEach(link => { + if (link.type === "sublinks" && link.subLinks?.length) { + link.subLinks = link.subLinks.filter( + subLink => !urls.includes(subLink.url) + ) + } + }) + await this.save({ ...navigation, links,