1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

Merge branch 'master' of github.com:budibase/budibase into make-reuse-containers-default

This commit is contained in:
Sam Rose 2024-04-26 14:02:06 +01:00
commit 2bc7b56d74
No known key found for this signature in database
32 changed files with 145 additions and 131 deletions

View file

@ -21,7 +21,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"postcss": "^8.2.9",
"rollup": "^2.45.2",
"rollup": "^4.9.6",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2"

View file

@ -29,7 +29,11 @@
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
import { getBindings } from "components/backend/DataTable/formula"
import JSONSchemaModal from "./JSONSchemaModal.svelte"
import { FieldType, FieldSubtype, SourceName } from "@budibase/types"
import {
FieldType,
BBReferenceFieldSubType,
SourceName,
} from "@budibase/types"
import RelationshipSelector from "components/common/RelationshipSelector.svelte"
import { RowUtils } from "@budibase/frontend-core"
import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte"
@ -41,8 +45,6 @@
const NUMBER_TYPE = FieldType.NUMBER
const JSON_TYPE = FieldType.JSON
const DATE_TYPE = FieldType.DATETIME
const USER_TYPE = FieldSubtype.USER
const USERS_TYPE = FieldSubtype.USERS
const dispatch = createEventDispatcher()
const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"]
@ -263,9 +265,9 @@
delete saveColumn.fieldName
}
if (isUsersColumn(saveColumn)) {
if (saveColumn.subtype === USER_TYPE) {
if (saveColumn.subtype === BBReferenceFieldSubType.USER) {
saveColumn.relationshipType = RelationshipType.ONE_TO_MANY
} else if (saveColumn.subtype === USERS_TYPE) {
} else if (saveColumn.subtype === BBReferenceFieldSubType.USERS) {
saveColumn.relationshipType = RelationshipType.MANY_TO_MANY
}
}
@ -375,7 +377,7 @@
const isUsers =
editableColumn.type === FieldType.BB_REFERENCE &&
editableColumn.subtype === FieldSubtype.USERS
editableColumn.subtype === BBReferenceFieldSubType.USERS
if (!externalTable) {
return [
@ -485,7 +487,9 @@
function isUsersColumn(column) {
return (
column.type === FieldType.BB_REFERENCE &&
[FieldSubtype.USER, FieldSubtype.USERS].includes(column.subtype)
[BBReferenceFieldSubType.USER, BBReferenceFieldSubType.USERS].includes(
column.subtype
)
)
}
@ -688,12 +692,14 @@
>
{:else if isUsersColumn(editableColumn) && datasource?.source !== SourceName.GOOGLE_SHEETS}
<Toggle
value={editableColumn.subtype === FieldSubtype.USERS}
value={editableColumn.subtype === BBReferenceFieldSubType.USERS}
on:change={e =>
handleTypeChange(
makeFieldId(
FieldType.BB_REFERENCE,
e.detail ? FieldSubtype.USERS : FieldSubtype.USER
e.detail
? BBReferenceFieldSubType.USERS
: BBReferenceFieldSubType.USER
)
)}
disabled={!isCreating}

View file

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

View file

@ -1,6 +1,6 @@
import {
FieldType,
FieldSubtype,
BBReferenceFieldSubType,
INTERNAL_TABLE_SOURCE_ID,
AutoFieldSubType,
Hosting,
@ -160,13 +160,13 @@ export const FIELDS = {
USER: {
name: "User",
type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USER,
subtype: BBReferenceFieldSubType.USER,
icon: TypeIconMap[FieldType.USER],
},
USERS: {
name: "Users",
type: FieldType.BB_REFERENCE,
subtype: FieldSubtype.USERS,
subtype: BBReferenceFieldSubType.USERS,
icon: TypeIconMap[FieldType.USERS],
constraints: {
type: "array",

View file

@ -1,7 +1,7 @@
<script>
import { getContext } from "svelte"
import RelationshipCell from "./RelationshipCell.svelte"
import { FieldSubtype, RelationshipType } from "@budibase/types"
import { BBReferenceFieldSubType, RelationshipType } from "@budibase/types"
export let api
@ -13,13 +13,16 @@
// This is not really used, just adding some content to be able to render the relationship cell
tableId: "external",
relationshipType:
subtype === FieldSubtype.USER
subtype === BBReferenceFieldSubType.USER
? RelationshipType.ONE_TO_MANY
: RelationshipType.MANY_TO_MANY,
}
async function searchFunction(searchParams) {
if (subtype !== FieldSubtype.USER && subtype !== FieldSubtype.USERS) {
if (
subtype !== BBReferenceFieldSubType.USER &&
subtype !== BBReferenceFieldSubType.USERS
) {
throw `Search for '${subtype}' not implemented`
}

View file

@ -7,7 +7,11 @@
} from "@budibase/bbui"
import { getContext } from "svelte"
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")
@ -29,9 +33,9 @@
}
const migrateUserColumn = async () => {
let subtype = FieldSubtype.USERS
let subtype = BBReferenceFieldSubType.USERS
if (column.schema.relationshipType === RelationshipType.ONE_TO_MANY) {
subtype = FieldSubtype.USER
subtype = BBReferenceFieldSubType.USER
}
try {

View file

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

@ -1 +1 @@
Subproject commit 01bec5657e0c3c3bb29e883e6ac71258fee8710b
Subproject commit 479879246aac5dd3073cc695945c62c41fae5b0e

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ import SqlTableQueryBuilder from "./sqlTable"
import {
BBReferenceFieldMetadata,
FieldSchema,
FieldSubtype,
BBReferenceFieldSubType,
FieldType,
JsonFieldMetadata,
Operation,
@ -767,7 +767,7 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
return (
field.type === FieldType.JSON ||
(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 {
FieldSubtype,
BBReferenceFieldSubType,
FieldType,
NumberFieldMetadata,
Operation,
@ -64,10 +64,10 @@ function generateSchema(
case FieldType.BB_REFERENCE: {
const subtype = column.subtype
switch (subtype) {
case FieldSubtype.USER:
case BBReferenceFieldSubType.USER:
schema.text(key)
break
case FieldSubtype.USERS:
case BBReferenceFieldSubType.USERS:
schema.json(key)
break
default:

View file

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

View file

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

View file

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

View file

@ -1,13 +1,17 @@
import { cache, db as dbCore } from "@budibase/backend-core"
import { utils } from "@budibase/shared-core"
import { FieldSubtype, DocumentType, SEPARATOR } from "@budibase/types"
import {
BBReferenceFieldSubType,
DocumentType,
SEPARATOR,
} from "@budibase/types"
import { InvalidBBRefError } from "./errors"
const ROW_PREFIX = DocumentType.ROW + SEPARATOR
export async function processInputBBReferences(
value: string | string[] | { _id: string } | { _id: string }[],
subtype: FieldSubtype.USER | FieldSubtype.USERS
subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
): Promise<string | string[] | null> {
let referenceIds: string[] = []
@ -40,15 +44,18 @@ export async function processInputBBReferences(
})
switch (subtype) {
case FieldSubtype.USER:
case FieldSubtype.USERS: {
case BBReferenceFieldSubType.USER:
case BBReferenceFieldSubType.USERS: {
const { notFoundIds } = await cache.user.getUsers(referenceIds)
if (notFoundIds?.length) {
throw new InvalidBBRefError(notFoundIds[0], FieldSubtype.USER)
throw new InvalidBBRefError(
notFoundIds[0],
BBReferenceFieldSubType.USER
)
}
if (subtype === FieldSubtype.USERS) {
if (subtype === BBReferenceFieldSubType.USERS) {
return referenceIds
}
@ -61,7 +68,7 @@ export async function processInputBBReferences(
export async function processOutputBBReferences(
value: string | string[],
subtype: FieldSubtype.USER | FieldSubtype.USERS
subtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
) {
if (value === null || value === undefined) {
// Already processed or nothing to process
@ -72,8 +79,8 @@ export async function processOutputBBReferences(
typeof value === "string" ? value.split(",").filter(id => !!id) : value
switch (subtype) {
case FieldSubtype.USER:
case FieldSubtype.USERS: {
case BBReferenceFieldSubType.USER:
case BBReferenceFieldSubType.USERS: {
const { users } = await cache.user.getUsers(ids)
if (!users.length) {
return undefined

View file

@ -1,7 +1,7 @@
import { FieldSubtype } from "@budibase/types"
import { BBReferenceFieldSubType } from "@budibase/types"
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}"`)
}
}

View file

@ -1,6 +1,6 @@
import _ from "lodash"
import * as backendCore from "@budibase/backend-core"
import { FieldSubtype, User } from "@budibase/types"
import { BBReferenceFieldSubType, User } from "@budibase/types"
import {
processInputBBReferences,
processOutputBBReferences,
@ -63,7 +63,7 @@ describe("bbReferenceProcessor", () => {
const userId = user!._id!
const result = await config.doInTenant(() =>
processInputBBReferences(userId, FieldSubtype.USER)
processInputBBReferences(userId, BBReferenceFieldSubType.USER)
)
expect(result).toEqual(userId)
@ -76,9 +76,11 @@ describe("bbReferenceProcessor", () => {
await expect(
config.doInTenant(() =>
processInputBBReferences(userId, FieldSubtype.USER)
processInputBBReferences(userId, BBReferenceFieldSubType.USER)
)
).rejects.toThrow(new InvalidBBRefError(userId, FieldSubtype.USER))
).rejects.toThrow(
new InvalidBBRefError(userId, BBReferenceFieldSubType.USER)
)
expect(cacheGetUsersSpy).toHaveBeenCalledTimes(1)
expect(cacheGetUsersSpy).toHaveBeenCalledWith([userId])
})
@ -88,7 +90,7 @@ describe("bbReferenceProcessor", () => {
const userIdCsv = userIds.join(" , ")
const result = await config.doInTenant(() =>
processInputBBReferences(userIdCsv, FieldSubtype.USER)
processInputBBReferences(userIdCsv, BBReferenceFieldSubType.USER)
)
expect(result).toEqual(userIds.join(","))
@ -108,16 +110,21 @@ describe("bbReferenceProcessor", () => {
await expect(
config.doInTenant(() =>
processInputBBReferences(userIdCsv, FieldSubtype.USER)
processInputBBReferences(userIdCsv, BBReferenceFieldSubType.USER)
)
).rejects.toThrow(new InvalidBBRefError(wrongId, FieldSubtype.USER))
).rejects.toThrow(
new InvalidBBRefError(wrongId, BBReferenceFieldSubType.USER)
)
})
it("validate valid user object", async () => {
const userId = _.sample(users)!._id!
const result = await config.doInTenant(() =>
processInputBBReferences({ _id: userId }, FieldSubtype.USER)
processInputBBReferences(
{ _id: userId },
BBReferenceFieldSubType.USER
)
)
expect(result).toEqual(userId)
@ -129,7 +136,7 @@ describe("bbReferenceProcessor", () => {
const userIds = _.sampleSize(users, 3).map(x => x._id!)
const result = await config.doInTenant(() =>
processInputBBReferences(userIds, FieldSubtype.USER)
processInputBBReferences(userIds, BBReferenceFieldSubType.USER)
)
expect(result).toEqual(userIds.join(","))
@ -139,7 +146,7 @@ describe("bbReferenceProcessor", () => {
it("empty strings will return null", async () => {
const result = await config.doInTenant(() =>
processInputBBReferences("", FieldSubtype.USER)
processInputBBReferences("", BBReferenceFieldSubType.USER)
)
expect(result).toEqual(null)
@ -147,7 +154,7 @@ describe("bbReferenceProcessor", () => {
it("empty arrays will return null", async () => {
const result = await config.doInTenant(() =>
processInputBBReferences([], FieldSubtype.USER)
processInputBBReferences([], BBReferenceFieldSubType.USER)
)
expect(result).toEqual(null)
@ -157,7 +164,7 @@ describe("bbReferenceProcessor", () => {
const userId = _.sample(users)!._id!
const userMetadataId = backendCore.db.generateUserMetadataID(userId)
const result = await config.doInTenant(() =>
processInputBBReferences(userMetadataId, FieldSubtype.USER)
processInputBBReferences(userMetadataId, BBReferenceFieldSubType.USER)
)
expect(result).toBe(userId)
})
@ -171,7 +178,7 @@ describe("bbReferenceProcessor", () => {
const userId = user._id!
const result = await config.doInTenant(() =>
processOutputBBReferences(userId, FieldSubtype.USER)
processOutputBBReferences(userId, BBReferenceFieldSubType.USER)
)
expect(result).toEqual([
@ -195,7 +202,7 @@ describe("bbReferenceProcessor", () => {
const result = await config.doInTenant(() =>
processOutputBBReferences(
[userId1, userId2].join(","),
FieldSubtype.USER
BBReferenceFieldSubType.USER
)
)

View file

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

View file

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

View file

@ -1,6 +1,6 @@
import {
FieldType,
FieldSubtype,
BBReferenceFieldSubType,
TableSchema,
FieldSchema,
Row,
@ -137,10 +137,10 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
parsedRow[columnName] = undefined
} else {
switch (columnSubtype) {
case FieldSubtype.USER:
case BBReferenceFieldSubType.USER:
parsedRow[columnName] = parsedValues[0]?._id
break
case FieldSubtype.USERS:
case BBReferenceFieldSubType.USERS:
parsedRow[columnName] = parsedValues.map(u => u._id)
break
default:
@ -164,11 +164,11 @@ export function parse(rows: Rows, schema: TableSchema): Rows {
function isValidBBReference(
columnData: any,
columnSubtype: FieldSubtype.USER | FieldSubtype.USERS
columnSubtype: BBReferenceFieldSubType.USER | BBReferenceFieldSubType.USERS
): boolean {
switch (columnSubtype) {
case FieldSubtype.USER:
case FieldSubtype.USERS: {
case BBReferenceFieldSubType.USER:
case BBReferenceFieldSubType.USERS: {
if (typeof columnData !== "string") {
return false
}
@ -177,7 +177,10 @@ function isValidBBReference(
return false
}
if (columnSubtype === FieldSubtype.USER && userArray.length > 1) {
if (
columnSubtype === BBReferenceFieldSubType.USER &&
userArray.length > 1
) {
return false
}

View file

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

View file

@ -38,7 +38,7 @@
"doctrine": "^3.0.0",
"jest": "29.7.0",
"marked": "^4.0.10",
"rollup": "^2.36.2",
"rollup": "^4.9.6",
"rollup-plugin-inject-process-env": "^1.3.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",

View file

@ -124,16 +124,3 @@ export interface Row extends Document {
_viewId?: string
[key: string]: any
}
export enum FieldSubtype {
USER = "user",
USERS = "users",
}
// The 'as' are required for typescript not to type the outputs as generic FieldSubtype
export const FieldTypeSubtypes = {
BB_REFERENCE: {
USER: FieldSubtype.USER as FieldSubtype.USER,
USERS: FieldSubtype.USERS as FieldSubtype.USERS,
},
}

View file

@ -24,3 +24,8 @@ export enum FormulaType {
STATIC = "static",
DYNAMIC = "dynamic",
}
export enum BBReferenceFieldSubType {
USER = "user",
USERS = "users",
}

View file

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

View file

@ -11590,7 +11590,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==
fsevents@^2.3.2, fsevents@~2.3.1, fsevents@~2.3.2:
fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
@ -19714,20 +19714,6 @@ rollup-pluginutils@^2.3.1, rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.8.1,
dependencies:
estree-walker "^0.6.1"
rollup@2.45.2:
version "2.45.2"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.45.2.tgz#8fb85917c9f35605720e92328f3ccbfba6f78b48"
integrity sha512-kRRU7wXzFHUzBIv0GfoFFIN3m9oteY4uAsKllIpQDId5cfnkWF2J130l+27dzDju0E6MScKiV0ZM5Bw8m4blYQ==
optionalDependencies:
fsevents "~2.3.1"
rollup@^2.36.2, rollup@^2.45.2:
version "2.79.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7"
integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==
optionalDependencies:
fsevents "~2.3.2"
rollup@^3.27.1:
version "3.29.4"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.29.4.tgz#4d70c0f9834146df8705bfb69a9a19c9e1109981"