From 8be84e5602eb33281dae06e81f289e28c8710599 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 23 Nov 2021 12:10:40 +0000 Subject: [PATCH 1/8] Quick fix for #3485 - default the key to the primary key but allow another field to be selected. --- .../Datasources/CreateEditRelationship.svelte | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 81032da716..8b984b5dea 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -71,6 +71,9 @@ if ($touched.toCol && !toRelate.name) { errors.toCol = colNotSet } + if ($touched.primary && !fromPrimary) { + errors.primary = "Please pick the primary key" + } // currently don't support relationships back onto the table itself, needs to relate out const tableError = "From/to/through tables must be different" if (fromTable && (fromTable === toTable || fromTable === throughTable)) { @@ -95,6 +98,12 @@ return errors } + $: isManyToMany = + fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_MANY + $: isManyToOne = + fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_ONE + $: fromPrimary = + !fromPrimary && fromTable ? fromTable.primary[0] : fromPrimary $: tableOptions = plusTables.map(table => ({ label: table.name, value: table._id, @@ -179,13 +188,13 @@ // foreignKey is what is linking out of the current table. relateFrom = { ...relateFrom, - foreignKey: fromTable.primary[0], + foreignKey: fromPrimary, } relateTo = { ...relateTo, relationshipType: RelationshipTypes.ONE_TO_MANY, foreignKey: relateFrom.fieldName, - fieldName: fromTable.primary[0], + fieldName: fromPrimary, } } @@ -264,6 +273,15 @@ bind:error={errors.from} bind:value={toRelationship.tableId} /> + {#if isManyToOne && fromTable} + - {#if fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_MANY} + {#if isManyToMany} Date: Tue, 23 Nov 2021 20:14:28 +0000 Subject: [PATCH 2/8] some autoscreen ux fixes --- .../NavigationPanel/NewScreenModal.svelte | 129 +++++++++++------- .../NavigationPanel/ScreenDetailsModal.svelte | 15 +- .../NavigationPanel/ScreenWizard.svelte | 35 +++-- 3 files changed, 123 insertions(+), 56 deletions(-) diff --git a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte index e7c9ef6ff2..1483517c20 100644 --- a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte @@ -1,13 +1,20 @@ - (autoSelected ? save() : chooseModal(1))} - disabled={!selectedScreens.length} - size="L" -> - Please select the screens you would like to add to your application. - Autogenerated screens come with CRUD functionality. + (autoSelected ? save() : chooseModal(1))} + disabled={!selectedScreens.length} + size="L" > - - - Blank screen -
x.id.includes(blankScreen))} - on:click={() => - toggleScreenSelection(templates.find(t => t.id === blankScreen))} - class:disabled={autoSelected} + Please select the screens you would like to add to your application. + Autogenerated screens come with CRUD functionality. -
- Blank -
-
- {#if selectedScreens.find(x => x.id === blankScreen)} - - {/if} -
-
- Autogenerated Screens - {#each $tables.list.filter(table => table._id !== "ta_users") as table} + + Blank screen
x.name.includes(table.name))} - on:click={() => toggleScreenSelection(table)} class="item" + class:selected={selectedScreens.find(x => x.id.includes(blankScreen))} + on:click={() => + toggleScreenSelection(templates.find(t => t.id === blankScreen))} + class:disabled={autoSelected} > -
- {table.name} +
+
Blank
- {#if selectedScreens.find(x => x.name.includes(table.name))} - + {#if selectedScreens.find(x => x.id === blankScreen)} +
+ +
{/if}
- {/each} - - + Autogenerated Screens + + {#each $tables.list.filter(table => table._id !== "ta_users") as table} +
+ x.name.includes(table.name) + )} + on:click={() => toggleScreenSelection(table)} + class="item" + > +
+
{table.name}
+
+
+ {#if selectedScreens.find(x => x.name.includes(table.name))} +
+ +
+ {/if} +
+
+ {/each} + +
+ {#if showProgressCircle} + + {/if} +
+ +
diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte index 7018bc2ed4..a86f0c2d75 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte @@ -12,34 +12,39 @@ let screenName = "" let url = "" let selectedScreens = [] - let roleId = $selectedAccessRole || "BASIC" - + let showProgressCircle = false let routeError let createdScreens = [] - $: { - selectedScreens?.forEach(screen => { - createdScreens = [...createdScreens, screen.create()] - }) + + const createScreens = async () => { + for (let screen of selectedScreens) { + let test = screen.create() + createdScreens.push(test) + } } const save = async () => { + showProgressCircle = true + await createScreens() for (let screen of createdScreens) { await saveScreens(screen) } await store.actions.routing.fetch() selectedScreens = [] + createdScreens = [] screenName = "" url = "" + showProgressCircle = false } const saveScreens = async draftScreen => { let existingScreenCount = $store.screens.filter( s => s.props._instanceName == draftScreen.props._instanceName ).length - if (existingScreenCount > 0) { let oldUrlArr = draftScreen.routing.route.split("/") + console.log(oldUrlArr) oldUrlArr[1] = `${oldUrlArr[1]}-${existingScreenCount + 1}` draftScreen.routing.route = oldUrlArr.join("/") } @@ -86,6 +91,7 @@ selectedScreens = [] screenName = "" url = "" + createdScreens = [] }) export const showModal = () => { @@ -109,9 +115,20 @@ - + - + From dd3d6aa630c6b46c5003f82cc39c2d760f568561 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 24 Nov 2021 11:53:56 +0000 Subject: [PATCH 3/8] unneeded log --- .../src/components/design/NavigationPanel/ScreenWizard.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte index a86f0c2d75..62843ccc91 100644 --- a/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ScreenWizard.svelte @@ -44,7 +44,6 @@ ).length if (existingScreenCount > 0) { let oldUrlArr = draftScreen.routing.route.split("/") - console.log(oldUrlArr) oldUrlArr[1] = `${oldUrlArr[1]}-${existingScreenCount + 1}` draftScreen.routing.route = oldUrlArr.join("/") } From e3e8b538f5c9c1204033b9f2b2ea2bda26732836 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 24 Nov 2021 13:15:44 +0000 Subject: [PATCH 4/8] Review comments. --- .../backend/Datasources/CreateEditRelationship.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 8b984b5dea..104fd7cb5a 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -98,12 +98,16 @@ return errors } + let fromPrimary + $: { + if (!fromPrimary && fromTable) { + fromPrimary = fromTable.primary[0] + } + } $: isManyToMany = fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_MANY $: isManyToOne = fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_ONE - $: fromPrimary = - !fromPrimary && fromTable ? fromTable.primary[0] : fromPrimary $: tableOptions = plusTables.map(table => ({ label: table.name, value: table._id, From c021a6e49c9888f895afc53de97fb6894e941b3c Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Wed, 24 Nov 2021 13:56:19 +0000 Subject: [PATCH 5/8] v0.9.185-alpha.20 --- lerna.json | 2 +- packages/auth/package.json | 2 +- packages/bbui/package.json | 2 +- packages/builder/package.json | 8 ++++---- packages/cli/package.json | 2 +- packages/client/package.json | 6 +++--- packages/server/package.json | 8 ++++---- packages/string-templates/package.json | 2 +- packages/worker/package.json | 6 +++--- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lerna.json b/lerna.json index 1cd2802044..3e4e2c7b93 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/auth/package.json b/packages/auth/package.json index 3d43666fb7..abc9c01250 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/auth", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "description": "Authentication middlewares for budibase builder and apps", "main": "src/index.js", "author": "Budibase", diff --git a/packages/bbui/package.json b/packages/bbui/package.json index 9373420039..f4f3b0b510 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/bbui", "description": "A UI solution used in the different Budibase projects.", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "license": "AGPL-3.0", "svelte": "src/index.js", "module": "dist/bbui.es.js", diff --git a/packages/builder/package.json b/packages/builder/package.json index 7491f77e96..7893de66ba 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "license": "AGPL-3.0", "private": true, "scripts": { @@ -65,10 +65,10 @@ } }, "dependencies": { - "@budibase/bbui": "^0.9.185-alpha.19", - "@budibase/client": "^0.9.185-alpha.19", + "@budibase/bbui": "^0.9.185-alpha.20", + "@budibase/client": "^0.9.185-alpha.20", "@budibase/colorpicker": "1.1.2", - "@budibase/string-templates": "^0.9.185-alpha.19", + "@budibase/string-templates": "^0.9.185-alpha.20", "@sentry/browser": "5.19.1", "@spectrum-css/page": "^3.0.1", "@spectrum-css/vars": "^3.0.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index 4c65256f32..978b6be1e6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/cli", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "description": "Budibase CLI, for developers, self hosting and migrations.", "main": "src/index.js", "bin": { diff --git a/packages/client/package.json b/packages/client/package.json index 74091fe94f..8a38acbce5 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "license": "MPL-2.0", "module": "dist/budibase-client.js", "main": "dist/budibase-client.js", @@ -19,9 +19,9 @@ "dev:builder": "rollup -cw" }, "dependencies": { - "@budibase/bbui": "^0.9.185-alpha.19", + "@budibase/bbui": "^0.9.185-alpha.20", "@budibase/standard-components": "^0.9.139", - "@budibase/string-templates": "^0.9.185-alpha.19", + "@budibase/string-templates": "^0.9.185-alpha.20", "regexparam": "^1.3.0", "shortid": "^2.2.15", "svelte-spa-router": "^3.0.5" diff --git a/packages/server/package.json b/packages/server/package.json index 4fc9a40c74..652a8a4b1f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/server", "email": "hi@budibase.com", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "description": "Budibase Web Server", "main": "src/index.js", "repository": { @@ -68,9 +68,9 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.185-alpha.19", - "@budibase/client": "^0.9.185-alpha.19", - "@budibase/string-templates": "^0.9.185-alpha.19", + "@budibase/auth": "^0.9.185-alpha.20", + "@budibase/client": "^0.9.185-alpha.20", + "@budibase/string-templates": "^0.9.185-alpha.20", "@bull-board/api": "^3.7.0", "@bull-board/koa": "^3.7.0", "@elastic/elasticsearch": "7.10.0", diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index fa5c13b3fc..983f70f1cb 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/string-templates", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "description": "Handlebars wrapper for Budibase templating.", "main": "src/index.cjs", "module": "dist/bundle.mjs", diff --git a/packages/worker/package.json b/packages/worker/package.json index 3d6ffb12b5..55237212a5 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -1,7 +1,7 @@ { "name": "@budibase/worker", "email": "hi@budibase.com", - "version": "0.9.185-alpha.19", + "version": "0.9.185-alpha.20", "description": "Budibase background service", "main": "src/index.js", "repository": { @@ -29,8 +29,8 @@ "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/auth": "^0.9.185-alpha.19", - "@budibase/string-templates": "^0.9.185-alpha.19", + "@budibase/auth": "^0.9.185-alpha.20", + "@budibase/string-templates": "^0.9.185-alpha.20", "@koa/router": "^8.0.0", "@sentry/node": "^6.0.0", "@techpass/passport-openidconnect": "^0.3.0", From f959ea0adda2cdcaf01f0481756ba0b014c99817 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 24 Nov 2021 14:55:14 +0000 Subject: [PATCH 6/8] Adding more error tracking around column creation, to reduce confusion/users not understanding required settings. --- .../DataTable/modals/CreateEditColumn.svelte | 60 +- packages/builder/src/stores/backend/tables.js | 3 + packages/server/yarn.lock | 787 +----------------- 3 files changed, 62 insertions(+), 788 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 7902212b7e..3d352877fa 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -9,6 +9,7 @@ DatePicker, ModalContent, Context, + notifications, } from "@budibase/bbui" import { createEventDispatcher } from "svelte" import { cloneDeep } from "lodash/fp" @@ -25,7 +26,6 @@ SWITCHABLE_TYPES, } from "constants/backend" import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils" - import { notifications } from "@budibase/bbui" import ValuesList from "components/common/ValuesList.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import { truncate } from "lodash" @@ -72,13 +72,8 @@ $: invalid = !field.name || (field.type === LINK_TYPE && !field.tableId) || - Object.keys($tables.draft?.schema ?? {}).some( - key => key !== originalName && key === field.name - ) || - columnNameInvalid - $: columnNameInvalid = PROHIBITED_COLUMN_NAMES.some( - name => field.name === name - ) + Object.keys(errors).length !== 0 + $: errors = checkErrors(field) // used to select what different options can be displayed for column type $: canBeSearched = @@ -106,13 +101,17 @@ if (field.type === AUTO_TYPE) { field = buildAutoColumn($tables.draft.name, field.name, field.subtype) } - await tables.saveField({ - originalName, - field, - primaryDisplay, - indexes, - }) - dispatch("updatecolumns") + try { + await tables.saveField({ + originalName, + field, + primaryDisplay, + indexes, + }) + dispatch("updatecolumns") + } catch (err) { + notifications.error(err) + } } function deleteColumn() { @@ -258,6 +257,32 @@ fieldToCheck.constraints.numericality = {} } } + + function checkErrors(fieldInfo) { + function inUse(tbl, column, ogName = null) { + return Object.keys(tbl?.schema || {}).some( + key => key !== ogName && key === column + ) + } + const newError = {} + if (PROHIBITED_COLUMN_NAMES.some(name => fieldInfo.name === name)) { + newError.name = `${PROHIBITED_COLUMN_NAMES.join( + ", " + )} are not allowed as column names` + } else if (inUse($tables.draft, fieldInfo.name, originalName)) { + newError.name = `Column name already in use.` + } + if (fieldInfo.fieldName && fieldInfo.tableId) { + const relatedTable = $tables.list.find( + tbl => tbl._id === fieldInfo.tableId + ) + console.log(relatedTable) + if (inUse(relatedTable, fieldInfo.fieldName)) { + newError.relatedName = `Column name already in use in table ${relatedTable.name}` + } + } + return newError + }