DRY
This commit is contained in:
parent
9ae1928e55
commit
95faefcb87
|
@ -13,7 +13,11 @@
|
|||
Layout,
|
||||
AbsTooltip,
|
||||
} 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 { cloneDeep } from "lodash/fp"
|
||||
import { tables, datasources } from "stores/builder"
|
||||
|
@ -361,11 +365,7 @@
|
|||
function getAllowedTypes(datasource) {
|
||||
if (originalName) {
|
||||
let possibleTypes = SWITCHABLE_TYPES[field.type] || [editableColumn.type]
|
||||
if (
|
||||
editableColumn.type === FieldType.BB_REFERENCE &&
|
||||
editableColumn.subtype === BBReferenceFieldSubType.USER &&
|
||||
editableColumn.constraints?.type !== "array"
|
||||
) {
|
||||
if (helpers.schema.isDeprecatedSingleUserColumn(editableColumn)) {
|
||||
// This will handle old single users columns
|
||||
return [
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<script>
|
||||
import { getContext } from "svelte"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
import RelationshipCell from "./RelationshipCell.svelte"
|
||||
import {
|
||||
BBReferenceFieldSubType,
|
||||
|
@ -12,26 +13,17 @@
|
|||
export let schema
|
||||
|
||||
const { API } = getContext("grid")
|
||||
const { type, subtype, constraints } = 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
|
||||
}
|
||||
}
|
||||
const { type, subtype } = schema
|
||||
|
||||
$: schema = {
|
||||
...$$props.schema,
|
||||
// This is not really used, just adding some content to be able to render the relationship cell
|
||||
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) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BBReferenceFieldSubType, FieldType } from "@budibase/types"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
import { TypeIconMap } from "../../../constants"
|
||||
|
||||
export const getColor = (idx, opacity = 0.3) => {
|
||||
|
@ -13,16 +13,11 @@ export const getColumnIcon = column => {
|
|||
return "MagicWand"
|
||||
}
|
||||
|
||||
const { type, subtype, constraints } = column.schema
|
||||
if (
|
||||
type === FieldType.BB_REFERENCE &&
|
||||
subtype === BBReferenceFieldSubType.USER &&
|
||||
constraints?.type !== "array"
|
||||
) {
|
||||
// This will handle old single users columns
|
||||
if (helpers.schema.isDeprecatedSingleUserColumn(column.schema)) {
|
||||
return "User"
|
||||
}
|
||||
|
||||
const { type, subtype } = column.schema
|
||||
const result =
|
||||
typeof TypeIconMap[type] === "object" && subtype
|
||||
? TypeIconMap[type][subtype]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// 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 { CONSTANT_INTERNAL_ROW_COLS } from "../../../../db/utils"
|
||||
|
||||
|
@ -111,12 +112,7 @@ export function fixArrayTypes(row: Row, table: Table) {
|
|||
try {
|
||||
row[fieldName] = JSON.parse(row[fieldName])
|
||||
} catch (err) {
|
||||
// Handling deprecated single user type
|
||||
const isDeprecatedSingleUser =
|
||||
schema.type === FieldType.BB_REFERENCE &&
|
||||
schema.subtype === BBReferenceFieldSubType.USER &&
|
||||
schema.constraints?.type !== "array"
|
||||
if (!isDeprecatedSingleUser) {
|
||||
if (!helpers.schema.isDeprecatedSingleUserColumn(schema)) {
|
||||
// couldn't convert back to array, ignore
|
||||
delete row[fieldName]
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./helpers"
|
||||
export * from "./integrations"
|
||||
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