From 1796a50d47bb35cd9014e46ee61b25a3b69779cc Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 16 Jun 2022 11:46:16 +0100 Subject: [PATCH 01/10] Use ID rather than name to identiy datasources when creating autoscreens --- .../store/screenTemplates/newRowScreen.js | 2 +- .../store/screenTemplates/rowDetailScreen.js | 2 +- .../store/screenTemplates/rowListScreen.js | 2 +- .../NavigationPanel/DatasourceModal.svelte | 16 +++++++--------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js b/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js index 2b9d2bc663..dd97c511e5 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/newRowScreen.js @@ -15,7 +15,7 @@ export default function (tables) { name: `${table.name} - New`, create: () => createScreen(table), id: NEW_ROW_TEMPLATE, - table: table.name, + table: table._id, } }) } diff --git a/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js b/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js index 8ab4a2bea7..a1916769c9 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/rowDetailScreen.js @@ -17,7 +17,7 @@ export default function (tables) { name: `${table.name} - Detail`, create: () => createScreen(table), id: ROW_DETAIL_TEMPLATE, - table: table.name, + table: table._id, } }) } diff --git a/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js b/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js index c369f99f68..39e88ae69e 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js @@ -10,7 +10,7 @@ export default function (tables) { name: `${table.name} - List`, create: () => createScreen(table), id: ROW_LIST_TEMPLATE, - table: table.name, + table: table._id, } }) } diff --git a/packages/builder/src/components/design/NavigationPanel/DatasourceModal.svelte b/packages/builder/src/components/design/NavigationPanel/DatasourceModal.svelte index 1cb3856165..bd9b6a1741 100644 --- a/packages/builder/src/components/design/NavigationPanel/DatasourceModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/DatasourceModal.svelte @@ -14,14 +14,14 @@ let selectedScreens = [...initalScreens] const toggleScreenSelection = (table, datasource) => { - if (selectedScreens.find(s => s.table === table.name)) { + if (selectedScreens.find(s => s.table === table._id)) { selectedScreens = selectedScreens.filter( - screen => screen.table !== table.name + screen => screen.table !== table._id ) } else { let partialTemplates = getTemplates($store, $tables.list).reduce( (acc, template) => { - if (template.table === table.name) { + if (template.table === table._id) { template.datasource = datasource.name acc.push(template) } @@ -88,7 +88,7 @@
x.table === table.name + x => x.table === table._id )} on:click={() => toggleScreenSelection(table, datasource)} > @@ -102,8 +102,7 @@ {table.name} - - {#if selectedScreens.find(x => x.table === table.name)} + {#if selectedScreens.find(x => x.table === table._id)} @@ -116,7 +115,7 @@
x.table === datasource.entities[table_key].name + x => x.table === datasource.entities[table_key]._id )} on:click={() => toggleScreenSelection( @@ -134,8 +133,7 @@ {datasource.entities[table_key].name} - - {#if selectedScreens.find(x => x.table === datasource.entities[table_key].name)} + {#if selectedScreens.find(x => x.table === datasource.entities[table_key]._id)} From 56187d0d3952798c0b981272bcafae9ab7170d46 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 16 Jun 2022 11:46:53 +0100 Subject: [PATCH 02/10] Fix logic around deleting autoscreens and autoscreen links --- .../src/builderStore/store/frontend.js | 116 +++++------------- .../NavigationPanel/ScreenWizard.svelte | 3 +- 2 files changed, 33 insertions(+), 86 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 641e2c2472..ec810e5c31 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -190,6 +190,7 @@ export const getFrontendStore = () => { // Build array of promises to speed up bulk deletions const promises = [] + let deleteUrls = [] screensToDelete.forEach(screen => { // Delete the screen promises.push( @@ -199,14 +200,10 @@ export const getFrontendStore = () => { }) ) // Remove links to this screen - promises.push( - store.actions.components.links.delete( - screen.routing.route, - screen.props._instanceName - ) - ) + deleteUrls.push(screen.routing.route) }) + promises.push(store.actions.links.delete(deleteUrls)) await Promise.all(promises) const deletedIds = screensToDelete.map(screen => screen._id) store.update(state => { @@ -578,89 +575,38 @@ export const getFrontendStore = () => { }) await store.actions.preview.saveSelected() }, - links: { - save: async (url, title) => { - const layout = get(mainLayout) - if (!layout) { - return - } + }, + links: { + save: async (url, title) => { + const layout = get(mainLayout) + if (!layout) { + return + } - // 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, - 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 - } + // Add link setting to main layout + if (!layout.props.links) { + layout.props.links = [] + } + layout.props.links.push({ + text: title, + url, + }) - let newLink - if (nav._children && nav._children.length) { - // Clone an existing link if one exists - newLink = cloneDeep(nav._children[0]) + await store.actions.layouts.save(layout) + }, + delete: async urls => { + const layout = get(mainLayout) + if (!layout?.props.links?.length) { + return + } - // Set our new props - newLink._id = Helpers.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] - } - } + // Filter out the URLs to delete + urls = Array.isArray(urls) ? urls : [urls] + layout.props.links = layout.props.links.filter( + link => !urls.includes(link.url) + ) - // Save layout - await store.actions.layouts.save(layout) - }, - delete: async (url, title) => { - const layout = get(mainLayout) - if (!layout) { - return - } - - // Add link setting to main layout - if (layout.props._component.endsWith("layout")) { - // If using a new SDK, add to the layout component settings - layout.props.links = layout.props.links.filter( - link => !(link.text === title && link.url === 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 - } - - nav._children = nav._children.filter( - child => !(child.url === url && child.text === title) - ) - } - // Save layout - await store.actions.layouts.save(layout) - }, + await store.actions.layouts.save(layout) }, }, settings: { diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte index 0a3c9611bc..5f36034b93 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte @@ -66,7 +66,7 @@ // Add link in layout for list screens if (screen.props._instanceName.endsWith("List")) { - await store.actions.components.links.save( + await store.actions.links.save( screen.routing.route, screen.routing.route.split("/")[1] ) @@ -131,6 +131,7 @@ const screens = selectedTemplates.map(template => { let screenTemplate = template.create() screenTemplate.datasource = template.datasource + screenTemplate.autoTableId = template.table return screenTemplate }) await createScreens({ screens, screenAccessRole }) From 2ad6f0a1ffb8bef3f17d09cae5fef570bd8627ed Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 20 Jun 2022 12:32:13 +0100 Subject: [PATCH 03/10] Add option to customise which columns are exported in export data action --- .../actions/ExportData.svelte | 63 +++++++++++++------ packages/client/src/utils/buttonActions.js | 1 + packages/frontend-core/src/api/rows.js | 5 +- .../src/api/controllers/row/external.js | 21 ++++++- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/ExportData.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/ExportData.svelte index 062b9abd4c..aa3bf2a36b 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/ExportData.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/actions/ExportData.svelte @@ -1,27 +1,18 @@