From 29796c3490211344490eeb1a4669424f3e178d51 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Sun, 17 Oct 2021 21:23:30 +0100 Subject: [PATCH] Potential fix for issues with updating and saving rows and columns --- packages/bbui/src/Table/CellRenderer.svelte | 3 --- .../backend/DataTable/DataTable.svelte | 20 +------------------ .../server/src/api/controllers/table/index.js | 3 +++ packages/server/src/constants/index.js | 1 + .../src/utilities/rowProcessor/index.js | 6 ++++++ 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 1c3822e51e..a4345512a3 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -5,7 +5,6 @@ import RelationshipRenderer from "./RelationshipRenderer.svelte" import AttachmentRenderer from "./AttachmentRenderer.svelte" import ArrayRenderer from "./ArrayRenderer.svelte" - import InternalRenderer from "./InternalRenderer.svelte" export let row export let schema @@ -23,9 +22,7 @@ number: StringRenderer, longform: StringRenderer, array: ArrayRenderer, - internal: InternalRenderer, } - $: type = schema?.type ?? "string" $: customRenderer = customRenderers?.find(x => x.column === schema?.name) $: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index f1d23e8f3d..58c1ee1378 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -16,29 +16,11 @@ import { Pagination } from "@budibase/bbui" let hideAutocolumns = true - let schema $: isUsersTable = $tables.selected?._id === TableNames.USERS $: type = $tables.selected?.type $: isInternal = type !== "external" - $: { - schema = $tables.selected?.schema + $: schema = $tables.selected?.schema - // Manually add these as we don't want them to be 'real' auto-columns - schema._id = { - type: "internal", - editable: false, - displayName: "ID", - autocolumn: true, - } - if (isInternal) { - schema._rev = { - type: "internal", - editable: false, - displayName: "Revision", - autocolumn: true, - } - } - } $: id = $tables.selected?._id $: search = searchTable(id) $: columnOptions = Object.keys($search.schema || {}) diff --git a/packages/server/src/api/controllers/table/index.js b/packages/server/src/api/controllers/table/index.js index c7b72cf1c8..c48a117928 100644 --- a/packages/server/src/api/controllers/table/index.js +++ b/packages/server/src/api/controllers/table/index.js @@ -91,6 +91,9 @@ exports.save = async function (ctx) { for (let propKey of Object.keys(tableToSave.schema)) { let column = tableToSave.schema[propKey] let oldColumn = oldTable.schema[propKey] + if (oldColumn && oldColumn.type === "internal") { + oldColumn.type = "auto" + } if (oldColumn && oldColumn.type !== column.type) { ctx.throw(400, "Cannot change the type of a column") } diff --git a/packages/server/src/constants/index.js b/packages/server/src/constants/index.js index d19f9ff313..8c194e109c 100644 --- a/packages/server/src/constants/index.js +++ b/packages/server/src/constants/index.js @@ -42,6 +42,7 @@ exports.FieldTypes = { FORMULA: "formula", AUTO: "auto", JSON: "json", + INTERNAL: "internal", } exports.RelationshipTypes = { diff --git a/packages/server/src/utilities/rowProcessor/index.js b/packages/server/src/utilities/rowProcessor/index.js index 7d4ae3016e..624871c926 100644 --- a/packages/server/src/utilities/rowProcessor/index.js +++ b/packages/server/src/utilities/rowProcessor/index.js @@ -200,6 +200,12 @@ exports.inputProcessing = ( clonedRow[key] = exports.coerce(value, field.type) } } + + if (!clonedRow._id) { + clonedRow._id = row._id + clonedRow._rev = row._rev + } + // handle auto columns - this returns an object like {table, row} return processAutoColumn(user, copiedTable, clonedRow, opts) }