1
0
Fork 0
mirror of synced 2024-10-05 12:34:50 +13: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. // for autoscreens, so it's always safe to do this.
await navigationStore.saveLink( await navigationStore.saveLink(
screen.routing.route, 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) this.syncAppNavigation(app.navigation)
} }
async saveLink(url, title) { async saveLink(url, title, roleId) {
const navigation = get(this.store) const navigation = get(this.store)
let links = [...(navigation?.links ?? [])] let links = [...(navigation?.links ?? [])]
@ -54,6 +54,8 @@ export class NavigationStore extends BudiStore {
links.push({ links.push({
text: title, text: title,
url, url,
type: "link",
roleId,
}) })
await this.save({ await this.save({
...navigation, ...navigation,
@ -67,11 +69,20 @@ export class NavigationStore extends BudiStore {
if (!links?.length) { if (!links?.length) {
return return
} }
// Filter out the URLs to delete
urls = Array.isArray(urls) ? urls : [urls] urls = Array.isArray(urls) ? urls : [urls]
// Filter out top level links pointing to these URLs
links = links.filter(link => !urls.includes(link.url)) 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({ await this.save({
...navigation, ...navigation,
links, links,