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:
parent
68eeb12686
commit
380a0e7d30
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue