From 7d8cb16824d34cdc3fae80e169395ec7ddd6a687 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 13 Oct 2020 10:59:24 +0100 Subject: [PATCH 01/18] prevent duplicate table names --- .../popovers/CreateEditColumnPopover.svelte | 22 ++++++++++--------- .../modals/CreateTableModal.svelte | 17 ++++++++++++-- .../popovers/EditTablePopover.svelte | 19 ++++++++++++++-- .../standard-components/src/Navigation.svelte | 12 ++++++---- 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte index 2e2ad6f158..bc076266e5 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/CreateEditColumnPopover.svelte @@ -65,16 +65,18 @@
- + {#if !originalName} + + {/if} {#if field.type !== 'link'} model.name === tableName)) { + error = `Table with name ${tableName} already exists. Please choose another name.` + return + } + error = "" } async function saveTable() { @@ -61,12 +72,14 @@ title="Create Table" confirmText="Create" onConfirm={saveTable} - disabled={!name || (dataImport && !dataImport.valid)}> + disabled={error || !name || (dataImport && !dataImport.valid)}> + on:input={checkValid} + bind:value={name} + {error} />
diff --git a/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte index 028b78a1e8..36ccbb4800 100644 --- a/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/ModelNavigator/popovers/EditTablePopover.svelte @@ -11,6 +11,8 @@ let dropdown let editing let confirmDeleteDialog + let error = "" + let originalName = table.name $: fields = Object.keys(table.schema) @@ -39,6 +41,15 @@ notifier.success("Table renamed successfully") hideEditor() } + + function checkValid(evt) { + const tableName = evt.target.value + if (originalName !== tableName && $backendUiStore.models.some(model => model.name === tableName)) { + error = `Table with name ${tableName} already exists. Please choose another name.` + return + } + error = "" + }
@@ -48,7 +59,11 @@ {#if editing}
Edit Table
- + + {error} />
--> + diff --git a/packages/standard-components/src/DataGrid/Component.svelte b/packages/standard-components/src/DataGrid/Component.svelte index b7a277435d..6a2a6ded61 100644 --- a/packages/standard-components/src/DataGrid/Component.svelte +++ b/packages/standard-components/src/DataGrid/Component.svelte @@ -123,7 +123,9 @@ {#if selectedRows.length > 0} - Delete {selectedRows.length} row(s) + Delete + {selectedRows.length} + row(s) {/if}
diff --git a/packages/standard-components/src/Login.svelte b/packages/standard-components/src/Login.svelte index b7435def58..6f2acb2d97 100644 --- a/packages/standard-components/src/Login.svelte +++ b/packages/standard-components/src/Login.svelte @@ -42,9 +42,7 @@
{#if logo} -
- logo -
+
logo
{/if} {#if title} diff --git a/packages/standard-components/src/Text.svelte b/packages/standard-components/src/Text.svelte index 96fc09e025..55b8fb762b 100644 --- a/packages/standard-components/src/Text.svelte +++ b/packages/standard-components/src/Text.svelte @@ -33,6 +33,4 @@ {text} {:else if isTag('sup')} {text} -{:else} - {text} -{/if} +{:else}{text}{/if} diff --git a/packages/standard-components/src/attachments/AttachmentList.svelte b/packages/standard-components/src/attachments/AttachmentList.svelte index bb58d5b0a3..52f61e2d8e 100644 --- a/packages/standard-components/src/attachments/AttachmentList.svelte +++ b/packages/standard-components/src/attachments/AttachmentList.svelte @@ -12,9 +12,7 @@
{#if FILE_TYPES.IMAGE.includes(file.extension.toLowerCase())} preview of {file.name} - {:else} - - {/if} + {:else}{/if}
{file.name} diff --git a/yarn.lock b/yarn.lock index 9b84e373af..0c0f88a3d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3690,11 +3690,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier-plugin-svelte@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-0.7.0.tgz#5ac0b9f194e0450c88ff1e167cbf3b32d2642df2" - dependencies: - tslib "^1.9.3" +prettier-plugin-svelte@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-1.4.0.tgz#bb992759fb77ec2c3545d454a7c60f7a258cb745" + integrity sha512-KXO2He7Kql0Lz4DdlzVli1j2JTDUR9jPV/DqyfnJmY1pCeSV1qZkxgdsyYma35W6OLrCAr/G6yKdmzo+75u2Ng== prettier@^1.19.1: version "1.19.1" @@ -4529,7 +4528,7 @@ trim-off-newlines@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" -tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.9.0: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" From 4be3014e91d3351902cfab196d7c59d5540b0b2e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 14 Oct 2020 15:06:48 +0100 Subject: [PATCH 16/18] update row_save event --- .../userInterface/temporaryPanelStructure.js | 74 +++++++++---------- packages/server/src/api/controllers/row.js | 24 +++--- 2 files changed, 45 insertions(+), 53 deletions(-) diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js index 7914e1a43a..36a6c8e073 100644 --- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js +++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js @@ -1165,14 +1165,6 @@ export default { }, children: [], }, - // { - // name: "Map", - // _component: "@budibase/standard-components/datamap", - // description: "Shiny map", - // icon: "ri-map-pin-line", - // properties: { design: { ...all } }, - // children: [], - // }, ], }, { @@ -1206,39 +1198,39 @@ export default { ], }, }, - { - name: "Login", - _component: "@budibase/standard-components/login", - description: - "A component that automatically generates a login screen for your app.", - icon: "ri-login-box-line", - children: [], - properties: { - design: { ...all }, - settings: [ - { - label: "Name", - key: "name", - control: Input, - }, - { - label: "Logo", - key: "logo", - control: Input, - }, - { - label: "Title", - key: "title", - control: Input, - }, - { - label: "Button Text", - key: "buttonText", - control: Input, - }, - ], - }, - }, + // { + // name: "Login", + // _component: "@budibase/standard-components/login", + // description: + // "A component that automatically generates a login screen for your app.", + // icon: "ri-login-box-line", + // children: [], + // properties: { + // design: { ...all }, + // settings: [ + // { + // label: "Name", + // key: "name", + // control: Input, + // }, + // { + // label: "Logo", + // key: "logo", + // control: Input, + // }, + // { + // label: "Title", + // key: "title", + // control: Input, + // }, + // { + // label: "Button Text", + // key: "buttonText", + // control: Input, + // }, + // ], + // }, + // }, ], }, ], diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 9c39149bae..8466cfcc33 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -12,16 +12,16 @@ const { cloneDeep } = require("lodash") const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}` validateJs.extend(validateJs.validators.datetime, { - parse: function(value) { + parse: function (value) { return new Date(value).getTime() }, // Input is a unix timestamp - format: function(value) { + format: function (value) { return new Date(value).toISOString() }, }) -exports.patch = async function(ctx) { +exports.patch = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) let row = await db.get(ctx.params.id) @@ -67,7 +67,7 @@ exports.patch = async function(ctx) { ctx.message = `${table.name} updated successfully.` } -exports.save = async function(ctx) { +exports.save = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) let row = ctx.request.body @@ -107,7 +107,7 @@ exports.save = async function(ctx) { // make sure link rows are up to date row = await linkRows.updateLinks({ instanceId, - eventType: linkRows.EventType.RECORD_SAVE, + eventType: linkRows.EventType.ROW_SAVE, row, tableId: row.tableId, table, @@ -134,7 +134,7 @@ exports.save = async function(ctx) { ctx.message = `${table.name} created successfully` } -exports.fetchView = async function(ctx) { +exports.fetchView = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const { stats, group, field } = ctx.query @@ -166,7 +166,7 @@ exports.fetchView = async function(ctx) { ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows) } -exports.fetchTableRows = async function(ctx) { +exports.fetchTableRows = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const response = await db.allDocs( @@ -181,7 +181,7 @@ exports.fetchTableRows = async function(ctx) { ) } -exports.search = async function(ctx) { +exports.search = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const response = await db.allDocs({ @@ -194,7 +194,7 @@ exports.search = async function(ctx) { ) } -exports.find = async function(ctx) { +exports.find = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const row = await db.get(ctx.params.rowId) @@ -205,7 +205,7 @@ exports.find = async function(ctx) { ctx.body = await linkRows.attachLinkInfo(instanceId, row) } -exports.destroy = async function(ctx) { +exports.destroy = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const row = await db.get(ctx.params.rowId) @@ -227,7 +227,7 @@ exports.destroy = async function(ctx) { ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row) } -exports.validate = async function(ctx) { +exports.validate = async function (ctx) { const errors = await validate({ instanceId: ctx.user.instanceId, tableId: ctx.params.tableId, @@ -253,7 +253,7 @@ async function validate({ instanceId, tableId, row, table }) { return { valid: Object.keys(errors).length === 0, errors } } -exports.fetchEnrichedRow = async function(ctx) { +exports.fetchEnrichedRow = async function (ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const tableId = ctx.params.tableId From 802b05815d3e6edfa185962c4e69d90316d1bae7 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 14 Oct 2020 15:13:22 +0100 Subject: [PATCH 17/18] lint --- packages/server/src/api/controllers/row.js | 22 +++++++++---------- .../src/DataGrid/AttachmentCell/Button.svelte | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index 8466cfcc33..4042336741 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -12,16 +12,16 @@ const { cloneDeep } = require("lodash") const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}` validateJs.extend(validateJs.validators.datetime, { - parse: function (value) { + parse: function(value) { return new Date(value).getTime() }, // Input is a unix timestamp - format: function (value) { + format: function(value) { return new Date(value).toISOString() }, }) -exports.patch = async function (ctx) { +exports.patch = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) let row = await db.get(ctx.params.id) @@ -67,7 +67,7 @@ exports.patch = async function (ctx) { ctx.message = `${table.name} updated successfully.` } -exports.save = async function (ctx) { +exports.save = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) let row = ctx.request.body @@ -134,7 +134,7 @@ exports.save = async function (ctx) { ctx.message = `${table.name} created successfully` } -exports.fetchView = async function (ctx) { +exports.fetchView = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const { stats, group, field } = ctx.query @@ -166,7 +166,7 @@ exports.fetchView = async function (ctx) { ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows) } -exports.fetchTableRows = async function (ctx) { +exports.fetchTableRows = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const response = await db.allDocs( @@ -181,7 +181,7 @@ exports.fetchTableRows = async function (ctx) { ) } -exports.search = async function (ctx) { +exports.search = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const response = await db.allDocs({ @@ -194,7 +194,7 @@ exports.search = async function (ctx) { ) } -exports.find = async function (ctx) { +exports.find = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const row = await db.get(ctx.params.rowId) @@ -205,7 +205,7 @@ exports.find = async function (ctx) { ctx.body = await linkRows.attachLinkInfo(instanceId, row) } -exports.destroy = async function (ctx) { +exports.destroy = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const row = await db.get(ctx.params.rowId) @@ -227,7 +227,7 @@ exports.destroy = async function (ctx) { ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, instanceId, row) } -exports.validate = async function (ctx) { +exports.validate = async function(ctx) { const errors = await validate({ instanceId: ctx.user.instanceId, tableId: ctx.params.tableId, @@ -253,7 +253,7 @@ async function validate({ instanceId, tableId, row, table }) { return { valid: Object.keys(errors).length === 0, errors } } -exports.fetchEnrichedRow = async function (ctx) { +exports.fetchEnrichedRow = async function(ctx) { const instanceId = ctx.user.instanceId const db = new CouchDB(instanceId) const tableId = ctx.params.tableId diff --git a/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte b/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte index 3d8e6364b7..f2fc24fd92 100644 --- a/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte +++ b/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte @@ -27,4 +27,4 @@ on:newRow={() => dispatch('newRow')} /> --> - + From 8132c77f8c6da60cc1491ed53f03db7bf88d5b76 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 14 Oct 2020 16:47:53 +0100 Subject: [PATCH 18/18] don't show login component on logged in page, fix auth for app assets --- .../ComponentPropertiesPanel.svelte | 12 ---- .../ComponentSelectionList.svelte | 22 +----- .../userInterface/ItemTab/Tab.svelte | 10 ++- .../userInterface/temporaryPanelStructure.js | 67 ++++++++++--------- .../server/src/middleware/authenticated.js | 6 +- packages/server/src/middleware/authorized.js | 3 + .../src/DataGrid/AttachmentCell/Button.svelte | 2 +- 7 files changed, 51 insertions(+), 71 deletions(-) diff --git a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte index 800905202d..1331ce0bdb 100644 --- a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte +++ b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte @@ -1,21 +1,10 @@ {#if !list.isCategory} - + {/if} {#each list.children as item} - handleClick(item)} /> + {#if !item.showOnPages || item.showOnPages.includes($store.currentPageName)} + handleClick(item)} /> + {/if} {/each} --> +