1
0
Fork 0
mirror of synced 2024-08-07 22:28:15 +12:00

Multiple users column

This commit is contained in:
Adria Navarro 2023-10-04 16:50:05 +02:00
parent 753cb442c2
commit 46b85ac12c
4 changed files with 36 additions and 8 deletions

View file

@ -188,7 +188,9 @@
)
}
allowedTypes = getAllowedTypes()
if (!savingColumn) {
allowedTypes = getAllowedTypes()
}
}
$: initialiseField(field, savingColumn)

View file

@ -133,6 +133,9 @@ export const FIELDS = {
type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS,
icon: "User",
constraints: {
type: "array",
},
},
}

View file

@ -1,9 +1,16 @@
import { Knex, knex } from "knex"
import { Operation, QueryJson, RenameColumn, Table } from "@budibase/types"
import {
FieldSubtype,
Operation,
QueryJson,
RenameColumn,
Table,
} from "@budibase/types"
import { breakExternalTableId } from "../utils"
import SchemaBuilder = Knex.SchemaBuilder
import CreateTableBuilder = Knex.CreateTableBuilder
import { FieldTypes, RelationshipType } from "../../constants"
import { utils } from "@budibase/shared-core"
function generateSchema(
schema: CreateTableBuilder,
@ -42,7 +49,17 @@ function generateSchema(
case FieldTypes.LONGFORM:
case FieldTypes.BARCODEQR:
case FieldTypes.BB_REFERENCE:
schema.text(key)
const subtype = column.subtype as FieldSubtype
switch (subtype) {
case FieldSubtype.USER:
schema.text(key)
break
case FieldSubtype.USERS:
schema.json(key)
break
default:
throw utils.unreachable(subtype)
}
break
case FieldTypes.NUMBER:
// if meta is specified then this is a junction table entry

View file

@ -3,10 +3,10 @@ import { utils } from "@budibase/shared-core"
import { FieldSubtype } from "@budibase/types"
import { InvalidBBRefError } from "./errors"
export async function processInputBBReferences(
export async function processInputBBReferences<T extends FieldSubtype>(
value: string | string[] | { _id: string } | { _id: string }[],
subtype: FieldSubtype
): Promise<string | null> {
): Promise<string | string[] | null> {
const referenceIds: string[] = []
if (Array.isArray(value)) {
@ -34,6 +34,11 @@ export async function processInputBBReferences(
if (notFoundIds?.length) {
throw new InvalidBBRefError(notFoundIds[0], FieldSubtype.USER)
}
if (subtype === FieldSubtype.USERS) {
return referenceIds
}
return referenceIds.join(",") || null
default:
@ -42,15 +47,16 @@ export async function processInputBBReferences(
}
export async function processOutputBBReferences(
value: string,
value: string | string[],
subtype: FieldSubtype
) {
if (typeof value !== "string") {
if (value === null || value === undefined) {
// Already processed or nothing to process
return value || undefined
}
const ids = value.split(",").filter(id => !!id)
const ids =
typeof value === "string" ? value.split(",").filter(id => !!id) : value
switch (subtype) {
case FieldSubtype.USER: