DRY
This commit is contained in:
parent
9ae1928e55
commit
95faefcb87
|
@ -13,7 +13,11 @@
|
||||||
Layout,
|
Layout,
|
||||||
AbsTooltip,
|
AbsTooltip,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { SWITCHABLE_TYPES, ValidColumnNameRegex } from "@budibase/shared-core"
|
import {
|
||||||
|
SWITCHABLE_TYPES,
|
||||||
|
ValidColumnNameRegex,
|
||||||
|
helpers,
|
||||||
|
} 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"
|
||||||
|
@ -361,11 +365,7 @@
|
||||||
function getAllowedTypes(datasource) {
|
function getAllowedTypes(datasource) {
|
||||||
if (originalName) {
|
if (originalName) {
|
||||||
let possibleTypes = SWITCHABLE_TYPES[field.type] || [editableColumn.type]
|
let possibleTypes = SWITCHABLE_TYPES[field.type] || [editableColumn.type]
|
||||||
if (
|
if (helpers.schema.isDeprecatedSingleUserColumn(editableColumn)) {
|
||||||
editableColumn.type === FieldType.BB_REFERENCE &&
|
|
||||||
editableColumn.subtype === BBReferenceFieldSubType.USER &&
|
|
||||||
editableColumn.constraints?.type !== "array"
|
|
||||||
) {
|
|
||||||
// This will handle old single users columns
|
// This will handle old single users columns
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
import RelationshipCell from "./RelationshipCell.svelte"
|
import RelationshipCell from "./RelationshipCell.svelte"
|
||||||
import {
|
import {
|
||||||
BBReferenceFieldSubType,
|
BBReferenceFieldSubType,
|
||||||
|
@ -12,26 +13,17 @@
|
||||||
export let schema
|
export let schema
|
||||||
|
|
||||||
const { API } = getContext("grid")
|
const { API } = getContext("grid")
|
||||||
const { type, subtype, constraints } = schema
|
const { type, subtype } = schema
|
||||||
|
|
||||||
let relationshipType
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if (
|
|
||||||
type === FieldType.BB_REFERENCE_SINGLE ||
|
|
||||||
constraints?.type !== "array" // Handle deprecated "single" user references
|
|
||||||
) {
|
|
||||||
relationshipType = RelationshipType.ONE_TO_MANY
|
|
||||||
} else {
|
|
||||||
relationshipType = RelationshipType.MANY_TO_MANY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$: schema = {
|
$: schema = {
|
||||||
...$$props.schema,
|
...$$props.schema,
|
||||||
// This is not really used, just adding some content to be able to render the relationship cell
|
// This is not really used, just adding some content to be able to render the relationship cell
|
||||||
tableId: "external",
|
tableId: "external",
|
||||||
relationshipType,
|
relationshipType:
|
||||||
|
type === FieldType.BB_REFERENCE_SINGLE ||
|
||||||
|
helpers.schema.isDeprecatedSingleUserColumn(schema)
|
||||||
|
? RelationshipType.ONE_TO_MANY
|
||||||
|
: RelationshipType.MANY_TO_MANY,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchFunction(searchParams) {
|
async function searchFunction(searchParams) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { BBReferenceFieldSubType, FieldType } from "@budibase/types"
|
import { helpers } from "@budibase/shared-core"
|
||||||
import { TypeIconMap } from "../../../constants"
|
import { TypeIconMap } from "../../../constants"
|
||||||
|
|
||||||
export const getColor = (idx, opacity = 0.3) => {
|
export const getColor = (idx, opacity = 0.3) => {
|
||||||
|
@ -13,16 +13,11 @@ export const getColumnIcon = column => {
|
||||||
return "MagicWand"
|
return "MagicWand"
|
||||||
}
|
}
|
||||||
|
|
||||||
const { type, subtype, constraints } = column.schema
|
if (helpers.schema.isDeprecatedSingleUserColumn(column.schema)) {
|
||||||
if (
|
|
||||||
type === FieldType.BB_REFERENCE &&
|
|
||||||
subtype === BBReferenceFieldSubType.USER &&
|
|
||||||
constraints?.type !== "array"
|
|
||||||
) {
|
|
||||||
// This will handle old single users columns
|
|
||||||
return "User"
|
return "User"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { type, subtype } = column.schema
|
||||||
const result =
|
const result =
|
||||||
typeof TypeIconMap[type] === "object" && subtype
|
typeof TypeIconMap[type] === "object" && subtype
|
||||||
? TypeIconMap[type][subtype]
|
? TypeIconMap[type][subtype]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// need to handle table name + field or just field, depending on if relationships used
|
// need to handle table name + field or just field, depending on if relationships used
|
||||||
import { BBReferenceFieldSubType, FieldType, Row, Table } from "@budibase/types"
|
import { FieldType, Row, Table } from "@budibase/types"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
import { generateRowIdField } from "../../../../integrations/utils"
|
import { generateRowIdField } from "../../../../integrations/utils"
|
||||||
import { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils"
|
import { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils"
|
||||||
|
|
||||||
|
@ -111,12 +112,7 @@ export function fixArrayTypes(row: Row, table: Table) {
|
||||||
try {
|
try {
|
||||||
row[fieldName] = JSON.parse(row[fieldName])
|
row[fieldName] = JSON.parse(row[fieldName])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Handling deprecated single user type
|
if (!helpers.schema.isDeprecatedSingleUserColumn(schema)) {
|
||||||
const isDeprecatedSingleUser =
|
|
||||||
schema.type === FieldType.BB_REFERENCE &&
|
|
||||||
schema.subtype === BBReferenceFieldSubType.USER &&
|
|
||||||
schema.constraints?.type !== "array"
|
|
||||||
if (!isDeprecatedSingleUser) {
|
|
||||||
// couldn't convert back to array, ignore
|
// couldn't convert back to array, ignore
|
||||||
delete row[fieldName]
|
delete row[fieldName]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export * from "./helpers"
|
export * from "./helpers"
|
||||||
export * from "./integrations"
|
export * from "./integrations"
|
||||||
export * as cron from "./cron"
|
export * as cron from "./cron"
|
||||||
|
export * as schema from "./schema"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {
|
||||||
|
BBReferenceFieldSubType,
|
||||||
|
FieldSchema,
|
||||||
|
FieldType,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
|
export function isDeprecatedSingleUserColumn(schema: FieldSchema) {
|
||||||
|
const result =
|
||||||
|
schema.type === FieldType.BB_REFERENCE &&
|
||||||
|
schema.subtype === BBReferenceFieldSubType.USER &&
|
||||||
|
schema.constraints?.type !== "array"
|
||||||
|
return result
|
||||||
|
}
|
Loading…
Reference in New Issue