1
0
Fork 0
mirror of synced 2024-09-10 06:26:02 +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) $: initialiseField(field, savingColumn)

View file

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

View file

@ -1,9 +1,16 @@
import { Knex, knex } from "knex" 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 { breakExternalTableId } from "../utils"
import SchemaBuilder = Knex.SchemaBuilder import SchemaBuilder = Knex.SchemaBuilder
import CreateTableBuilder = Knex.CreateTableBuilder import CreateTableBuilder = Knex.CreateTableBuilder
import { FieldTypes, RelationshipType } from "../../constants" import { FieldTypes, RelationshipType } from "../../constants"
import { utils } from "@budibase/shared-core"
function generateSchema( function generateSchema(
schema: CreateTableBuilder, schema: CreateTableBuilder,
@ -42,7 +49,17 @@ function generateSchema(
case FieldTypes.LONGFORM: case FieldTypes.LONGFORM:
case FieldTypes.BARCODEQR: case FieldTypes.BARCODEQR:
case FieldTypes.BB_REFERENCE: 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 break
case FieldTypes.NUMBER: case FieldTypes.NUMBER:
// if meta is specified then this is a junction table entry // 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 { FieldSubtype } from "@budibase/types"
import { InvalidBBRefError } from "./errors" import { InvalidBBRefError } from "./errors"
export async function processInputBBReferences( export async function processInputBBReferences<T extends FieldSubtype>(
value: string | string[] | { _id: string } | { _id: string }[], value: string | string[] | { _id: string } | { _id: string }[],
subtype: FieldSubtype subtype: FieldSubtype
): Promise<string | null> { ): Promise<string | string[] | null> {
const referenceIds: string[] = [] const referenceIds: string[] = []
if (Array.isArray(value)) { if (Array.isArray(value)) {
@ -34,6 +34,11 @@ export async function processInputBBReferences(
if (notFoundIds?.length) { if (notFoundIds?.length) {
throw new InvalidBBRefError(notFoundIds[0], FieldSubtype.USER) throw new InvalidBBRefError(notFoundIds[0], FieldSubtype.USER)
} }
if (subtype === FieldSubtype.USERS) {
return referenceIds
}
return referenceIds.join(",") || null return referenceIds.join(",") || null
default: default:
@ -42,15 +47,16 @@ export async function processInputBBReferences(
} }
export async function processOutputBBReferences( export async function processOutputBBReferences(
value: string, value: string | string[],
subtype: FieldSubtype subtype: FieldSubtype
) { ) {
if (typeof value !== "string") { if (value === null || value === undefined) {
// Already processed or nothing to process // Already processed or nothing to process
return value || undefined return value || undefined
} }
const ids = value.split(",").filter(id => !!id) const ids =
typeof value === "string" ? value.split(",").filter(id => !!id) : value
switch (subtype) { switch (subtype) {
case FieldSubtype.USER: case FieldSubtype.USER: