Merge branch 'master' into budi-8123/single-user-column-type

This commit is contained in:
Adria Navarro 2024-04-26 12:47:35 +02:00
commit d45aa9beaf
23 changed files with 128 additions and 106 deletions

View File

@ -1,5 +1,5 @@
<script> <script>
import { FieldType, FieldSubtype } from "@budibase/types" import { FieldType, BBReferenceFieldSubType } from "@budibase/types"
import { Select, Toggle, Multiselect } from "@budibase/bbui" import { Select, Toggle, Multiselect } from "@budibase/bbui"
import { DB_TYPE_INTERNAL } from "constants/backend" import { DB_TYPE_INTERNAL } from "constants/backend"
import { API } from "api" import { API } from "api"
@ -60,15 +60,15 @@
}, },
{ {
label: "User", label: "User",
value: `${FieldType.BB_REFERENCE}${FieldSubtype.USER}`, value: `${FieldType.BB_REFERENCE}${BBReferenceFieldSubType.USER}`,
}, },
{ {
label: "Users", label: "Users",
value: `${FieldType.BB_REFERENCE}${FieldSubtype.USERS}`, value: `${FieldType.BB_REFERENCE}${BBReferenceFieldSubType.USERS}`,
}, },
{ {
label: "User", label: "User",
value: `${FieldType.BB_REFERENCE_SINGLE}${FieldSubtype.USER}`, value: `${FieldType.BB_REFERENCE_SINGLE}${BBReferenceFieldSubType.USER}`,
}, },
] ]

View File

