Fixing #4192 - allowing switching between JSON and multi-select types, as well as not switching multi-select to JSON when fetching SQL tables.
This commit is contained in:
parent
95e0c1aa1f
commit
9b55ba8b13
|
@ -22,8 +22,10 @@
|
||||||
RelationshipTypes,
|
RelationshipTypes,
|
||||||
ALLOWABLE_STRING_OPTIONS,
|
ALLOWABLE_STRING_OPTIONS,
|
||||||
ALLOWABLE_NUMBER_OPTIONS,
|
ALLOWABLE_NUMBER_OPTIONS,
|
||||||
|
ALLOWABLE_JSON_OPTIONS,
|
||||||
ALLOWABLE_STRING_TYPES,
|
ALLOWABLE_STRING_TYPES,
|
||||||
ALLOWABLE_NUMBER_TYPES,
|
ALLOWABLE_NUMBER_TYPES,
|
||||||
|
ALLOWABLE_JSON_TYPES,
|
||||||
SWITCHABLE_TYPES,
|
SWITCHABLE_TYPES,
|
||||||
} from "constants/backend"
|
} from "constants/backend"
|
||||||
import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils"
|
import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils"
|
||||||
|
@ -236,6 +238,11 @@
|
||||||
ALLOWABLE_NUMBER_TYPES.indexOf(field.type) !== -1
|
ALLOWABLE_NUMBER_TYPES.indexOf(field.type) !== -1
|
||||||
) {
|
) {
|
||||||
return ALLOWABLE_NUMBER_OPTIONS
|
return ALLOWABLE_NUMBER_OPTIONS
|
||||||
|
} else if (
|
||||||
|
originalName &&
|
||||||
|
ALLOWABLE_JSON_TYPES.indexOf(field.type) !== -1
|
||||||
|
) {
|
||||||
|
return ALLOWABLE_JSON_OPTIONS
|
||||||
} else if (!external) {
|
} else if (!external) {
|
||||||
return [
|
return [
|
||||||
...Object.values(fieldDefinitions),
|
...Object.values(fieldDefinitions),
|
||||||
|
|
|
@ -148,20 +148,23 @@ export const RelationshipTypes = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ALLOWABLE_STRING_OPTIONS = [FIELDS.STRING, FIELDS.OPTIONS]
|
export const ALLOWABLE_STRING_OPTIONS = [FIELDS.STRING, FIELDS.OPTIONS]
|
||||||
|
|
||||||
export const ALLOWABLE_STRING_TYPES = ALLOWABLE_STRING_OPTIONS.map(
|
export const ALLOWABLE_STRING_TYPES = ALLOWABLE_STRING_OPTIONS.map(
|
||||||
opt => opt.type
|
opt => opt.type
|
||||||
)
|
)
|
||||||
|
|
||||||
export const ALLOWABLE_NUMBER_OPTIONS = [FIELDS.NUMBER, FIELDS.BOOLEAN]
|
export const ALLOWABLE_NUMBER_OPTIONS = [FIELDS.NUMBER, FIELDS.BOOLEAN]
|
||||||
|
|
||||||
export const ALLOWABLE_NUMBER_TYPES = ALLOWABLE_NUMBER_OPTIONS.map(
|
export const ALLOWABLE_NUMBER_TYPES = ALLOWABLE_NUMBER_OPTIONS.map(
|
||||||
opt => opt.type
|
opt => opt.type
|
||||||
)
|
)
|
||||||
|
|
||||||
export const SWITCHABLE_TYPES = ALLOWABLE_NUMBER_TYPES.concat(
|
export const ALLOWABLE_JSON_OPTIONS = [FIELDS.JSON, FIELDS.ARRAY]
|
||||||
ALLOWABLE_STRING_TYPES
|
export const ALLOWABLE_JSON_TYPES = ALLOWABLE_JSON_OPTIONS.map(opt => opt.type)
|
||||||
)
|
|
||||||
|
export const SWITCHABLE_TYPES = [
|
||||||
|
...ALLOWABLE_STRING_TYPES,
|
||||||
|
...ALLOWABLE_NUMBER_TYPES,
|
||||||
|
...ALLOWABLE_JSON_TYPES,
|
||||||
|
]
|
||||||
|
|
||||||
export const IntegrationTypes = {
|
export const IntegrationTypes = {
|
||||||
POSTGRES: "POSTGRES",
|
POSTGRES: "POSTGRES",
|
||||||
|
|
|
@ -8,7 +8,11 @@ const {
|
||||||
const { isEqual } = require("lodash/fp")
|
const { isEqual } = require("lodash/fp")
|
||||||
const { AutoFieldSubTypes, FieldTypes } = require("../../../constants")
|
const { AutoFieldSubTypes, FieldTypes } = require("../../../constants")
|
||||||
const { inputProcessing } = require("../../../utilities/rowProcessor")
|
const { inputProcessing } = require("../../../utilities/rowProcessor")
|
||||||
const { USERS_TABLE_SCHEMA, SwitchableTypes } = require("../../../constants")
|
const {
|
||||||
|
USERS_TABLE_SCHEMA,
|
||||||
|
SwitchableTypes,
|
||||||
|
CanSwitchTypes,
|
||||||
|
} = require("../../../constants")
|
||||||
const {
|
const {
|
||||||
isExternalTable,
|
isExternalTable,
|
||||||
breakExternalTableId,
|
breakExternalTableId,
|
||||||
|
@ -340,6 +344,23 @@ exports.foreignKeyStructure = (keyName, meta = null) => {
|
||||||
return structure
|
return structure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.areSwitchableTypes = (type1, type2) => {
|
||||||
|
if (
|
||||||
|
SwitchableTypes.indexOf(type1) === -1 &&
|
||||||
|
SwitchableTypes.indexOf(type2) === -1
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for (let option of CanSwitchTypes) {
|
||||||
|
const index1 = option.indexOf(type1),
|
||||||
|
index2 = option.indexOf(type2)
|
||||||
|
if (index1 !== -1 && index2 !== -1 && index1 !== index2) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
exports.hasTypeChanged = (table, oldTable) => {
|
exports.hasTypeChanged = (table, oldTable) => {
|
||||||
if (!oldTable) {
|
if (!oldTable) {
|
||||||
return false
|
return false
|
||||||
|
@ -350,7 +371,7 @@ exports.hasTypeChanged = (table, oldTable) => {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const newType = table.schema[key].type
|
const newType = table.schema[key].type
|
||||||
if (oldType !== newType && SwitchableTypes.indexOf(oldType) === -1) {
|
if (oldType !== newType && !exports.areSwitchableTypes(oldType, newType)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,13 +45,16 @@ exports.FieldTypes = {
|
||||||
INTERNAL: "internal",
|
INTERNAL: "internal",
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.SwitchableTypes = [
|
exports.CanSwitchTypes = [
|
||||||
exports.FieldTypes.STRING,
|
[exports.FieldTypes.JSON, exports.FieldTypes.ARRAY],
|
||||||
exports.FieldTypes.OPTIONS,
|
[exports.FieldTypes.STRING, exports.FieldTypes.OPTIONS],
|
||||||
exports.FieldTypes.NUMBER,
|
[exports.FieldTypes.BOOLEAN, exports.FieldTypes.NUMBER],
|
||||||
exports.FieldTypes.BOOLEAN,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
exports.SwitchableTypes = exports.CanSwitchTypes.reduce((prev, current) =>
|
||||||
|
prev ? prev.concat(current) : current
|
||||||
|
)
|
||||||
|
|
||||||
exports.RelationshipTypes = {
|
exports.RelationshipTypes = {
|
||||||
ONE_TO_MANY: "one-to-many",
|
ONE_TO_MANY: "one-to-many",
|
||||||
MANY_TO_ONE: "many-to-one",
|
MANY_TO_ONE: "many-to-one",
|
||||||
|
|
|
@ -157,6 +157,7 @@ function copyExistingPropsOver(
|
||||||
if (
|
if (
|
||||||
existingTableSchema[key].type === FieldTypes.LINK ||
|
existingTableSchema[key].type === FieldTypes.LINK ||
|
||||||
existingTableSchema[key].type === FieldTypes.OPTIONS ||
|
existingTableSchema[key].type === FieldTypes.OPTIONS ||
|
||||||
|
existingTableSchema[key].type === FieldTypes.ARRAY ||
|
||||||
((!table.schema[key] || table.schema[key].type === FieldTypes.NUMBER) &&
|
((!table.schema[key] || table.schema[key].type === FieldTypes.NUMBER) &&
|
||||||
existingTableSchema[key].type === FieldTypes.BOOLEAN)
|
existingTableSchema[key].type === FieldTypes.BOOLEAN)
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in New Issue