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 = {
|
const schema: FieldSchema = {
|
||||||
name: "",
|
name: "",
|
||||||
type: FieldType.LINK,
|
type: FieldType.LINK,
|
||||||
subtype: "", // missing subtype
|
subtype: undefined, // missing subtype
|
||||||
icon: "ri-magic-line",
|
icon: "ri-magic-line",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
constraints: { type: "array", presence: false },
|
constraints: { type: "array", presence: false },
|
||||||
|
@ -22,31 +22,31 @@ describe("rowProcessor utility", () => {
|
||||||
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
||||||
AutoFieldSubTypes.CREATED_BY
|
AutoFieldSubTypes.CREATED_BY
|
||||||
)
|
)
|
||||||
schema.subtype = ""
|
schema.subtype = undefined
|
||||||
|
|
||||||
schema.name = AutoFieldDefaultNames.UPDATED_BY
|
schema.name = AutoFieldDefaultNames.UPDATED_BY
|
||||||
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
||||||
AutoFieldSubTypes.UPDATED_BY
|
AutoFieldSubTypes.UPDATED_BY
|
||||||
)
|
)
|
||||||
schema.subtype = ""
|
schema.subtype = undefined
|
||||||
|
|
||||||
schema.name = AutoFieldDefaultNames.CREATED_AT
|
schema.name = AutoFieldDefaultNames.CREATED_AT
|
||||||
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
||||||
AutoFieldSubTypes.CREATED_AT
|
AutoFieldSubTypes.CREATED_AT
|
||||||
)
|
)
|
||||||
schema.subtype = ""
|
schema.subtype = undefined
|
||||||
|
|
||||||
schema.name = AutoFieldDefaultNames.UPDATED_AT
|
schema.name = AutoFieldDefaultNames.UPDATED_AT
|
||||||
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
||||||
AutoFieldSubTypes.UPDATED_AT
|
AutoFieldSubTypes.UPDATED_AT
|
||||||
)
|
)
|
||||||
schema.subtype = ""
|
schema.subtype = undefined
|
||||||
|
|
||||||
schema.name = AutoFieldDefaultNames.AUTO_ID
|
schema.name = AutoFieldDefaultNames.AUTO_ID
|
||||||
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
expect(fixAutoColumnSubType(schema).subtype).toEqual(
|
||||||
AutoFieldSubTypes.AUTO_ID
|
AutoFieldSubTypes.AUTO_ID
|
||||||
)
|
)
|
||||||
schema.subtype = ""
|
schema.subtype = undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
it("returns the column if subtype exists", async () => {
|
it("returns the column if subtype exists", async () => {
|
||||||
|
|
|
@ -5,13 +5,20 @@ import {
|
||||||
FormulaTypes,
|
FormulaTypes,
|
||||||
} from "../../constants"
|
} from "../../constants"
|
||||||
import { processStringSync } from "@budibase/string-templates"
|
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
|
* If the subtype has been lost for any reason this works out what
|
||||||
* subtype the auto column should be.
|
* 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) {
|
if (!column.autocolumn || !column.name || column.subtype) {
|
||||||
return column
|
return column
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// all added by grid/table when defining the
|
// all added by grid/table when defining the
|
||||||
// column size, position and whether it can be viewed
|
// column size, position and whether it can be viewed
|
||||||
import { FieldType } from "../row"
|
import { FieldSubtype, FieldType } from "../row"
|
||||||
import {
|
import {
|
||||||
AutoFieldSubTypes,
|
AutoFieldSubTypes,
|
||||||
AutoReason,
|
AutoReason,
|
||||||
|
@ -15,11 +15,13 @@ export interface UIFieldMetadata {
|
||||||
icon?: string
|
icon?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BaseRelationshipFieldMetadata extends BaseFieldSchema {
|
interface BaseRelationshipFieldMetadata
|
||||||
|
extends Omit<BaseFieldSchema, "subtype"> {
|
||||||
type: FieldType.LINK
|
type: FieldType.LINK
|
||||||
main?: boolean
|
main?: boolean
|
||||||
fieldName?: string
|
fieldName?: string
|
||||||
tableId: string
|
tableId: string
|
||||||
|
subtype?: Omit<AutoFieldSubTypes, AutoFieldSubTypes.AUTO_ID>
|
||||||
}
|
}
|
||||||
export interface ManyToManyRelationshipFieldMetadata
|
export interface ManyToManyRelationshipFieldMetadata
|
||||||
extends BaseRelationshipFieldMetadata {
|
extends BaseRelationshipFieldMetadata {
|
||||||
|
@ -43,7 +45,8 @@ export type RelationshipFieldMetadata =
|
||||||
| OneToManyRelationshipFieldMetadata
|
| OneToManyRelationshipFieldMetadata
|
||||||
| ManyToOneRelationshipFieldMetadata
|
| ManyToOneRelationshipFieldMetadata
|
||||||
|
|
||||||
export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
export interface AutoColumnFieldMetadata
|
||||||
|
extends Omit<BaseFieldSchema, "subtype"> {
|
||||||
type: FieldType.AUTO
|
type: FieldType.AUTO
|
||||||
autocolumn: true
|
autocolumn: true
|
||||||
subtype?: AutoFieldSubTypes
|
subtype?: AutoFieldSubTypes
|
||||||
|
@ -52,7 +55,7 @@ export interface AutoColumnFieldMetadata extends BaseFieldSchema {
|
||||||
autoReason?: AutoReason
|
autoReason?: AutoReason
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NumberFieldMetadata extends BaseFieldSchema {
|
export interface NumberFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
|
||||||
type: FieldType.NUMBER
|
type: FieldType.NUMBER
|
||||||
autocolumn?: boolean
|
autocolumn?: boolean
|
||||||
subtype?: AutoFieldSubTypes.AUTO_ID
|
subtype?: AutoFieldSubTypes.AUTO_ID
|
||||||
|
@ -86,6 +89,12 @@ export interface FormulaFieldMetadata extends BaseFieldSchema {
|
||||||
formulaType?: FormulaTypes
|
formulaType?: FormulaTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BBReferenceFieldMetadata
|
||||||
|
extends Omit<BaseFieldSchema, "subtype"> {
|
||||||
|
type: FieldType.BB_REFERENCE
|
||||||
|
subtype: FieldSubtype.USER
|
||||||
|
}
|
||||||
|
|
||||||
export interface FieldConstraints {
|
export interface FieldConstraints {
|
||||||
type?: string
|
type?: string
|
||||||
email?: boolean
|
email?: boolean
|
||||||
|
@ -118,7 +127,7 @@ interface BaseFieldSchema extends UIFieldMetadata {
|
||||||
constraints?: FieldConstraints
|
constraints?: FieldConstraints
|
||||||
autocolumn?: boolean
|
autocolumn?: boolean
|
||||||
autoReason?: AutoReason.FOREIGN_KEY
|
autoReason?: AutoReason.FOREIGN_KEY
|
||||||
subtype?: string
|
subtype?: never
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OtherFieldMetadata extends BaseFieldSchema {
|
interface OtherFieldMetadata extends BaseFieldSchema {
|
||||||
|
@ -143,6 +152,7 @@ export type FieldSchema =
|
||||||
| FormulaFieldMetadata
|
| FormulaFieldMetadata
|
||||||
| NumberFieldMetadata
|
| NumberFieldMetadata
|
||||||
| LongFormFieldMetadata
|
| LongFormFieldMetadata
|
||||||
|
| BBReferenceFieldMetadata
|
||||||
|
|
||||||
export interface TableSchema {
|
export interface TableSchema {
|
||||||
[key: string]: FieldSchema
|
[key: string]: FieldSchema
|
||||||
|
|
Loading…
Reference in New Issue