@ -1,6 +1,6 @@
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
AutoFieldSubType, AutoFieldSubType,
Hosting, Hosting,
@ -160,21 +160,25 @@ export const FIELDS = {
USER: { USER: {
name: "User", name: "User",
type: FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE_SINGLE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
icon: TypeIconMap[FieldType.BB_REFERENCE_SINGLE][FieldSubtype.USER], icon: TypeIconMap[FieldType.BB_REFERENCE_SINGLE][
BBReferenceFieldSubType.USER
],
}, },
// Used for display of editing existing columns // Used for display of editing existing columns
OLD_USER: { OLD_USER: {
name: "User", name: "User",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
icon: TypeIconMap[FieldType.BB_REFERENCE_SINGLE][FieldSubtype.USER], icon: TypeIconMap[FieldType.BB_REFERENCE_SINGLE][
BBReferenceFieldSubType.USER
],
}, },
USERS: { USERS: {
name: "User List", name: "User List",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
icon: TypeIconMap[FieldType.BB_REFERENCE][FieldSubtype.USERS], icon: TypeIconMap[FieldType.BB_REFERENCE][BBReferenceFieldSubType.USERS],
constraints: { constraints: {
type: "array", type: "array",
}, },

View File

@ -1,7 +1,7 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import RelationshipCell from "./RelationshipCell.svelte" import RelationshipCell from "./RelationshipCell.svelte"
import { FieldSubtype, RelationshipType } from "@budibase/types" import { BBReferenceFieldSubType, RelationshipType } from "@budibase/types"
export let api export let api
export let hideCounter = false export let hideCounter = false
@ -14,13 +14,16 @@
// 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 === FieldSubtype.USER subtype === BBReferenceFieldSubType.USER
? RelationshipType.ONE_TO_MANY ? RelationshipType.ONE_TO_MANY
: RelationshipType.MANY_TO_MANY, : RelationshipType.MANY_TO_MANY,
} }
async function searchFunction(searchParams) { async function searchFunction(searchParams) {
if (subtype !== FieldSubtype.USER && subtype !== FieldSubtype.USERS) { if (
subtype !== BBReferenceFieldSubType.USER &&
subtype !== BBReferenceFieldSubType.USERS
) {
throw `Search for '${subtype}' not implemented` throw `Search for '${subtype}' not implemented`
} }

View File

@ -7,7 +7,11 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { getContext } from "svelte" import { getContext } from "svelte"
import { ValidColumnNameRegex } from "@budibase/shared-core" import { ValidColumnNameRegex } from "@budibase/shared-core"
import { FieldSubtype, FieldType, RelationshipType } from "@budibase/types" import {
BBReferenceFieldSubType,
FieldType,
RelationshipType,
} from "@budibase/types"
const { API, definition, rows } = getContext("grid") const { API, definition, rows } = getContext("grid")
@ -29,9 +33,9 @@
} }
const migrateUserColumn = async () => { const migrateUserColumn = async () => {
let subtype = FieldSubtype.USERS let subtype = BBReferenceFieldSubType.USERS
if (column.schema.relationshipType === RelationshipType.ONE_TO_MANY) { if (column.schema.relationshipType === RelationshipType.ONE_TO_MANY) {
subtype = FieldSubtype.USER subtype = BBReferenceFieldSubType.USER
} }
try { try {

View File

@ -4,7 +4,7 @@
export { OperatorOptions, SqlNumberTypeRangeMap } from "@budibase/shared-core" export { OperatorOptions, SqlNumberTypeRangeMap } from "@budibase/shared-core"
export { Feature as Features } from "@budibase/types" export { Feature as Features } from "@budibase/types"
import { BpmCorrelationKey } from "@budibase/shared-core" import { BpmCorrelationKey } from "@budibase/shared-core"
import { FieldType, FieldSubtype } from "@budibase/types" import { FieldType, BBReferenceFieldSubType } from "@budibase/types"
// Cookie names // Cookie names
export const Cookies = { export const Cookies = {
@ -132,10 +132,10 @@ export const TypeIconMap = {
[FieldType.BIGINT]: "TagBold", [FieldType.BIGINT]: "TagBold",
[FieldType.AUTO]: "MagicWand", [FieldType.AUTO]: "MagicWand",
[FieldType.BB_REFERENCE]: { [FieldType.BB_REFERENCE]: {
[FieldSubtype.USER]: "User", [BBReferenceFieldSubType.USER]: "User",
[FieldSubtype.USERS]: "UserGroup", [BBReferenceFieldSubType.USERS]: "UserGroup",
}, },
[FieldType.BB_REFERENCE_SINGLE]: { [FieldType.BB_REFERENCE_SINGLE]: {
[FieldSubtype.USER]: "User", [BBReferenceFieldSubType.USER]: "User",
}, },
} }

View File

@ -9,7 +9,7 @@ import { mocks } from "@budibase/backend-core/tests"
import { import {
Datasource, Datasource,
FieldSchema, FieldSchema,
FieldSubtype, BBReferenceFieldSubType,
FieldType, FieldType,
QueryPreview, QueryPreview,
RelationshipType, RelationshipType,
@ -337,7 +337,7 @@ describe("/datasources", () => {
[FieldType.BB_REFERENCE]: { [FieldType.BB_REFERENCE]: {
name: "bb_reference", name: "bb_reference",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
} }

View File

@ -13,7 +13,7 @@ import {
DeleteRow, DeleteRow,
FieldSchema, FieldSchema,
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
FormulaType, FormulaType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
NumberFieldMetadata, NumberFieldMetadata,
@ -1015,12 +1015,12 @@ describe.each([
user: { user: {
name: "user", name: "user",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
}, },
users: { users: {
name: "users", name: "users",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}), }),
() => config.createUser(), () => config.createUser(),

View File

@ -2,7 +2,7 @@ import { context, events } from "@budibase/backend-core"
import { import {
AutoFieldSubType, AutoFieldSubType,
Datasource, Datasource,
FieldSubtype, BBReferenceFieldSubType,
FieldType, FieldType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
InternalTable, InternalTable,
@ -497,7 +497,7 @@ describe.each([
newColumn: { newColumn: {
name: "user column", name: "user column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
}, },
}) })
@ -562,7 +562,7 @@ describe.each([
newColumn: { newColumn: {
name: "user column", name: "user column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}) })
@ -614,7 +614,7 @@ describe.each([
newColumn: { newColumn: {
name: "user column", name: "user column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}) })
@ -669,7 +669,7 @@ describe.each([
newColumn: { newColumn: {
name: "user column", name: "user column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}) })
@ -728,7 +728,7 @@ describe.each([
newColumn: { newColumn: {
name: "", name: "",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}, },
{ status: 400 } { status: 400 }
@ -743,7 +743,7 @@ describe.each([
newColumn: { newColumn: {
name: "_id", name: "_id",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}, },
{ status: 400 } { status: 400 }
@ -758,7 +758,7 @@ describe.each([
newColumn: { newColumn: {
name: "num", name: "num",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}, },
{ status: 400 } { status: 400 }
@ -772,12 +772,12 @@ describe.each([
oldColumn: { oldColumn: {
name: "not a column", name: "not a column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
newColumn: { newColumn: {
name: "new column", name: "new column",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}, },
{ status: 400 } { status: 400 }

View File

@ -12,7 +12,7 @@ import SqlTableQueryBuilder from "./sqlTable"
import { import {
BBReferenceFieldMetadata, BBReferenceFieldMetadata,
FieldSchema, FieldSchema,
FieldSubtype, BBReferenceFieldSubType,
FieldType, FieldType,
JsonFieldMetadata, JsonFieldMetadata,
Operation, Operation,
@ -767,7 +767,7 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
return ( return (
field.type === FieldType.JSON || field.type === FieldType.JSON ||
(field.type === FieldType.BB_REFERENCE && (field.type === FieldType.BB_REFERENCE &&
field.subtype === FieldSubtype.USERS) field.subtype === BBReferenceFieldSubType.USERS)
) )
} }

View File

@ -1,6 +1,6 @@
import { Knex, knex } from "knex" import { Knex, knex } from "knex"
import { import {
FieldSubtype, BBReferenceFieldSubType,
FieldType, FieldType,
NumberFieldMetadata, NumberFieldMetadata,
Operation, Operation,
@ -66,10 +66,10 @@ function generateSchema(
case FieldType.BB_REFERENCE_SINGLE: { case FieldType.BB_REFERENCE_SINGLE: {
const subtype = column.subtype const subtype = column.subtype
switch (subtype) { switch (subtype) {
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
schema.text(key) schema.text(key)
break break
case FieldSubtype.USERS: case BBReferenceFieldSubType.USERS:
schema.json(key) schema.json(key)
break break
default: default:

View File

@ -2,7 +2,7 @@ import { searchInputMapping } from "../utils"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
RowSearchParams, RowSearchParams,
Table, Table,
@ -20,7 +20,7 @@ const tableWithUserCol: Table = {
user: { user: {
name: "user", name: "user",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
}, },
}, },
} }
@ -35,7 +35,7 @@ const tableWithUsersCol: Table = {
user: { user: {
name: "user", name: "user",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
}, },
} }

View File

@ -3,7 +3,7 @@ import {
Table, Table,
DocumentType, DocumentType,
SEPARATOR, SEPARATOR,
FieldSubtype, BBReferenceFieldSubType,
SearchFilters, SearchFilters,
SearchIndex, SearchIndex,
SearchResponse, SearchResponse,
@ -89,8 +89,8 @@ export function searchInputMapping(table: Table, options: RowSearchParams) {
case FieldType.BB_REFERENCE: { case FieldType.BB_REFERENCE: {
const subtype = column.subtype const subtype = column.subtype
switch (subtype) { switch (subtype) {
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
case FieldSubtype.USERS: case BBReferenceFieldSubType.USERS:
userColumnMapping(key, options) userColumnMapping(key, options)
break break
default: default:

View File

@ -2,7 +2,7 @@ import { BadRequestError, context, db as dbCore } from "@budibase/backend-core"
import { import {
BBReferenceFieldMetadata, BBReferenceFieldMetadata,
FieldSchema, FieldSchema,
FieldSubtype, BBReferenceFieldSubType,
InternalTable, InternalTable,
isBBReferenceField, isBBReferenceField,
isRelationshipField, isRelationshipField,
@ -96,7 +96,7 @@ function getColumnMigrator(
} }
if (oldColumn.relationshipType === RelationshipType.ONE_TO_MANY) { if (oldColumn.relationshipType === RelationshipType.ONE_TO_MANY) {
if (newColumn.subtype !== FieldSubtype.USER) { if (newColumn.subtype !== BBReferenceFieldSubType.USER) {
throw new BadRequestError( throw new BadRequestError(
`Column "${oldColumn.name}" is a one-to-many column but "${newColumn.name}" is not a single user column` `Column "${oldColumn.name}" is a one-to-many column but "${newColumn.name}" is not a single user column`
) )
@ -107,7 +107,7 @@ function getColumnMigrator(
oldColumn.relationshipType === RelationshipType.MANY_TO_MANY || oldColumn.relationshipType === RelationshipType.MANY_TO_MANY ||
oldColumn.relationshipType === RelationshipType.MANY_TO_ONE oldColumn.relationshipType === RelationshipType.MANY_TO_ONE
) { ) {
if (newColumn.subtype !== FieldSubtype.USERS) { if (newColumn.subtype !== BBReferenceFieldSubType.USERS) {
throw new BadRequestError( throw new BadRequestError(
`Column "${oldColumn.name}" is a ${oldColumn.relationshipType} column but "${newColumn.name}" is not a multi user column` `Column "${oldColumn.name}" is a ${oldColumn.relationshipType} column but "${newColumn.name}" is not a multi user column`
) )

View File

@ -2,7 +2,7 @@ import { cache, db as dbCore } from "@budibase/backend-core"
import { utils } from "@budibase/shared-core" import { utils } from "@budibase/shared-core"
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
DocumentType, DocumentType,
SEPARATOR, SEPARATOR,
} from "@budibase/types" } from "@budibase/types"
@ -17,13 +17,13 @@ export function processInputBBReferences(
export function processInputBBReferences( export function processInputBBReferences(
value: string | string[] | { _id: string } | { _id: string }[], value: string | string[] | { _id: string } | { _id: string }[],
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER | FieldSubtype.USERS subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
): Promise<string | null> ): Promise<string | null>
export async function processInputBBReferences( export async function processInputBBReferences(
value: string | string[] | { _id: string } | { _id: string }[], value: string | string[] | { _id: string } | { _id: string }[],
type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE,
subtype?: FieldSubtype subtype?: BBReferenceFieldSubType
): Promise<string | string[] | null> { ): Promise<string | string[] | null> {
switch (type) { switch (type) {
case FieldType.BB_REFERENCE: { case FieldType.BB_REFERENCE: {
@ -60,19 +60,22 @@ export async function processInputBBReferences(
switch (subtype) { switch (subtype) {
case undefined: case undefined:
throw "Subtype must be defined" throw "Subtype must be defined"
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
case FieldSubtype.USERS: { case BBReferenceFieldSubType.USERS: {
const { notFoundIds } = await cache.user.getUsers(referenceIds) const { notFoundIds } = await cache.user.getUsers(referenceIds)
if (notFoundIds?.length) { if (notFoundIds?.length) {
throw new InvalidBBRefError(notFoundIds[0], FieldSubtype.USER) throw new InvalidBBRefError(
notFoundIds[0],
BBReferenceFieldSubType.USER
)
} }
if (!referenceIds?.length) { if (!referenceIds?.length) {
return null return null
} }
if (subtype === FieldSubtype.USERS) { if (subtype === BBReferenceFieldSubType.USERS) {
return referenceIds return referenceIds
} }
@ -92,7 +95,7 @@ export async function processInputBBReferences(
const user = await cache.user.getUser(id) const user = await cache.user.getUser(id)
if (!user) { if (!user) {
throw new InvalidBBRefError(id, FieldSubtype.USER) throw new InvalidBBRefError(id, BBReferenceFieldSubType.USER)
} }
return user._id! return user._id!
@ -118,13 +121,13 @@ export function processOutputBBReferences(
export function processOutputBBReferences( export function processOutputBBReferences(
value: string, value: string,
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER | FieldSubtype.USERS subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
): Promise<UserReferenceInfo[]> ): Promise<UserReferenceInfo[]>
export async function processOutputBBReferences( export async function processOutputBBReferences(
value: string | string[], value: string | string[],
type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE,
subtype?: FieldSubtype subtype?: BBReferenceFieldSubType
) { ) {
if (value === null || value === undefined) { if (value === null || value === undefined) {
// Already processed or nothing to process // Already processed or nothing to process
@ -139,8 +142,8 @@ export async function processOutputBBReferences(
switch (subtype) { switch (subtype) {
case undefined: case undefined:
throw "Subtype must be defined" throw "Subtype must be defined"
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
case FieldSubtype.USERS: { case BBReferenceFieldSubType.USERS: {
const { users } = await cache.user.getUsers(ids) const { users } = await cache.user.getUsers(ids)
if (!users.length) { if (!users.length) {
return undefined return undefined

View File

@ -1,7 +1,7 @@
import { FieldSubtype } from "@budibase/types" import { BBReferenceFieldSubType } from "@budibase/types"
export class InvalidBBRefError extends Error { export class InvalidBBRefError extends Error {
constructor(id: string, subtype: FieldSubtype) { constructor(id: string, subtype: BBReferenceFieldSubType) {
super(`Id "${id}" is not valid for the subtype "${subtype}"`) super(`Id "${id}" is not valid for the subtype "${subtype}"`)
} }
} }

View File

@ -1,6 +1,6 @@
import _ from "lodash" import _ from "lodash"
import * as backendCore from "@budibase/backend-core" import * as backendCore from "@budibase/backend-core"
import { FieldSubtype, FieldType, User } from "@budibase/types" import { BBReferenceFieldSubType, FieldType, User } from "@budibase/types"
import { import {
processInputBBReferences, processInputBBReferences,
processOutputBBReferences, processOutputBBReferences,
@ -66,7 +66,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userId, userId,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -83,10 +83,12 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userId, userId,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
).rejects.toThrow(new InvalidBBRefError(userId, FieldSubtype.USER)) ).rejects.toThrow(
new InvalidBBRefError(userId, BBReferenceFieldSubType.USER)
)
expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1) expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1)
expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId]) expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId])
}) })
@ -99,7 +101,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userIdCsv, userIdCsv,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -123,10 +125,12 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userIdCsv, userIdCsv,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
).rejects.toThrow(new InvalidBBRefError(wrongId, FieldSubtype.USER)) ).rejects.toThrow(
new InvalidBBRefError(wrongId, BBReferenceFieldSubType.USER)
)
}) })
it("validate valid user object", async () => { it("validate valid user object", async () => {
@ -136,7 +140,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
{ _id: userId }, { _id: userId },
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -152,7 +156,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userIds, userIds,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -166,7 +170,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
"", "",
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -178,7 +182,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
[], [],
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -192,7 +196,7 @@ describe("bbReferenceProcessor", () => {
processInputBBReferences( processInputBBReferences(
userMetadataId, userMetadataId,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
expect(result).toBe(userId) expect(result).toBe(userId)
@ -210,7 +214,7 @@ describe("bbReferenceProcessor", () => {
processOutputBBReferences( processOutputBBReferences(
userId, userId,
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )
@ -236,7 +240,7 @@ describe("bbReferenceProcessor", () => {
processOutputBBReferences( processOutputBBReferences(
[userId1, userId2].join(","), [userId1, userId2].join(","),
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
) )

View File

@ -2,7 +2,7 @@ import { inputProcessing } from ".."
import { generator, structures } from "@budibase/backend-core/tests" import { generator, structures } from "@budibase/backend-core/tests"
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
Table, Table,
TableSourceType, TableSourceType,
@ -39,7 +39,7 @@ describe("rowProcessor - inputProcessing", () => {
}, },
user: { user: {
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
name: "user", name: "user",
constraints: { constraints: {
presence: true, presence: true,
@ -94,7 +94,7 @@ describe("rowProcessor - inputProcessing", () => {
}, },
user: { user: {
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
name: "user", name: "user",
constraints: { constraints: {
presence: false, presence: false,
@ -136,7 +136,7 @@ describe("rowProcessor - inputProcessing", () => {
}, },
user: { user: {
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
name: "user", name: "user",
constraints: { constraints: {
presence: false, presence: false,

View File

@ -1,6 +1,6 @@
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
INTERNAL_TABLE_SOURCE_ID, INTERNAL_TABLE_SOURCE_ID,
RowAttachment, RowAttachment,
Table, Table,
@ -41,7 +41,7 @@ describe("rowProcessor - outputProcessing", () => {
}, },
user: { user: {
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
name: "user", name: "user",
constraints: { constraints: {
presence: false, presence: false,
@ -69,7 +69,7 @@ describe("rowProcessor - outputProcessing", () => {
expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith( expect(bbReferenceProcessor.processOutputBBReferences).toHaveBeenCalledWith(
"123", "123",
FieldType.BB_REFERENCE, FieldType.BB_REFERENCE,
FieldSubtype.USER BBReferenceFieldSubType.USER
) )
}) })
@ -175,7 +175,7 @@ describe("rowProcessor - outputProcessing", () => {
}, },
user: { user: {
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER, subtype: BBReferenceFieldSubType.USER,
name: "user", name: "user",
constraints: { constraints: {
presence: false, presence: false,

View File

@ -1,6 +1,6 @@
import { import {
FieldType, FieldType,
FieldSubtype, BBReferenceFieldSubType,
TableSchema, TableSchema,
FieldSchema, FieldSchema,
Row, Row,
@ -138,10 +138,10 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
parsedRow[columnName] = undefined parsedRow[columnName] = undefined
} else { } else {
switch (columnSubtype) { switch (columnSubtype) {
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
parsedRow[columnName] = parsedValues[0]?._id parsedRow[columnName] = parsedValues[0]?._id
break break
case FieldSubtype.USERS: case BBReferenceFieldSubType.USERS:
parsedRow[columnName] = parsedValues.map(u => u._id) parsedRow[columnName] = parsedValues.map(u => u._id)
break break
default: default:
@ -170,7 +170,7 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
function isValidBBReference( function isValidBBReference(
data: any, data: any,
type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE | FieldType.BB_REFERENCE_SINGLE,
subtype: FieldSubtype.USER | FieldSubtype.USERS subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
): boolean { ): boolean {
if (typeof data !== "string") { if (typeof data !== "string") {
return false return false
@ -185,14 +185,14 @@ function isValidBBReference(
} }
switch (subtype) { switch (subtype) {
case FieldSubtype.USER: case BBReferenceFieldSubType.USER:
case FieldSubtype.USERS: { case BBReferenceFieldSubType.USERS: {
const userArray = parseCsvExport<{ _id: string }[]>(data) const userArray = parseCsvExport<{ _id: string }[]>(data)
if (!Array.isArray(userArray)) { if (!Array.isArray(userArray)) {
return false return false
} }
if (subtype === FieldSubtype.USER && userArray.length > 1) { if (subtype === BBReferenceFieldSubType.USER && userArray.length > 1) {
return false return false
} }

View File

@ -1,6 +1,6 @@
import { import {
Datasource, Datasource,
FieldSubtype, BBReferenceFieldSubType,
FieldType, FieldType,
FormulaType, FormulaType,
SearchFilter, SearchFilter,
@ -22,7 +22,7 @@ const HBS_REGEX = /{{([^{].*?)}}/g
export const getValidOperatorsForType = ( export const getValidOperatorsForType = (
fieldType: { fieldType: {
type: FieldType type: FieldType
subtype?: FieldSubtype subtype?: BBReferenceFieldSubType
formulaType?: FormulaType formulaType?: FormulaType
}, },
field: string, field: string,
@ -71,10 +71,13 @@ export const getValidOperatorsForType = (
} else if ( } else if (
(type === FieldType.BB_REFERENCE_SINGLE || (type === FieldType.BB_REFERENCE_SINGLE ||
type === FieldType.BB_REFERENCE) && type === FieldType.BB_REFERENCE) &&
subtype == FieldSubtype.USER 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 (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USERS) { } else if (
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]
} }

View File

@ -128,9 +128,3 @@ export interface Row extends Document {
_viewId?: string _viewId?: string
[key: string]: any [key: string]: any
} }
export enum FieldSubtype {
USER = "user",
/** @deprecated this should not be used anymore */
USERS = "users",
}

View File

@ -24,3 +24,9 @@ export enum FormulaType {
STATIC = "static", STATIC = "static",
DYNAMIC = "dynamic", DYNAMIC = "dynamic",
} }
export enum BBReferenceFieldSubType {
USER = "user",
/** @deprecated this should not be used anymore, left here in order to support the existing usages */
USERS = "users",
}

View File

@ -1,9 +1,10 @@
// all added by grid/table when defining the // all added by grid/table when defining the
// column size, position and whether it can be viewed // column size, position and whether it can be viewed
import { FieldSubtype, FieldType } from "../row" import { FieldType } from "../row"
import { import {
AutoFieldSubType, AutoFieldSubType,
AutoReason, AutoReason,
BBReferenceFieldSubType,
FormulaType, FormulaType,
JsonFieldSubType, JsonFieldSubType,
RelationshipType, RelationshipType,
@ -109,13 +110,13 @@ export interface FormulaFieldMetadata extends BaseFieldSchema {
export interface BBReferenceFieldMetadata export interface BBReferenceFieldMetadata
extends Omit<BaseFieldSchema, "subtype"> { extends Omit<BaseFieldSchema, "subtype"> {
type: FieldType.BB_REFERENCE type: FieldType.BB_REFERENCE
subtype: FieldSubtype.USER | FieldSubtype.USERS subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
relationshipType?: RelationshipType relationshipType?: RelationshipType
} }
export interface BBReferenceSingleFieldMetadata export interface BBReferenceSingleFieldMetadata
extends Omit<BaseFieldSchema, "subtype"> { extends Omit<BaseFieldSchema, "subtype"> {
type: FieldType.BB_REFERENCE_SINGLE type: FieldType.BB_REFERENCE_SINGLE
subtype: FieldSubtype.USER | FieldSubtype.USERS subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
} }
export interface AttachmentFieldMetadata extends BaseFieldSchema { export interface AttachmentFieldMetadata extends BaseFieldSchema {