diff --git a/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts b/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts index 4a943ddd67..2437fa8864 100644 --- a/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/utils.spec.ts @@ -7,7 +7,7 @@ describe("rowProcessor utility", () => { const schema: FieldSchema = { name: "", type: FieldType.LINK, - subtype: "", // missing subtype + subtype: undefined, // missing subtype icon: "ri-magic-line", autocolumn: true, constraints: { type: "array", presence: false }, @@ -22,31 +22,31 @@ describe("rowProcessor utility", () => { expect(fixAutoColumnSubType(schema).subtype).toEqual( AutoFieldSubTypes.CREATED_BY ) - schema.subtype = "" + schema.subtype = undefined schema.name = AutoFieldDefaultNames.UPDATED_BY expect(fixAutoColumnSubType(schema).subtype).toEqual( AutoFieldSubTypes.UPDATED_BY ) - schema.subtype = "" + schema.subtype = undefined schema.name = AutoFieldDefaultNames.CREATED_AT expect(fixAutoColumnSubType(schema).subtype).toEqual( AutoFieldSubTypes.CREATED_AT ) - schema.subtype = "" + schema.subtype = undefined schema.name = AutoFieldDefaultNames.UPDATED_AT expect(fixAutoColumnSubType(schema).subtype).toEqual( AutoFieldSubTypes.UPDATED_AT ) - schema.subtype = "" + schema.subtype = undefined schema.name = AutoFieldDefaultNames.AUTO_ID expect(fixAutoColumnSubType(schema).subtype).toEqual( AutoFieldSubTypes.AUTO_ID ) - schema.subtype = "" + schema.subtype = undefined }) it("returns the column if subtype exists", async () => { diff --git a/packages/server/src/utilities/rowProcessor/utils.ts b/packages/server/src/utilities/rowProcessor/utils.ts index 0a051a02e2..f93fdc4c46 100644 --- a/packages/server/src/utilities/rowProcessor/utils.ts +++ b/packages/server/src/utilities/rowProcessor/utils.ts @@ -5,13 +5,20 @@ import { FormulaTypes, } from "../../constants" import { processStringSync } from "@budibase/string-templates" -import { FieldSchema, Row, Table } from "@budibase/types" +import { + AutoColumnFieldMetadata, + FieldSchema, + Row, + Table, +} from "@budibase/types" /** * If the subtype has been lost for any reason this works out what * subtype the auto column should be. */ -export function fixAutoColumnSubType(column: FieldSchema) { +export function fixAutoColumnSubType( + column: FieldSchema +): AutoColumnFieldMetadata | FieldSchema { if (!column.autocolumn || !column.name || column.subtype) { return column } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 9cfd67bf80..6ecc32dca4 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -1,6 +1,6 @@ // all added by grid/table when defining the // column size, position and whether it can be viewed -import { FieldType } from "../row" +import { FieldSubtype, FieldType } from "../row" import { AutoFieldSubTypes, AutoReason, @@ -15,11 +15,13 @@ export interface UIFieldMetadata { icon?: string } -interface BaseRelationshipFieldMetadata extends BaseFieldSchema { +interface BaseRelationshipFieldMetadata + extends Omit { type: FieldType.LINK main?: boolean fieldName?: string tableId: string + subtype?: Omit } export interface ManyToManyRelationshipFieldMetadata extends BaseRelationshipFieldMetadata { @@ -43,7 +45,8 @@ export type RelationshipFieldMetadata = | OneToManyRelationshipFieldMetadata | ManyToOneRelationshipFieldMetadata -export interface AutoColumnFieldMetadata extends BaseFieldSchema { +export interface AutoColumnFieldMetadata + extends Omit { type: FieldType.AUTO autocolumn: true subtype?: AutoFieldSubTypes @@ -52,7 +55,7 @@ export interface AutoColumnFieldMetadata extends BaseFieldSchema { autoReason?: AutoReason } -export interface NumberFieldMetadata extends BaseFieldSchema { +export interface NumberFieldMetadata extends Omit { type: FieldType.NUMBER autocolumn?: boolean subtype?: AutoFieldSubTypes.AUTO_ID @@ -86,6 +89,12 @@ export interface FormulaFieldMetadata extends BaseFieldSchema { formulaType?: FormulaTypes } +export interface BBReferenceFieldMetadata + extends Omit { + type: FieldType.BB_REFERENCE + subtype: FieldSubtype.USER +} + export interface FieldConstraints { type?: string email?: boolean @@ -118,7 +127,7 @@ interface BaseFieldSchema extends UIFieldMetadata { constraints?: FieldConstraints autocolumn?: boolean autoReason?: AutoReason.FOREIGN_KEY - subtype?: string + subtype?: never } interface OtherFieldMetadata extends BaseFieldSchema { @@ -143,6 +152,7 @@ export type FieldSchema = | FormulaFieldMetadata | NumberFieldMetadata | LongFormFieldMetadata + | BBReferenceFieldMetadata export interface TableSchema { [key: string]: FieldSchema