From 09ad3e73aed8c0c160022c9d9857361ba1b5b794 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 25 Aug 2023 12:14:17 +0100 Subject: [PATCH] Rewrite most of the screen creation code to account for views and clean up mess --- .../store/screenTemplates/index.js | 11 +- .../store/screenTemplates/rowListScreen.js | 33 ++-- .../NewScreen/CreateScreenModal.svelte | 2 +- .../NewScreen/DatasourceModal.svelte | 187 ++++++------------ .../NewScreen/DatasourceTemplateRow.svelte | 42 ++++ 5 files changed, 122 insertions(+), 153 deletions(-) create mode 100644 packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/DatasourceTemplateRow.svelte diff --git a/packages/builder/src/builderStore/store/screenTemplates/index.js b/packages/builder/src/builderStore/store/screenTemplates/index.js index 1bf0af6eeb..3ff42fdec6 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/index.js +++ b/packages/builder/src/builderStore/store/screenTemplates/index.js @@ -1,10 +1,10 @@ import rowListScreen from "./rowListScreen" import createFromScratchScreen from "./createFromScratchScreen" -const allTemplates = tables => [...rowListScreen(tables)] +const allTemplates = datasources => [...rowListScreen(datasources)] // Allows us to apply common behaviour to all create() functions -const createTemplateOverride = (frontendState, template) => () => { +const createTemplateOverride = template => () => { const screen = template.create() screen.name = screen.props._id screen.routing.route = screen.routing.route.toLowerCase() @@ -12,14 +12,13 @@ const createTemplateOverride = (frontendState, template) => () => { return screen } -export default (frontendState, tables) => { +export default datasources => { const enrichTemplate = template => ({ ...template, - create: createTemplateOverride(frontendState, template), + create: createTemplateOverride(template), }) - const fromScratch = enrichTemplate(createFromScratchScreen) - const tableTemplates = allTemplates(tables).map(enrichTemplate) + const tableTemplates = allTemplates(datasources).map(enrichTemplate) return [ fromScratch, ...tableTemplates.sort((templateA, templateB) => { diff --git a/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js b/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js index 06d9e5aa3e..968d6deb4a 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/rowListScreen.js @@ -2,31 +2,26 @@ import sanitizeUrl from "./utils/sanitizeUrl" import { Screen } from "./utils/Screen" import { Component } from "./utils/Component" -export default function (tables) { - return tables.map(table => { +export default function (datasources) { + return datasources.map(datasource => { return { - name: `${table.name} - List`, - create: () => createScreen(table), + name: `${datasource.name} - List`, + create: () => createScreen(datasource), id: ROW_LIST_TEMPLATE, - table: table._id, + resourceId: datasource.resourceId, } }) } export const ROW_LIST_TEMPLATE = "ROW_LIST_TEMPLATE" -export const rowListUrl = table => sanitizeUrl(`/${table.name}`) +export const rowListUrl = datasource => sanitizeUrl(`/${datasource.name}`) -const generateTableBlock = table => { +const generateTableBlock = datasource => { const tableBlock = new Component("@budibase/standard-components/tableblock") tableBlock .customProps({ - title: table.name, - dataSource: { - label: table.name, - name: table._id, - tableId: table._id, - type: "table", - }, + title: datasource.name, + dataSource: datasource, sortOrder: "Ascending", size: "spectrum--medium", paginate: true, @@ -36,14 +31,14 @@ const generateTableBlock = table => { titleButtonText: "Create row", titleButtonClickBehaviour: "new", }) - .instanceName(`${table.name} - Table block`) + .instanceName(`${datasource.name} - Table block`) return tableBlock } -const createScreen = table => { +const createScreen = datasource => { return new Screen() - .route(rowListUrl(table)) - .instanceName(`${table.name} - List`) - .addChild(generateTableBlock(table)) + .route(rowListUrl(datasource)) + .instanceName(`${datasource.name} - List`) + .addChild(generateTableBlock(datasource)) .json() } diff --git a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte index cc4415ce2c..2bfa2d0013 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte @@ -179,7 +179,7 @@ diff --git a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/DatasourceModal.svelte b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/DatasourceModal.svelte index 26e44ca1d0..ad62d84eaf 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/DatasourceModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/DatasourceModal.svelte @@ -1,41 +1,30 @@ + +
+ + {datasource.name} + {#if selected} + + + + {/if} +
+ +