Addressing PR comments.

This commit is contained in:
mike12345567 2024-06-21 11:27:47 +01:00
parent fead1f436a
commit b4910043c6
4 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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)',
},
})
})

View File

@ -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)`
)
}

View File

@ -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
}