Update autoscreen link creation and deletion to use new app level navigation settings
This commit is contained in:
parent
955c7b0600
commit
1dd0528b17
|
@ -1,6 +1,11 @@
|
||||||
import { get, writable } from "svelte/store"
|
import { get, writable } from "svelte/store"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { currentAsset, mainLayout, selectedComponent } from "builderStore"
|
import {
|
||||||
|
currentAsset,
|
||||||
|
mainLayout,
|
||||||
|
selectedComponent,
|
||||||
|
selectedScreen,
|
||||||
|
} from "builderStore"
|
||||||
import {
|
import {
|
||||||
datasources,
|
datasources,
|
||||||
integrations,
|
integrations,
|
||||||
|
@ -617,35 +622,38 @@ export const getFrontendStore = () => {
|
||||||
},
|
},
|
||||||
links: {
|
links: {
|
||||||
save: async (url, title) => {
|
save: async (url, title) => {
|
||||||
const layout = get(mainLayout)
|
const navigation = get(store).navigation
|
||||||
if (!layout) {
|
let links = [...navigation?.links]
|
||||||
|
|
||||||
|
// Skip if we have an identical link
|
||||||
|
if (links.find(link => link.url === url && link.text === title)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add link setting to main layout
|
links.push({
|
||||||
if (!layout.props.links) {
|
|
||||||
layout.props.links = []
|
|
||||||
}
|
|
||||||
layout.props.links.push({
|
|
||||||
text: title,
|
text: title,
|
||||||
url,
|
url,
|
||||||
})
|
})
|
||||||
|
await store.actions.navigation.save({
|
||||||
await store.actions.layouts.save(layout)
|
...navigation,
|
||||||
|
links: [...links],
|
||||||
|
})
|
||||||
},
|
},
|
||||||
delete: async urls => {
|
delete: async urls => {
|
||||||
const layout = get(mainLayout)
|
const navigation = get(store).navigation
|
||||||
if (!layout?.props.links?.length) {
|
let links = navigation?.links
|
||||||
|
if (!links?.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out the URLs to delete
|
// Filter out the URLs to delete
|
||||||
urls = Array.isArray(urls) ? urls : [urls]
|
urls = Array.isArray(urls) ? urls : [urls]
|
||||||
layout.props.links = layout.props.links.filter(
|
links = links.filter(link => !urls.includes(link.url))
|
||||||
link => !urls.includes(link.url)
|
|
||||||
)
|
|
||||||
|
|
||||||
await store.actions.layouts.save(layout)
|
await store.actions.navigation.save({
|
||||||
|
...navigation,
|
||||||
|
links,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
settings: {
|
settings: {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
import getTemplates from "builderStore/store/screenTemplates"
|
import getTemplates from "builderStore/store/screenTemplates"
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
import { Roles } from "constants/backend"
|
import { Roles } from "constants/backend"
|
||||||
|
import { capitalise } from "helpers"
|
||||||
|
|
||||||
let pendingScreen
|
let pendingScreen
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@
|
||||||
if (screen.props._instanceName.endsWith("List")) {
|
if (screen.props._instanceName.endsWith("List")) {
|
||||||
await store.actions.links.save(
|
await store.actions.links.save(
|
||||||
screen.routing.route,
|
screen.routing.route,
|
||||||
screen.routing.route.split("/")[1]
|
capitalise(screen.routing.route.split("/")[1])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue