From 085cfdccadcef74f98eb020043604aec4d40959c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 18 Jun 2021 12:23:33 +0100 Subject: [PATCH] Update autoscreen link generation to work with new layouts --- .../src/builderStore/store/frontend.js | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 50f75d69e4..8746cf94ac 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -536,37 +536,50 @@ export const getFrontendStore = () => { return } - // Find a nav bar in the main layout - 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, + // Add link setting to main layout + if (layout.props._component.endsWith("layout")) { + // If using a new SDK, add to the layout component settings + if (!layout.props.links) { + layout.props.links = [] + } + layout.props.links.push({ 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 - nav._children = [...nav._children, newLink] await store.actions.layouts.save(layout) }, },