From a25020aad73748f215015abd5b3a4e37663f8456 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 13 Oct 2021 11:39:36 +0100 Subject: [PATCH] refactor new autocolumn functionality --- packages/bbui/src/Table/CellRenderer.svelte | 13 +++------- .../backend/DataTable/DataTable.svelte | 24 +++++++++++++++++-- .../builder/src/constants/backend/index.js | 4 ---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/bbui/src/Table/CellRenderer.svelte b/packages/bbui/src/Table/CellRenderer.svelte index 8ab180eb8b..262b7929f0 100644 --- a/packages/bbui/src/Table/CellRenderer.svelte +++ b/packages/bbui/src/Table/CellRenderer.svelte @@ -25,18 +25,11 @@ array: ArrayRenderer, internal: InternalRenderer, } + console.log(value) + $: type = schema?.type ?? "string" $: customRenderer = customRenderers?.find(x => x.column === schema?.name) - $: { - // this has to be done purely in the front-end due to migration issues - // the schema gets overriden on every tables fetch so we can't just set - // these to be a new type unfortunately - if (schema.name === "_id" || schema.name === "_rev") { - renderer = typeMap.internal - } else { - renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer - } - } + $: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer {#if renderer && (customRenderer || (value != null && value !== ""))} diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1cba1c31d9..02dc613ac1 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -16,11 +16,31 @@ import { Pagination } from "@budibase/bbui" let hideAutocolumns = true - + let schema $: isUsersTable = $tables.selected?._id === TableNames.USERS - $: schema = $tables.selected?.schema $: type = $tables.selected?.type $: isInternal = type !== "external" + $: { + 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", + name: "ID", + autocolumn: true, + } + if (isInternal) { + schema._rev = { + type: "internal", + editable: false, + displayName: "Revision", + name: "REV", + autocolumn: true, + } + } + } $: id = $tables.selected?._id $: search = searchTable(id) $: columnOptions = Object.keys($search.schema || {}) diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 7ddfdc1b2f..088db024a6 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -97,8 +97,6 @@ export const AUTO_COLUMN_SUB_TYPES = { CREATED_AT: "createdAt", UPDATED_BY: "updatedBy", UPDATED_AT: "updatedAt", - _id: "_id", - _rev: "_rev", } export const AUTO_COLUMN_DISPLAY_NAMES = { @@ -107,8 +105,6 @@ export const AUTO_COLUMN_DISPLAY_NAMES = { CREATED_AT: "Created At", UPDATED_BY: "Updated By", UPDATED_AT: "Updated At", - _id: "_id", - _rev: "_rev", } export const FILE_TYPES = {