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