From b4910043c67fe3bcd9c162684a46bee5bcaaa707 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 21 Jun 2024 11:27:47 +0100 Subject: [PATCH] Addressing PR comments. --- .../backend/DataTable/modals/CreateEditColumn.svelte | 1 - packages/server/src/api/routes/tests/table.spec.ts | 11 +++++------ packages/server/src/sdk/app/tables/internal/index.ts | 8 +++++--- packages/shared-core/src/table.ts | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 29d418c1f6..d79eedd194 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -54,7 +54,6 @@ const DATE_TYPE = FieldType.DATETIME const dispatch = createEventDispatcher() - const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"] const { dispatch: gridDispatch, rows } = getContext("grid") export let field diff --git a/packages/server/src/api/routes/tests/table.spec.ts b/packages/server/src/api/routes/tests/table.spec.ts index a84fd923bb..e75e5e23e7 100644 --- a/packages/server/src/api/routes/tests/table.spec.ts +++ b/packages/server/src/api/routes/tests/table.spec.ts @@ -289,18 +289,17 @@ describe.each([ status: 400, body: { message: - 'Column "type" is duplicated - make sure there are no duplicate columns names, this is case insensitive.', + 'Column(s) "type" are duplicated - check for other columns with these name (case in-sensitive)', }, }) - saveTableRequest.schema = { - foo: { type: FieldType.STRING, name: "foo" }, - FOO: { type: FieldType.STRING, name: "FOO" }, - } + saveTableRequest.schema.foo = { type: FieldType.STRING, name: "foo" } + saveTableRequest.schema.FOO = { type: FieldType.STRING, name: "FOO" } + await config.api.table.save(saveTableRequest, { status: 400, body: { message: - 'Column "foo" is duplicated - make sure there are no duplicate columns names, this is case insensitive.', + 'Column(s) "type, foo" are duplicated - check for other columns with these name (case in-sensitive)', }, }) }) diff --git a/packages/server/src/sdk/app/tables/internal/index.ts b/packages/server/src/sdk/app/tables/internal/index.ts index 9178b2cea3..fc32708708 100644 --- a/packages/server/src/sdk/app/tables/internal/index.ts +++ b/packages/server/src/sdk/app/tables/internal/index.ts @@ -16,7 +16,7 @@ import { EventType, updateLinks } from "../../../../db/linkedRows" import { cloneDeep } from "lodash/fp" import isEqual from "lodash/isEqual" import { runStaticFormulaChecks } from "../../../../api/controllers/table/bulkFormula" -import { context, db as dbCore } from "@budibase/backend-core" +import { context } from "@budibase/backend-core" import { findDuplicateInternalColumns } from "@budibase/shared-core" import { getTable } from "../getters" import { checkAutoColumns } from "./utils" @@ -48,9 +48,11 @@ export async function save( // check for case sensitivity - we don't want to allow duplicated columns const duplicateColumn = findDuplicateInternalColumns(table) - if (duplicateColumn) { + if (duplicateColumn.length) { throw new Error( - `Column "${duplicateColumn}" is duplicated - make sure there are no duplicate columns names, this is case insensitive.` + `Column(s) "${duplicateColumn.join( + ", " + )}" are duplicated - check for other columns with these name (case in-sensitive)` ) } diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 1e40b38c05..4b578a2aef 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -53,21 +53,21 @@ export function canBeSortColumn(type: FieldType): boolean { return !!allowSortColumnByType[type] } -export function findDuplicateInternalColumns(table: Table): string | undefined { +export function findDuplicateInternalColumns(table: Table): string[] { // get the column names const columnNames = Object.keys(table.schema) .concat(CONSTANT_INTERNAL_ROW_COLS) .map(colName => colName.toLowerCase()) // there are duplicates const set = new Set(columnNames) - let foundDuplicate: string | undefined + let duplicates: string[] = [] if (set.size !== columnNames.length) { for (let key of set.keys()) { const count = columnNames.filter(name => name === key).length if (count > 1) { - foundDuplicate = key + duplicates.push(key) } } } - return foundDuplicate + return duplicates }