Use types
This commit is contained in:
parent
8c8e386d2d
commit
d431f633d3
|
@ -1,3 +1,4 @@
|
||||||
|
import { FieldType } from "@budibase/types"
|
||||||
import { FIELDS } from "constants/backend"
|
import { FIELDS } from "constants/backend"
|
||||||
import { tables } from "stores/builder"
|
import { tables } from "stores/builder"
|
||||||
import { get as svelteGet } from "svelte/store"
|
import { get as svelteGet } from "svelte/store"
|
||||||
|
@ -5,14 +6,12 @@ import { get as svelteGet } from "svelte/store"
|
||||||
// currently supported level of relationship depth (server side)
|
// currently supported level of relationship depth (server side)
|
||||||
const MAX_DEPTH = 1
|
const MAX_DEPTH = 1
|
||||||
|
|
||||||
//https://github.com/Budibase/budibase/issues/3030
|
|
||||||
const internalType = "internal"
|
|
||||||
|
|
||||||
const TYPES_TO_SKIP = [
|
const TYPES_TO_SKIP = [
|
||||||
FIELDS.FORMULA.type,
|
FieldType.FORMULA,
|
||||||
FIELDS.LONGFORM.type,
|
FieldType.LONGFORM,
|
||||||
FIELDS.ATTACHMENT.type,
|
FieldType.ATTACHMENT,
|
||||||
internalType,
|
//https://github.com/Budibase/budibase/issues/3030
|
||||||
|
FieldType.INTERNAL,
|
||||||
]
|
]
|
||||||
|
|
||||||
export function getBindings({
|
export function getBindings({
|
||||||
|
@ -26,7 +25,7 @@ export function getBindings({
|
||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
for (let [column, schema] of Object.entries(table.schema)) {
|
for (let [column, schema] of Object.entries(table.schema)) {
|
||||||
const isRelationship = schema.type === FIELDS.LINK.type
|
const isRelationship = schema.type === FieldType.LINK
|
||||||
// skip relationships after a certain depth and types which
|
// skip relationships after a certain depth and types which
|
||||||
// can't bind to
|
// can't bind to
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -12,7 +12,7 @@ const getDefaultSchema = rows => {
|
||||||
newSchema[column] = {
|
newSchema[column] = {
|
||||||
name: column,
|
name: column,
|
||||||
type: "string",
|
type: "string",
|
||||||
constraints: FIELDS["STRING"].constraints,
|
constraints: FIELDS.STRING.constraints,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import { FIELDS } from "constants/backend"
|
import { FieldType } from "@budibase/types"
|
||||||
|
|
||||||
function baseConversion(type) {
|
function baseConversion(type) {
|
||||||
if (type === "string") {
|
if (type === "string") {
|
||||||
return {
|
return {
|
||||||
type: FIELDS.STRING.type,
|
type: FieldType.STRING,
|
||||||
}
|
}
|
||||||
} else if (type === "boolean") {
|
} else if (type === "boolean") {
|
||||||
return {
|
return {
|
||||||
type: FIELDS.BOOLEAN.type,
|
type: FieldType.BOOLEAN,
|
||||||
}
|
}
|
||||||
} else if (type === "number") {
|
} else if (type === "number") {
|
||||||
return {
|
return {
|
||||||
type: FIELDS.NUMBER.type,
|
type: FieldType.NUMBER,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ function recurse(schemaLevel = {}, objectLevel) {
|
||||||
const schema = recurse(schemaLevel[key], value[0])
|
const schema = recurse(schemaLevel[key], value[0])
|
||||||
if (schema) {
|
if (schema) {
|
||||||
schemaLevel[key] = {
|
schemaLevel[key] = {
|
||||||
type: FIELDS.ARRAY.type,
|
type: FieldType.ARRAY,
|
||||||
schema,
|
schema,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ function recurse(schemaLevel = {}, objectLevel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!schemaLevel.type) {
|
if (!schemaLevel.type) {
|
||||||
return { type: FIELDS.JSON.type, schema: schemaLevel }
|
return { type: FieldType.JSON, schema: schemaLevel }
|
||||||
} else {
|
} else {
|
||||||
return schemaLevel
|
return schemaLevel
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { FieldType } from "@budibase/types"
|
||||||
import { ActionStepID } from "constants/backend/automations"
|
import { ActionStepID } from "constants/backend/automations"
|
||||||
import { TableNames } from "constants"
|
import { TableNames } from "constants"
|
||||||
import {
|
import {
|
||||||
|
@ -20,20 +21,20 @@ export function buildAutoColumn(tableName, name, subtype) {
|
||||||
switch (subtype) {
|
switch (subtype) {
|
||||||
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY:
|
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY:
|
||||||
case AUTO_COLUMN_SUB_TYPES.CREATED_BY:
|
case AUTO_COLUMN_SUB_TYPES.CREATED_BY:
|
||||||
type = FIELDS.LINK.type
|
type = FieldType.LINK
|
||||||
constraints = FIELDS.LINK.constraints
|
constraints = FIELDS.LINK.constraints
|
||||||
break
|
break
|
||||||
case AUTO_COLUMN_SUB_TYPES.AUTO_ID:
|
case AUTO_COLUMN_SUB_TYPES.AUTO_ID:
|
||||||
type = FIELDS.NUMBER.type
|
type = FieldType.NUMBER
|
||||||
constraints = FIELDS.NUMBER.constraints
|
constraints = FIELDS.NUMBER.constraints
|
||||||
break
|
break
|
||||||
case AUTO_COLUMN_SUB_TYPES.UPDATED_AT:
|
case AUTO_COLUMN_SUB_TYPES.UPDATED_AT:
|
||||||
case AUTO_COLUMN_SUB_TYPES.CREATED_AT:
|
case AUTO_COLUMN_SUB_TYPES.CREATED_AT:
|
||||||
type = FIELDS.DATETIME.type
|
type = FieldType.DATETIME
|
||||||
constraints = FIELDS.DATETIME.constraints
|
constraints = FIELDS.DATETIME.constraints
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
type = FIELDS.STRING.type
|
type = FieldType.STRING
|
||||||
constraints = FIELDS.STRING.constraints
|
constraints = FIELDS.STRING.constraints
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { FieldType } from "@budibase/types"
|
||||||
import { get, writable, derived } from "svelte/store"
|
import { get, writable, derived } from "svelte/store"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import { SWITCHABLE_TYPES, FIELDS } from "constants/backend"
|
import { SWITCHABLE_TYPES } from "constants/backend"
|
||||||
|
|
||||||
export function createTablesStore() {
|
export function createTablesStore() {
|
||||||
const store = writable({
|
const store = writable({
|
||||||
|
@ -83,14 +84,14 @@ export function createTablesStore() {
|
||||||
// make sure tables up to date (related)
|
// make sure tables up to date (related)
|
||||||
let newTableIds = []
|
let newTableIds = []
|
||||||
for (let column of Object.values(updatedTable?.schema || {})) {
|
for (let column of Object.values(updatedTable?.schema || {})) {
|
||||||
if (column.type === FIELDS.LINK.type) {
|
if (column.type === FieldType.LINK) {
|
||||||
newTableIds.push(column.tableId)
|
newTableIds.push(column.tableId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let oldTableIds = []
|
let oldTableIds = []
|
||||||
for (let column of Object.values(oldTable?.schema || {})) {
|
for (let column of Object.values(oldTable?.schema || {})) {
|
||||||
if (column.type === FIELDS.LINK.type) {
|
if (column.type === FieldType.LINK) {
|
||||||
oldTableIds.push(column.tableId)
|
oldTableIds.push(column.tableId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue