Remove subtype from the base field schema
This commit is contained in:
parent
74cba9de27
commit
f57104730e
|
@ -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 () => {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<BaseFieldSchema, "subtype"> {
|
||||
type: FieldType.LINK
|
||||
main?: boolean
|
||||
fieldName?: string
|
||||
tableId: string
|
||||
subtype?: Omit<AutoFieldSubTypes, AutoFieldSubTypes.AUTO_ID>
|
||||
}
|
||||
export interface ManyToManyRelationshipFieldMetadata
|
||||
extends BaseRelationshipFieldMetadata {
|
||||
|
@ -43,7 +45,8 @@ export type RelationshipFieldMetadata =
|
|||
| OneToManyRelationshipFieldMetadata
|
||||
| ManyToOneRelationshipFieldMetadata
|
||||
|
||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||
export interface AutoColumnFieldMetadata
|
||||
extends Omit<BaseFieldSchema, "subtype"> {
|
||||
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<BaseFieldSchema, "subtype"> {
|
||||
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<BaseFieldSchema, "subtype"> {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue