1
0
Fork 0
mirror of synced 2024-07-06 23:10:57 +12:00

Add type and role to automatically created nav links and ensure cleanup from both links and sublinks when deleting screens

This commit is contained in:
Andrew Kingston 2024-04-10 14:19:05 +01:00
parent 68eeb12686
commit 380a0e7d30
2 changed files with 16 additions and 4 deletions

View file

@ -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
)
}

View file

@ -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,