Merge pull request #14772 from Budibase/budi-8722-default-value-on-user-columns

Allow BB_REFERNCE_SINGLE to have default values.
This commit is contained in:
Sam Rose 2024-10-11 16:37:06 +01:00 committed by GitHub
commit 4a52b648f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import {
InternalTable, InternalTable,
tenancy, tenancy,
features, features,
utils,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { import {
@ -757,6 +758,37 @@ describe.each([
}) })
}) })
describe("user column", () => {
beforeAll(async () => {
table = await config.api.table.save(
saveTableRequest({
schema: {
user: {
name: "user",
type: FieldType.BB_REFERENCE_SINGLE,
subtype: BBReferenceFieldSubType.USER,
default: "{{ [Current User]._id }}",
},
},
})
)
})
it("creates a new row with a default value successfully", async () => {
const row = await config.api.row.save(table._id!, {})
expect(row.user._id).toEqual(config.getUser()._id)
})
it("does not use default value if value specified", async () => {
const id = `us_${utils.newid()}`
await config.createUser({ _id: id })
const row = await config.api.row.save(table._id!, {
user: id,
})
expect(row.user._id).toEqual(id)
})
})
describe("bindings", () => { describe("bindings", () => {
describe("string column", () => { describe("string column", () => {
beforeAll(async () => { beforeAll(async () => {

View File

@ -67,7 +67,7 @@ const allowDefaultColumnByType: Record<FieldType, boolean> = {
[FieldType.SIGNATURE_SINGLE]: false, [FieldType.SIGNATURE_SINGLE]: false,
[FieldType.LINK]: false, [FieldType.LINK]: false,
[FieldType.BB_REFERENCE]: false, [FieldType.BB_REFERENCE]: false,
[FieldType.BB_REFERENCE_SINGLE]: false, [FieldType.BB_REFERENCE_SINGLE]: true,
} }
export function canBeDisplayColumn(type: FieldType): boolean { export function canBeDisplayColumn(type: FieldType): boolean {

View File

@ -126,6 +126,7 @@ export interface BBReferenceSingleFieldMetadata
extends Omit<BaseFieldSchema, "subtype"> { extends Omit<BaseFieldSchema, "subtype"> {
type: FieldType.BB_REFERENCE_SINGLE type: FieldType.BB_REFERENCE_SINGLE
subtype: Exclude<BBReferenceFieldSubType, BBReferenceFieldSubType.USERS> subtype: Exclude<BBReferenceFieldSubType, BBReferenceFieldSubType.USERS>
default?: string
} }
export interface AttachmentFieldMetadata extends BaseFieldSchema { export interface AttachmentFieldMetadata extends BaseFieldSchema {