From ca5f5f44acb43e56e27f9d43c5de785a4adc341a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 15 Oct 2020 18:09:19 +0100 Subject: [PATCH 1/6] Fixing issues with table columns allowing weirdness to happen around casing, now only one column with a particular name can be specified, no matter what the case, but the case will be respected. --- .../builder/src/builderStore/store/backend.js | 18 ++++++++++++++++-- .../components/backend/DataTable/Table.svelte | 1 - .../DataTable/popovers/ColumnPopover.svelte | 3 --- packages/server/src/api/controllers/table.js | 16 ++++++++++++++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index f48b561ef0..3cdabf1ed5 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -1,4 +1,4 @@ -import { writable } from "svelte/store" +import { writable, get } from "svelte/store" import { cloneDeep } from "lodash/fp" import api from "../api" @@ -62,16 +62,30 @@ export const getBackendUiStore = () => { }), save: async table => { const updatedTable = cloneDeep(table) + const oldTable = get(store).tables.filter(t => t._id === table._id)[0] + const fieldNames = [] // update any renamed schema keys to reflect their names - for (let key in updatedTable.schema) { + for (let key of Object.keys(updatedTable.schema)) { + // if field name has been seen before remove it + if (fieldNames.indexOf(key.toLowerCase()) !== -1) { + delete updatedTable.schema[key] + continue + } const field = updatedTable.schema[key] + const oldField = oldTable?.schema[key] + // if the type has changed then revert back to the old field + if (oldField != null && oldField.type !== field.type) { + updatedTable.schema[key] = oldField + } // field has been renamed if (field.name && field.name !== key) { updatedTable.schema[field.name] = field updatedTable._rename = { old: key, updated: field.name } delete updatedTable.schema[key] } + // finally record this field has been used + fieldNames.push(key.toLowerCase()) } const SAVE_TABLE_URL = `/api/tables` diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 4c0dc06d39..8354b464c0 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -132,7 +132,6 @@ font-size: 24px; font-weight: 600; text-rendering: optimizeLegibility; - text-transform: capitalize; margin-top: 0; display: flex; flex-direction: row; diff --git a/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte index 2857b651c3..f844cdefae 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/ColumnPopover.svelte @@ -110,9 +110,6 @@ align-items: center; gap: var(--spacing-xs); } - .container span { - text-transform: capitalize; - } h5 { padding: var(--spacing-xl) 0 0 var(--spacing-xl); diff --git a/packages/server/src/api/controllers/table.js b/packages/server/src/api/controllers/table.js index 82f981e3e6..3030274016 100644 --- a/packages/server/src/api/controllers/table.js +++ b/packages/server/src/api/controllers/table.js @@ -41,6 +41,18 @@ exports.save = async function(ctx) { oldTable = await db.get(ctx.request.body._id) } + // make sure that types don't change of a column, have to remove + // the column if you want to change the type + if (oldTable && oldTable.schema) { + for (let propKey of Object.keys(tableToSave.schema)) { + let column = tableToSave.schema[propKey] + let oldColumn = oldTable.schema[propKey] + if (oldColumn && oldColumn.type !== column.type) { + ctx.throw(400, "Cannot change the type of a column") + } + } + } + // Don't rename if the name is the same let { _rename } = tableToSave if (_rename && _rename.old === _rename.updated) { @@ -50,9 +62,9 @@ exports.save = async function(ctx) { // rename row fields when table column is renamed if (_rename && tableToSave.schema[_rename.updated].type === "link") { - throw "Cannot rename a linked field." + ctx.throw(400, "Cannot rename a linked column.") } else if (_rename && tableToSave.primaryDisplay === _rename.old) { - throw "Cannot rename the display column." + ctx.throw(400, "Cannot rename the display column.") } else if (_rename) { const rows = await db.allDocs( getRowParams(tableToSave._id, null, { From 99b5efc40f829cf5c2ce625dec8be8434bb22de6 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 15 Oct 2020 18:11:36 +0100 Subject: [PATCH 2/6] Formatting. --- .../src/DataGrid/AttachmentCell/Button.svelte | 2 +- .../src/DataGrid/Component.svelte | 14 ++++-- .../src/attachments/AttachmentList.svelte | 45 +++++++++++-------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte b/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte index 139ffe02aa..12f3cc8e9f 100644 --- a/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte +++ b/packages/standard-components/src/DataGrid/AttachmentCell/Button.svelte @@ -3,4 +3,4 @@ export let files - \ No newline at end of file + diff --git a/packages/standard-components/src/DataGrid/Component.svelte b/packages/standard-components/src/DataGrid/Component.svelte index 0d86808961..2fb32ffcdd 100644 --- a/packages/standard-components/src/DataGrid/Component.svelte +++ b/packages/standard-components/src/DataGrid/Component.svelte @@ -12,7 +12,12 @@ import AgGrid from "@budibase/svelte-ag-grid" import CreateRowButton from "./CreateRow/Button.svelte" - import { TextButton as DeleteButton, Icon, Modal, ModalContent } from "@budibase/bbui" + import { + TextButton as DeleteButton, + Icon, + Modal, + ModalContent, + } from "@budibase/bbui" export let _bb export let datasource = {} @@ -25,7 +30,7 @@ let canEdit = editable && datasource && datasource.type !== "view" let canAddDelete = editable && datasource && datasource.type === "table" - let modal; + let modal let store = _bb.store let dataLoaded = false @@ -153,7 +158,10 @@ on:select={({ detail }) => (selectedRows = detail)} /> {/if} - + Are you sure you want to delete {selectedRows.length} row(s)? diff --git a/packages/standard-components/src/attachments/AttachmentList.svelte b/packages/standard-components/src/attachments/AttachmentList.svelte index e52eeef5a7..9d9b96246d 100644 --- a/packages/standard-components/src/attachments/AttachmentList.svelte +++ b/packages/standard-components/src/attachments/AttachmentList.svelte @@ -1,6 +1,6 @@ @@ -31,12 +31,19 @@ {:else}{/if} {file.name} -
+
+ +
{/each} - + Are you sure you want to delete this attachment? @@ -67,7 +74,7 @@ position: relative; } - button { + button { display: block; box-sizing: border-box; position: absolute; @@ -85,18 +92,18 @@ border-radius: var(--border-radius-xl); background: black; transition: transform 0.2s cubic-bezier(0.25, 0.1, 0.25, 1), - background 0.2s cubic-bezier(0.25, 0.1, 0.25, 1); + background 0.2s cubic-bezier(0.25, 0.1, 0.25, 1); -webkit-appearance: none; outline: none; - } - button:hover { - background-color: var(--grey-8); - cursor: pointer; - } - button:active { - background-color: var(--grey-9); - cursor: pointer; - } + } + button:hover { + background-color: var(--grey-8); + cursor: pointer; + } + button:active { + background-color: var(--grey-9); + cursor: pointer; + } .file { position: relative; From ea772c0342c22a7d29d86634aa6df06dfa69851d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 16 Oct 2020 09:33:17 +0100 Subject: [PATCH 3/6] Removing the pretty function on DataGrids to match the backend. --- packages/standard-components/src/DataGrid/Component.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/standard-components/src/DataGrid/Component.svelte b/packages/standard-components/src/DataGrid/Component.svelte index 2fb32ffcdd..3ccf826711 100644 --- a/packages/standard-components/src/DataGrid/Component.svelte +++ b/packages/standard-components/src/DataGrid/Component.svelte @@ -71,7 +71,7 @@ headerCheckboxSelection: i === 0 && canEdit, checkboxSelection: i === 0 && canEdit, valueSetter: setters.get(schema[key].type), - headerName: key.charAt(0).toUpperCase() + key.slice(1), + headerName: key, field: key, hide: shouldHideField(key), sortable: true, From f31cd884ec3078c1b916864b222157eedd0dd2ad Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 16 Oct 2020 09:54:35 +0100 Subject: [PATCH 4/6] linting --- .../userInterface/ComponentsHierarchy.svelte | 15 ++++++--------- .../src/DataGrid/Component.svelte | 15 +++++++++------ .../src/DataGrid/ViewDetails/Cell.svelte | 12 ++++++------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte index 8393299b12..add2a99d6a 100644 --- a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte @@ -27,15 +27,12 @@ const joinPath = join("/") const normalizedName = name => - pipe( - name, - [ - trimCharsStart("./"), - trimCharsStart("~/"), - trimCharsStart("../"), - trimChars(" "), - ] - ) + pipe(name, [ + trimCharsStart("./"), + trimCharsStart("~/"), + trimCharsStart("../"), + trimChars(" "), + ]) const changeScreen = screen => { store.setCurrentScreen(screen.props._instanceName) diff --git a/packages/standard-components/src/DataGrid/Component.svelte b/packages/standard-components/src/DataGrid/Component.svelte index 35b214f00f..675fb1d5b3 100644 --- a/packages/standard-components/src/DataGrid/Component.svelte +++ b/packages/standard-components/src/DataGrid/Component.svelte @@ -81,19 +81,22 @@ autoHeight: true, } }) - columnDefs = [...columnDefs, { - headerName: 'Details', - field: '_id', + columnDefs = [ + ...columnDefs, + { + headerName: "Details", + field: "_id", width: 25, flex: 0, editable: false, sortable: false, cellRenderer: getRenderer({ - type: '_id', - options: detailUrl + type: "_id", + options: detailUrl, }), autoHeight: true, - }] + }, + ] dataLoaded = true } }) diff --git a/packages/standard-components/src/DataGrid/ViewDetails/Cell.svelte b/packages/standard-components/src/DataGrid/ViewDetails/Cell.svelte index 58cf2a5408..09c9b15e6d 100644 --- a/packages/standard-components/src/DataGrid/ViewDetails/Cell.svelte +++ b/packages/standard-components/src/DataGrid/ViewDetails/Cell.svelte @@ -1,12 +1,12 @@ \ No newline at end of file + a { + color: var(--grey-6); + } + From e87d9afbaf41152b35b0f5d229ca469bce83e86e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 16 Oct 2020 11:59:59 +0100 Subject: [PATCH 5/6] Fixing an issue whereby in some enrichment calls the count of links would be doubled (counting both sides). --- packages/server/src/db/linkedRows/index.js | 9 +++++++-- packages/server/src/db/linkedRows/linkUtils.js | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/server/src/db/linkedRows/index.js b/packages/server/src/db/linkedRows/index.js index 0932fc665f..dedb0f84a5 100644 --- a/packages/server/src/db/linkedRows/index.js +++ b/packages/server/src/db/linkedRows/index.js @@ -1,5 +1,5 @@ const LinkController = require("./LinkController") -const { IncludeDocs, getLinkDocuments, createLinkView } = require("./linkUtils") +const { IncludeDocs, getLinkDocuments, createLinkView, getUniqueByProp } = require("./linkUtils") const _ = require("lodash") /** @@ -110,7 +110,12 @@ exports.attachLinkInfo = async (instanceId, rows) => { // now iterate through the rows and all field information for (let row of rows) { // get all links for row, ignore fieldName for now - const linkVals = responses.filter(el => el.thisId === row._id) + // have to get unique as the previous table query can + // return duplicates, could be querying for both tables in a relation + const linkVals = getUniqueByProp( + responses.filter(el => el.thisId === row._id), + "id" + ) for (let linkVal of linkVals) { // work out which link pertains to this row if (!(row[linkVal.fieldName] instanceof Array)) { diff --git a/packages/server/src/db/linkedRows/linkUtils.js b/packages/server/src/db/linkedRows/linkUtils.js index 8f548eed3d..5f600cc3cb 100644 --- a/packages/server/src/db/linkedRows/linkUtils.js +++ b/packages/server/src/db/linkedRows/linkUtils.js @@ -92,3 +92,9 @@ exports.getLinkDocuments = async function({ } } } + +exports.getUniqueByProp = (array, prop) => { + return array.filter((obj, pos, arr) => { + return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos + }) +} From a21a3f817ee0ec982d60bf3fe28e17cfd18c498d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 16 Oct 2020 12:13:27 +0100 Subject: [PATCH 6/6] Linting. --- packages/server/src/db/linkedRows/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/db/linkedRows/index.js b/packages/server/src/db/linkedRows/index.js index dedb0f84a5..6f745b6e7c 100644 --- a/packages/server/src/db/linkedRows/index.js +++ b/packages/server/src/db/linkedRows/index.js @@ -1,5 +1,10 @@ const LinkController = require("./LinkController") -const { IncludeDocs, getLinkDocuments, createLinkView, getUniqueByProp } = require("./linkUtils") +const { + IncludeDocs, + getLinkDocuments, + createLinkView, + getUniqueByProp, +} = require("./linkUtils") const _ = require("lodash") /**