From 7f055ed8dcb897162e52a35c342bfaf04e0cd152 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 10 Nov 2021 15:01:44 +0000 Subject: [PATCH] Adding a way to switch between string and options, as well as number and boolean types, this is very useful for SQL tables. --- .../DataTable/modals/CreateEditColumn.svelte | 19 +++++++++++++++++-- .../builder/src/constants/backend/index.js | 16 ++++++++++++++++ packages/builder/src/stores/backend/tables.js | 7 ++++++- .../src/api/controllers/table/external.js | 5 +++++ .../src/api/controllers/table/internal.js | 6 +++++- .../server/src/api/controllers/table/utils.js | 19 ++++++++++++++++++- packages/server/src/constants/index.js | 7 +++++++ .../server/src/integrations/base/sqlTable.ts | 2 +- 8 files changed, 75 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index aa21799ca2..83ed741b75 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -18,6 +18,11 @@ FIELDS, AUTO_COLUMN_SUB_TYPES, RelationshipTypes, + ALLOWABLE_STRING_OPTIONS, + ALLOWABLE_NUMBER_OPTIONS, + ALLOWABLE_STRING_TYPES, + ALLOWABLE_NUMBER_TYPES, + SWITCHABLE_TYPES, } from "constants/backend" import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils" import { notifications } from "@budibase/bbui" @@ -92,6 +97,9 @@ opt.type === table.type && table.sourceId === opt.sourceId ) + $: typeEnabled = + !originalName || + (originalName && SWITCHABLE_TYPES.indexOf(field.type) !== -1) async function saveColumn() { if (field.type === AUTO_TYPE) { @@ -204,7 +212,14 @@ } function getAllowedTypes() { - if (!external) { + if (originalName && ALLOWABLE_STRING_TYPES.indexOf(field.type) !== -1) { + return ALLOWABLE_STRING_OPTIONS + } else if ( + originalName && + ALLOWABLE_NUMBER_TYPES.indexOf(field.type) !== -1 + ) { + return ALLOWABLE_NUMBER_OPTIONS + } else if (!external) { return [ ...Object.values(fieldDefinitions), { name: "Auto Column", type: AUTO_TYPE }, @@ -259,7 +274,7 @@ />