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:
commit
4a52b648f8
|
@ -14,6 +14,7 @@ import {
|
|||
InternalTable,
|
||||
tenancy,
|
||||
features,
|
||||
utils,
|
||||
} from "@budibase/backend-core"
|
||||
import { quotas } from "@budibase/pro"
|
||||
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("string column", () => {
|
||||
beforeAll(async () => {
|
||||
|
|
|
@ -67,7 +67,7 @@ const allowDefaultColumnByType: Record<FieldType, boolean> = {
|
|||
[FieldType.SIGNATURE_SINGLE]: false,
|
||||
[FieldType.LINK]: false,
|
||||
[FieldType.BB_REFERENCE]: false,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: false,
|
||||
[FieldType.BB_REFERENCE_SINGLE]: true,
|
||||
}
|
||||
|
||||
export function canBeDisplayColumn(type: FieldType): boolean {
|
||||
|
|
|
@ -126,6 +126,7 @@ export interface BBReferenceSingleFieldMetadata
|
|||
extends Omit<BaseFieldSchema, "subtype"> {
|
||||
type: FieldType.BB_REFERENCE_SINGLE
|
||||
subtype: Exclude<BBReferenceFieldSubType, BBReferenceFieldSubType.USERS>
|
||||
default?: string
|
||||
}
|
||||
|
||||
export interface AttachmentFieldMetadata extends BaseFieldSchema {
|
||||
|
|
Loading…
Reference in New Issue