Fix data between old and new
This commit is contained in:
parent
457eebbcb4
commit
9a6e6ed115
|
@ -1,22 +1,35 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import RelationshipCell from "./RelationshipCell.svelte"
|
import RelationshipCell from "./RelationshipCell.svelte"
|
||||||
import { BBReferenceFieldSubType, RelationshipType } from "@budibase/types"
|
import {
|
||||||
|
BBReferenceFieldSubType,
|
||||||
|
FieldType,
|
||||||
|
RelationshipType,
|
||||||
|
} from "@budibase/types"
|
||||||
|
|
||||||
export let api
|
export let api
|
||||||
export let hideCounter = false
|
export let hideCounter = false
|
||||||
|
|
||||||
const { API } = getContext("grid")
|
const { API } = getContext("grid")
|
||||||
const { subtype } = $$props.schema
|
const { type, subtype, constraints } = $$props.schema
|
||||||
|
|
||||||
const schema = {
|
let relationshipType
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (type === FieldType.BB_REFERENCE_SINGLE) {
|
||||||
|
relationshipType = RelationshipType.ONE_TO_MANY
|
||||||
|
} else if (constraints?.type === "array") {
|
||||||
|
relationshipType = RelationshipType.MANY_TO_MANY
|
||||||
|
} else {
|
||||||
|
relationshipType = RelationshipType.ONE_TO_MANY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: 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,
|
||||||
subtype === BBReferenceFieldSubType.USER
|
|
||||||
? RelationshipType.ONE_TO_MANY
|
|
||||||
: RelationshipType.MANY_TO_MANY,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchFunction(searchParams) {
|
async function searchFunction(searchParams) {
|
||||||
|
|
|
@ -765,9 +765,7 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
||||||
field: FieldSchema
|
field: FieldSchema
|
||||||
): field is JsonFieldMetadata | BBReferenceFieldMetadata {
|
): field is JsonFieldMetadata | BBReferenceFieldMetadata {
|
||||||
return (
|
return (
|
||||||
field.type === FieldType.JSON ||
|
field.type === FieldType.JSON || field.type === FieldType.BB_REFERENCE
|
||||||
(field.type === FieldType.BB_REFERENCE &&
|
|
||||||
field.subtype === BBReferenceFieldSubType.USERS)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,20 +63,6 @@ function generateSchema(
|
||||||
case FieldType.BB_REFERENCE_SINGLE:
|
case FieldType.BB_REFERENCE_SINGLE:
|
||||||
schema.text(key)
|
schema.text(key)
|
||||||
break
|
break
|
||||||
case FieldType.BB_REFERENCE: {
|
|
||||||
const subtype = column.subtype
|
|
||||||
switch (subtype) {
|
|
||||||
case BBReferenceFieldSubType.USER:
|
|
||||||
schema.text(key)
|
|
||||||
break
|
|
||||||
case BBReferenceFieldSubType.USERS:
|
|
||||||
schema.json(key)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw utils.unreachable(subtype)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case FieldType.NUMBER:
|
case FieldType.NUMBER:
|
||||||
// if meta is specified then this is a junction table entry
|
// if meta is specified then this is a junction table entry
|
||||||
if (column.meta && column.meta.toKey && column.meta.toTable) {
|
if (column.meta && column.meta.toKey && column.meta.toTable) {
|
||||||
|
@ -99,6 +85,7 @@ function generateSchema(
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case FieldType.ARRAY:
|
case FieldType.ARRAY:
|
||||||
|
case FieldType.BB_REFERENCE:
|
||||||
schema.json(key)
|
schema.json(key)
|
||||||
break
|
break
|
||||||
case FieldType.LINK:
|
case FieldType.LINK:
|
||||||
|
|
|
@ -99,15 +99,7 @@ export function searchInputMapping(table: Table, options: RowSearchParams) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case FieldType.BB_REFERENCE: {
|
case FieldType.BB_REFERENCE: {
|
||||||
const subtype = column.subtype
|
userColumnMapping(key, options)
|
||||||
switch (subtype) {
|
|
||||||
case BBReferenceFieldSubType.USER:
|
|
||||||
case BBReferenceFieldSubType.USERS:
|
|
||||||
userColumnMapping(key, options)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
utils.unreachable(subtype)
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,21 +140,9 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
|
||||||
: columnData
|
: columnData
|
||||||
} else if (columnType === FieldType.BB_REFERENCE) {
|
} else if (columnType === FieldType.BB_REFERENCE) {
|
||||||
const parsedValues =
|
const parsedValues =
|
||||||
!!columnData && parseCsvExport<{ _id: string }[]>(columnData)
|
(!!columnData && parseCsvExport<{ _id: string }[]>(columnData)) || []
|
||||||
if (!parsedValues) {
|
|
||||||
parsedRow[columnName] = undefined
|
parsedRow[columnName] = parsedValues?.map(u => u._id)
|
||||||
} else {
|
|
||||||
switch (columnSubtype) {
|
|
||||||
case BBReferenceFieldSubType.USER:
|
|
||||||
parsedRow[columnName] = parsedValues[0]?._id
|
|
||||||
break
|
|
||||||
case BBReferenceFieldSubType.USERS:
|
|
||||||
parsedRow[columnName] = parsedValues.map(u => u._id)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
utils.unreachable(columnSubtype)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (columnType === FieldType.BB_REFERENCE_SINGLE) {
|
} else if (columnType === FieldType.BB_REFERENCE_SINGLE) {
|
||||||
const parsedValue =
|
const parsedValue =
|
||||||
columnData && parseCsvExport<{ _id: string }>(columnData)
|
columnData && parseCsvExport<{ _id: string }>(columnData)
|
||||||
|
|
|
@ -68,16 +68,9 @@ export const getValidOperatorsForType = (
|
||||||
ops = numOps
|
ops = numOps
|
||||||
} else if (type === FieldType.FORMULA && formulaType === FormulaType.STATIC) {
|
} else if (type === FieldType.FORMULA && formulaType === FormulaType.STATIC) {
|
||||||
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
||||||
} else if (
|
} else if (type === FieldType.BB_REFERENCE_SINGLE) {
|
||||||
(type === FieldType.BB_REFERENCE_SINGLE ||
|
|
||||||
type === FieldType.BB_REFERENCE) &&
|
|
||||||
subtype == BBReferenceFieldSubType.USER
|
|
||||||
) {
|
|
||||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
||||||
} else if (
|
} else if (type === FieldType.BB_REFERENCE) {
|
||||||
type === FieldType.BB_REFERENCE &&
|
|
||||||
subtype == BBReferenceFieldSubType.USERS
|
|
||||||
) {
|
|
||||||
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue