diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index 02134f0317..76102b9be4 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -37,6 +37,7 @@ import { jsonFromCsvString } from "../../../utilities/csv" import { builderSocket } from "../../../websockets" import { cloneDeep } from "lodash" import { + canBeDisplayColumn, helpers, PROTECTED_EXTERNAL_COLUMNS, PROTECTED_INTERNAL_COLUMNS, @@ -67,6 +68,20 @@ function checkDefaultFields(table: Table) { } } +function guardTable(table: Table) { + checkDefaultFields(table) + + if ( + table.primaryDisplay && + !canBeDisplayColumn(table.schema[table.primaryDisplay]?.type) + ) { + throw new HTTPError( + `Column "${table.primaryDisplay}" cannot be used as a display type.`, + 400 + ) + } +} + // covers both internal and external export async function fetch(ctx: UserCtx) { const internal = await sdk.tables.getAllInternalTables() @@ -111,7 +126,7 @@ export async function save(ctx: UserCtx) { const isCreate = !table._id - checkDefaultFields(table) + guardTable(table) let savedTable: Table if (isCreate) { diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 5402439d9c..070ee6c760 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -12,8 +12,8 @@ const allowDisplayColumnByType: Record = { [FieldType.AUTO]: true, [FieldType.INTERNAL]: true, [FieldType.BARCODEQR]: true, - [FieldType.BIGINT]: true, + [FieldType.BOOLEAN]: false, [FieldType.ARRAY]: false, [FieldType.ATTACHMENTS]: false,