Use shared-core
This commit is contained in:
parent
8161dfc0a9
commit
3e32ce4d24
|
@ -13,6 +13,7 @@
|
||||||
Layout,
|
Layout,
|
||||||
AbsTooltip,
|
AbsTooltip,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
|
import { SWITCHABLE_TYPES } from "@budibase/shared-core"
|
||||||
import { createEventDispatcher, getContext, onMount } from "svelte"
|
import { createEventDispatcher, getContext, onMount } from "svelte"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { tables, datasources } from "stores/builder"
|
import { tables, datasources } from "stores/builder"
|
||||||
|
@ -20,11 +21,6 @@
|
||||||
import {
|
import {
|
||||||
FIELDS,
|
FIELDS,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
ALLOWABLE_STRING_OPTIONS,
|
|
||||||
ALLOWABLE_NUMBER_OPTIONS,
|
|
||||||
ALLOWABLE_STRING_TYPES,
|
|
||||||
ALLOWABLE_NUMBER_TYPES,
|
|
||||||
SWITCHABLE_TYPES,
|
|
||||||
PrettyRelationshipDefinitions,
|
PrettyRelationshipDefinitions,
|
||||||
DB_TYPE_EXTERNAL,
|
DB_TYPE_EXTERNAL,
|
||||||
} from "constants/backend"
|
} from "constants/backend"
|
||||||
|
@ -175,7 +171,7 @@
|
||||||
$: typeEnabled =
|
$: typeEnabled =
|
||||||
!originalName ||
|
!originalName ||
|
||||||
(originalName &&
|
(originalName &&
|
||||||
SWITCHABLE_TYPES.indexOf(editableColumn.type) !== -1 &&
|
SWITCHABLE_TYPES[editableColumn.type] &&
|
||||||
!editableColumn?.autocolumn)
|
!editableColumn?.autocolumn)
|
||||||
|
|
||||||
const fieldDefinitions = Object.values(FIELDS).reduce(
|
const fieldDefinitions = Object.values(FIELDS).reduce(
|
||||||
|
@ -367,16 +363,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllowedTypes() {
|
function getAllowedTypes() {
|
||||||
if (
|
if (originalName) {
|
||||||
originalName &&
|
return (
|
||||||
ALLOWABLE_STRING_TYPES.indexOf(editableColumn.type) !== -1
|
SWITCHABLE_TYPES[editableColumn.type] || [editableColumn.type]
|
||||||
) {
|
).map(f => FIELDS[f.toUpperCase()])
|
||||||
return ALLOWABLE_STRING_OPTIONS
|
|
||||||
} else if (
|
|
||||||
originalName &&
|
|
||||||
ALLOWABLE_NUMBER_TYPES.indexOf(editableColumn.type) !== -1
|
|
||||||
) {
|
|
||||||
return ALLOWABLE_NUMBER_OPTIONS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUsers =
|
const isUsers =
|
||||||
|
|
|
@ -202,26 +202,6 @@ export const PrettyRelationshipDefinitions = {
|
||||||
ONE: "One row",
|
ONE: "One row",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ALLOWABLE_STRING_OPTIONS = [
|
|
||||||
FIELDS.STRING,
|
|
||||||
FIELDS.OPTIONS,
|
|
||||||
FIELDS.LONGFORM,
|
|
||||||
FIELDS.BARCODEQR,
|
|
||||||
]
|
|
||||||
export const ALLOWABLE_STRING_TYPES = ALLOWABLE_STRING_OPTIONS.map(
|
|
||||||
opt => opt.type
|
|
||||||
)
|
|
||||||
|
|
||||||
export const ALLOWABLE_NUMBER_OPTIONS = [FIELDS.NUMBER, FIELDS.BOOLEAN]
|
|
||||||
export const ALLOWABLE_NUMBER_TYPES = ALLOWABLE_NUMBER_OPTIONS.map(
|
|
||||||
opt => opt.type
|
|
||||||
)
|
|
||||||
|
|
||||||
export const SWITCHABLE_TYPES = [
|
|
||||||
...ALLOWABLE_STRING_TYPES,
|
|
||||||
...ALLOWABLE_NUMBER_TYPES,
|
|
||||||
]
|
|
||||||
|
|
||||||
export const BUDIBASE_INTERNAL_DB_ID = INTERNAL_TABLE_SOURCE_ID
|
export const BUDIBASE_INTERNAL_DB_ID = INTERNAL_TABLE_SOURCE_ID
|
||||||
export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default"
|
export const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default"
|
||||||
export const BUDIBASE_DATASOURCE_TYPE = "budibase"
|
export const BUDIBASE_DATASOURCE_TYPE = "budibase"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { FieldType } from "@budibase/types"
|
import { FieldType } from "@budibase/types"
|
||||||
|
import { SWITCHABLE_TYPES } from "@budibase/shared-core"
|
||||||
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 } from "constants/backend"
|
|
||||||
|
|
||||||
export function createTablesStore() {
|
export function createTablesStore() {
|
||||||
const store = writable({
|
const store = writable({
|
||||||
|
@ -64,7 +64,7 @@ export function createTablesStore() {
|
||||||
if (
|
if (
|
||||||
oldField != null &&
|
oldField != null &&
|
||||||
oldField?.type !== field.type &&
|
oldField?.type !== field.type &&
|
||||||
SWITCHABLE_TYPES.indexOf(oldField?.type) === -1
|
SWITCHABLE_TYPES[oldField?.type]
|
||||||
) {
|
) {
|
||||||
updatedTable.schema[key] = oldField
|
updatedTable.schema[key] = oldField
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ type SwitchableTypes = Partial<{
|
||||||
[K in FieldType]: [K, ...FieldType[]]
|
[K in FieldType]: [K, ...FieldType[]]
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export const SWITCHABLE_TYPES: Partial<SwitchableTypes> = {
|
export const SWITCHABLE_TYPES: SwitchableTypes = {
|
||||||
[FieldType.STRING]: [
|
[FieldType.STRING]: [
|
||||||
FieldType.STRING,
|
FieldType.STRING,
|
||||||
FieldType.OPTIONS,
|
FieldType.OPTIONS,
|
||||||
|
|
Loading…
Reference in New Issue