Update autoscreen link generation to work with new layouts

This commit is contained in:
Andrew Kingston 2021-06-18 12:23:33 +01:00
parent b497000f7b
commit 085cfdccad
1 changed files with 39 additions and 26 deletions

View File

@ -536,37 +536,50 @@ export const getFrontendStore = () => {
return return
} }
// Find a nav bar in the main layout // Add link setting to main layout
const nav = findComponentType( if (layout.props._component.endsWith("layout")) {
layout.props, // If using a new SDK, add to the layout component settings
"@budibase/standard-components/navigation" if (!layout.props.links) {
) layout.props.links = []
if (!nav) { }
return layout.props.links.push({
}
let newLink
if (nav._children && nav._children.length) {
// Clone an existing link if one exists
newLink = cloneDeep(nav._children[0])
// Set our new props
newLink._id = uuid()
newLink._instanceName = `${title} Link`
newLink.url = url
newLink.text = title
} else {
// Otherwise create vanilla new link
newLink = {
...store.actions.components.createInstance("link"),
url,
text: title, text: title,
_instanceName: `${title} Link`, url,
})
} else {
// If using an old SDK, add to the navigation component
// TODO: remove this when we can assume everyone has updated
const nav = findComponentType(
layout.props,
"@budibase/standard-components/navigation"
)
if (!nav) {
return
}
let newLink
if (nav._children && nav._children.length) {
// Clone an existing link if one exists
newLink = cloneDeep(nav._children[0])
// Set our new props
newLink._id = uuid()
newLink._instanceName = `${title} Link`
newLink.url = url
newLink.text = title
} else {
// Otherwise create vanilla new link
newLink = {
...store.actions.components.createInstance("link"),
url,
text: title,
_instanceName: `${title} Link`,
}
nav._children = [...nav._children, newLink]
} }
} }
// Save layout // Save layout
nav._children = [...nav._children, newLink]
await store.actions.layouts.save(layout) await store.actions.layouts.save(layout)
}, },
}, },