Merge branch 'master' of github.com:Budibase/budibase into v3-ui
This commit is contained in:
commit
bb5b94f667
|
@ -23,6 +23,7 @@
|
||||||
sourceType: DB_TYPE_EXTERNAL,
|
sourceType: DB_TYPE_EXTERNAL,
|
||||||
schema: {
|
schema: {
|
||||||
id: {
|
id: {
|
||||||
|
name: "id",
|
||||||
autocolumn: true,
|
autocolumn: true,
|
||||||
type: "number",
|
type: "number",
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
import { GridRowHeight, GridColumns } from "constants"
|
import { GridRowHeight, GridColumns } from "constants"
|
||||||
import { memo } from "@budibase/frontend-core"
|
import { memo } from "@budibase/frontend-core"
|
||||||
|
|
||||||
|
export let onClick
|
||||||
|
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { styleable, builderStore } = getContext("sdk")
|
const { styleable, builderStore } = getContext("sdk")
|
||||||
const context = getContext("context")
|
const context = getContext("context")
|
||||||
|
@ -121,15 +123,19 @@
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<div
|
<div
|
||||||
bind:this={ref}
|
bind:this={ref}
|
||||||
class="grid"
|
class="grid"
|
||||||
class:mobile
|
class:mobile
|
||||||
|
class:clickable={!!onClick}
|
||||||
bind:clientWidth={width}
|
bind:clientWidth={width}
|
||||||
bind:clientHeight={height}
|
bind:clientHeight={height}
|
||||||
use:styleable={$styles}
|
use:styleable={$styles}
|
||||||
data-cols={GridColumns}
|
data-cols={GridColumns}
|
||||||
data-col-size={colSize}
|
data-col-size={colSize}
|
||||||
|
on:click={onClick}
|
||||||
>
|
>
|
||||||
{#if inBuilder}
|
{#if inBuilder}
|
||||||
<div class="underlay">
|
<div class="underlay">
|
||||||
|
@ -176,6 +182,9 @@
|
||||||
.placeholder.first-col {
|
.placeholder.first-col {
|
||||||
border-left: 1px solid var(--spectrum-global-color-gray-900);
|
border-left: 1px solid var(--spectrum-global-color-gray-900);
|
||||||
}
|
}
|
||||||
|
.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
/* Highlight grid lines when resizing children */
|
/* Highlight grid lines when resizing children */
|
||||||
:global(.grid.highlight > .underlay) {
|
:global(.grid.highlight > .underlay) {
|
||||||
|
|
|
@ -71,19 +71,20 @@ export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
||||||
|
|
||||||
const datasources = await sdk.datasources.getExternalDatasources()
|
const datasources = await sdk.datasources.getExternalDatasources()
|
||||||
|
|
||||||
const external = datasources.flatMap(datasource => {
|
const external: Table[] = []
|
||||||
|
for (const datasource of datasources) {
|
||||||
let entities = datasource.entities
|
let entities = datasource.entities
|
||||||
if (entities) {
|
if (entities) {
|
||||||
return Object.values(entities).map<Table>((entity: Table) => ({
|
for (const entity of Object.values(entities)) {
|
||||||
...entity,
|
external.push({
|
||||||
sourceType: TableSourceType.EXTERNAL,
|
...(await processTable(entity)),
|
||||||
sourceId: datasource._id!,
|
sourceType: TableSourceType.EXTERNAL,
|
||||||
sql: isSQL(datasource),
|
sourceId: datasource._id!,
|
||||||
}))
|
sql: isSQL(datasource),
|
||||||
} else {
|
})
|
||||||
return []
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
const result: FetchTablesResponse = []
|
const result: FetchTablesResponse = []
|
||||||
for (const table of [...internal, ...external]) {
|
for (const table of [...internal, ...external]) {
|
||||||
|
|
|
@ -789,6 +789,39 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("multi-user column", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
users: {
|
||||||
|
name: "users",
|
||||||
|
type: FieldType.BB_REFERENCE,
|
||||||
|
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.users).toHaveLength(1)
|
||||||
|
expect(row.users[0]._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!, {
|
||||||
|
users: [id],
|
||||||
|
})
|
||||||
|
expect(row.users).toHaveLength(1)
|
||||||
|
expect(row.users[0]._id).toEqual(id)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("bindings", () => {
|
describe("bindings", () => {
|
||||||
describe("string column", () => {
|
describe("string column", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
|
|
@ -20,7 +20,13 @@ export async function processTable(table: Table): Promise<Table> {
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table = { ...table }
|
||||||
if (table._id && isExternalTableID(table._id)) {
|
if (table._id && isExternalTableID(table._id)) {
|
||||||
|
// Old created external tables via Budibase might have a missing field name breaking some UI such as filters
|
||||||
|
if (table.schema["id"] && !table.schema["id"].name) {
|
||||||
|
table.schema["id"].name = "id"
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...table,
|
...table,
|
||||||
type: "table",
|
type: "table",
|
||||||
|
|
|
@ -33,7 +33,7 @@ import {
|
||||||
PROTECTED_EXTERNAL_COLUMNS,
|
PROTECTED_EXTERNAL_COLUMNS,
|
||||||
PROTECTED_INTERNAL_COLUMNS,
|
PROTECTED_INTERNAL_COLUMNS,
|
||||||
} from "@budibase/shared-core"
|
} from "@budibase/shared-core"
|
||||||
import { processString } from "@budibase/string-templates"
|
import { processStringSync } from "@budibase/string-templates"
|
||||||
import {
|
import {
|
||||||
getTableFromSource,
|
getTableFromSource,
|
||||||
isUserMetadataTable,
|
isUserMetadataTable,
|
||||||
|
@ -134,10 +134,15 @@ async function processDefaultValues(table: Table, row: Row) {
|
||||||
|
|
||||||
for (const [key, schema] of Object.entries(table.schema)) {
|
for (const [key, schema] of Object.entries(table.schema)) {
|
||||||
if ("default" in schema && schema.default != null && row[key] == null) {
|
if ("default" in schema && schema.default != null && row[key] == null) {
|
||||||
const processed =
|
let processed: string | string[]
|
||||||
typeof schema.default === "string"
|
if (Array.isArray(schema.default)) {
|
||||||
? await processString(schema.default, ctx)
|
processed = schema.default.map(val => processStringSync(val, ctx))
|
||||||
: schema.default
|
} else if (typeof schema.default === "string") {
|
||||||
|
processed = processStringSync(schema.default, ctx)
|
||||||
|
} else {
|
||||||
|
processed = schema.default
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
row[key] = coerce(processed, schema.type)
|
row[key] = coerce(processed, schema.type)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ const allowDefaultColumnByType: Record<FieldType, boolean> = {
|
||||||
[FieldType.ATTACHMENT_SINGLE]: false,
|
[FieldType.ATTACHMENT_SINGLE]: false,
|
||||||
[FieldType.SIGNATURE_SINGLE]: false,
|
[FieldType.SIGNATURE_SINGLE]: false,
|
||||||
[FieldType.LINK]: false,
|
[FieldType.LINK]: false,
|
||||||
[FieldType.BB_REFERENCE]: false,
|
[FieldType.BB_REFERENCE]: true,
|
||||||
[FieldType.BB_REFERENCE_SINGLE]: true,
|
[FieldType.BB_REFERENCE_SINGLE]: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,7 @@ export interface BBReferenceFieldMetadata
|
||||||
type: FieldType.BB_REFERENCE
|
type: FieldType.BB_REFERENCE
|
||||||
subtype: BBReferenceFieldSubType
|
subtype: BBReferenceFieldSubType
|
||||||
relationshipType?: RelationshipType
|
relationshipType?: RelationshipType
|
||||||
|
default?: string[]
|
||||||
}
|
}
|
||||||
export interface BBReferenceSingleFieldMetadata
|
export interface BBReferenceSingleFieldMetadata
|
||||||
extends Omit<BaseFieldSchema, "subtype"> {
|
extends Omit<BaseFieldSchema, "subtype"> {
|
||||||
|
|
Loading…
Reference in New Issue