diff --git a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte index 79e457aa16..456eb50a9c 100644 --- a/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte +++ b/packages/frontend-core/src/components/grid/controls/ColumnsSettingContent.svelte @@ -12,7 +12,7 @@ export let columns export let fromRelationshipField - const { datasource, dispatch, cache, config } = getContext("grid") + const { datasource, dispatch, config } = getContext("grid") $: canSetRelationshipSchemas = $config.canSetRelationshipSchemas @@ -114,29 +114,19 @@ return { ...c, options } }) - let relationshipPanelColumns = [] - async function fetchRelationshipPanelColumns(relationshipField) { - relationshipPanelColumns = [] - if (!relationshipField) { - return + $: relationshipPanelColumns = Object.entries( + relationshipField?.columns || {} + ).map(([name, column]) => { + return { + name: name, + label: name, + schema: { + type: column.type, + visible: column.visible, + readonly: column.readonly, + }, } - - const table = await cache.actions.getTable(relationshipField.tableId) - relationshipPanelColumns = Object.entries( - relationshipField?.columns || {} - ).map(([name, column]) => { - return { - name: name, - label: name, - schema: { - type: table.schema[name].type, - visible: column.visible, - readonly: column.readonly, - }, - } - }) - } - $: fetchRelationshipPanelColumns(relationshipField) + }) async function toggleColumn(column, permission) { const visible = permission !== FieldPermissions.HIDDEN diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 90e80fe81d..40afb2e846 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -29,6 +29,9 @@ async function parseSchema(view: CreateViewRequest) { acc[key] = { visible: fieldSchema.visible, readonly: fieldSchema.readonly, + order: fieldSchema.order, + width: fieldSchema.width, + icon: fieldSchema.icon, } return acc }, {}) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 6d2d13e580..3ca28f31aa 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -1278,9 +1278,18 @@ describe.each([ schema: expect.objectContaining({ aux: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - name: { visible: true, readonly: true }, - dob: { visible: true, readonly: true }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + name: expect.objectContaining({ + visible: true, + readonly: true, + }), + dob: expect.objectContaining({ + visible: true, + readonly: true, + }), }, }), }), @@ -1323,16 +1332,34 @@ describe.each([ schema: expect.objectContaining({ aux: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - name: { visible: true, readonly: true }, - dob: { visible: true, readonly: true }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + name: expect.objectContaining({ + visible: true, + readonly: true, + }), + dob: expect.objectContaining({ + visible: true, + readonly: true, + }), }, }), aux2: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - name: { visible: true, readonly: true }, - dob: { visible: true, readonly: true }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + name: expect.objectContaining({ + visible: true, + readonly: true, + }), + dob: expect.objectContaining({ + visible: true, + readonly: true, + }), }, }), }), @@ -1375,16 +1402,34 @@ describe.each([ schema: expect.objectContaining({ aux: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - fullName: { visible: true, readonly: true }, - age: { visible: false, readonly: false }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + fullName: expect.objectContaining({ + visible: true, + readonly: true, + }), + age: expect.objectContaining({ + visible: false, + readonly: false, + }), }, }), aux2: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - name: { visible: true, readonly: true }, - age: { visible: false, readonly: false }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + name: expect.objectContaining({ + visible: true, + readonly: true, + }), + age: expect.objectContaining({ + visible: false, + readonly: false, + }), }, }), }), @@ -1427,9 +1472,18 @@ describe.each([ schema: expect.objectContaining({ aux: expect.objectContaining({ columns: { - id: { visible: false, readonly: false }, - name: { visible: true, readonly: true }, - dob: { visible: true, readonly: true }, + id: expect.objectContaining({ + visible: false, + readonly: false, + }), + name: expect.objectContaining({ + visible: true, + readonly: true, + }), + dob: expect.objectContaining({ + visible: true, + readonly: true, + }), }, }), }), diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index a0cffb2634..d7e05abf2f 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -7,6 +7,7 @@ import { View, ViewFieldMetadata, ViewV2, + ViewV2ColumnEnriched, ViewV2Enriched, } from "@budibase/types" import { HTTPError } from "@budibase/backend-core" @@ -176,7 +177,7 @@ export async function enrichSchema( } const relTable = tableCache[tableId] - const result: Record = {} + const result: Record = {} for (const relTableFieldName of Object.keys(relTable.schema)) { const relTableField = relTable.schema[relTableFieldName] @@ -188,9 +189,13 @@ export async function enrichSchema( continue } - const isVisible = !!viewFields[relTableFieldName]?.visible - const isReadonly = !!viewFields[relTableFieldName]?.readonly + const viewFieldSchema = viewFields[relTableFieldName] + const isVisible = !!viewFieldSchema?.visible + const isReadonly = !!viewFieldSchema?.readonly result[relTableFieldName] = { + ...relTableField, + ...viewFieldSchema, + name: relTableField.name, visible: isVisible, readonly: isReadonly, } @@ -211,6 +216,7 @@ export async function enrichSchema( ...tableSchema[key], ...ui, order: anyViewOrder ? ui?.order ?? undefined : tableSchema[key].order, + columns: undefined, } if (schema[key].type === FieldType.LINK) { diff --git a/packages/server/src/sdk/app/views/tests/views.spec.ts b/packages/server/src/sdk/app/views/tests/views.spec.ts index 5a86702ab6..1d7360c5eb 100644 --- a/packages/server/src/sdk/app/views/tests/views.spec.ts +++ b/packages/server/src/sdk/app/views/tests/views.spec.ts @@ -355,10 +355,14 @@ describe("table sdk", () => { visible: true, columns: { title: { + name: "title", + type: "string", visible: true, readonly: true, }, age: { + name: "age", + type: "number", visible: false, readonly: false, }, diff --git a/packages/types/src/documents/app/table/constants.ts b/packages/types/src/documents/app/table/constants.ts index 210ad1423d..fffaddc5df 100644 --- a/packages/types/src/documents/app/table/constants.ts +++ b/packages/types/src/documents/app/table/constants.ts @@ -10,6 +10,11 @@ export enum AutoReason { FOREIGN_KEY = "foreign_key", } +export type FieldSubType = + | AutoFieldSubType + | JsonFieldSubType + | BBReferenceFieldSubType + export enum AutoFieldSubType { CREATED_BY = "createdBy", CREATED_AT = "createdAt", diff --git a/packages/types/src/documents/app/view.ts b/packages/types/src/documents/app/view.ts index b5fdcacefe..b847520526 100644 --- a/packages/types/src/documents/app/view.ts +++ b/packages/types/src/documents/app/view.ts @@ -38,8 +38,7 @@ export type ViewFieldMetadata = UIFieldMetadata & { columns?: Record } -export type RelationSchemaField = { - visible?: boolean +export type RelationSchemaField = UIFieldMetadata & { readonly?: boolean } diff --git a/packages/types/src/sdk/view.ts b/packages/types/src/sdk/view.ts index b330db3950..422207197d 100644 --- a/packages/types/src/sdk/view.ts +++ b/packages/types/src/sdk/view.ts @@ -3,7 +3,9 @@ import { FieldSchema, RelationSchemaField, ViewV2 } from "../documents" export interface ViewV2Enriched extends ViewV2 { schema?: { [key: string]: FieldSchema & { - columns?: Record + columns?: Record } } } + +export type ViewV2ColumnEnriched = RelationSchemaField & FieldSchema