Add metadata on related columns

This commit is contained in:
Adria Navarro 2024-09-06 17:01:13 +02:00
parent 30e31e1254
commit 77be1cd869
4 changed files with 24 additions and 9 deletions

View File

@ -29,6 +29,9 @@ async function parseSchema(view: CreateViewRequest) {
acc[key] = { acc[key] = {
visible: fieldSchema.visible, visible: fieldSchema.visible,
readonly: fieldSchema.readonly, readonly: fieldSchema.readonly,
order: fieldSchema.order,
width: fieldSchema.width,
icon: fieldSchema.icon,
} }
return acc return acc
}, {}) }, {})

View File

@ -1,5 +1,4 @@
import { import {
FieldSchema,
FieldType, FieldType,
RelationSchemaField, RelationSchemaField,
RenameColumn, RenameColumn,
@ -8,6 +7,7 @@ import {
View, View,
ViewFieldMetadata, ViewFieldMetadata,
ViewV2, ViewV2,
ViewV2ColumnEnriched,
ViewV2Enriched, ViewV2Enriched,
} from "@budibase/types" } from "@budibase/types"
import { HTTPError } from "@budibase/backend-core" import { HTTPError } from "@budibase/backend-core"
@ -177,7 +177,7 @@ export async function enrichSchema(
} }
const relTable = tableCache[tableId] const relTable = tableCache[tableId]
const result: Record<string, FieldSchema & RelationSchemaField> = {} const result: Record<string, ViewV2ColumnEnriched> = {}
for (const relTableFieldName of Object.keys(relTable.schema)) { for (const relTableFieldName of Object.keys(relTable.schema)) {
const relTableField = relTable.schema[relTableFieldName] const relTableField = relTable.schema[relTableFieldName]
@ -189,10 +189,13 @@ export async function enrichSchema(
continue continue
} }
const isVisible = !!viewFields[relTableFieldName]?.visible const viewFieldSchema = viewFields[relTableFieldName]
const isReadonly = !!viewFields[relTableFieldName]?.readonly const isVisible = !!viewFieldSchema?.visible
const isReadonly = !!viewFieldSchema?.readonly
result[relTableFieldName] = { result[relTableFieldName] = {
...relTableField, ...viewFieldSchema,
type: relTableField.type,
name: relTableField.name,
visible: isVisible, visible: isVisible,
readonly: isReadonly, readonly: isReadonly,
} }

View File

@ -38,8 +38,7 @@ export type ViewFieldMetadata = UIFieldMetadata & {
columns?: Record<string, RelationSchemaField> columns?: Record<string, RelationSchemaField>
} }
export type RelationSchemaField = { export type RelationSchemaField = UIFieldMetadata & {
visible?: boolean
readonly?: boolean readonly?: boolean
} }

View File

@ -1,9 +1,19 @@
import { FieldSchema, RelationSchemaField, ViewV2 } from "../documents" import {
FieldSchema,
FieldType,
RelationSchemaField,
ViewV2,
} from "../documents"
export interface ViewV2Enriched extends ViewV2 { export interface ViewV2Enriched extends ViewV2 {
schema?: { schema?: {
[key: string]: FieldSchema & { [key: string]: FieldSchema & {
columns?: Record<string, FieldSchema & RelationSchemaField> columns?: Record<string, ViewV2ColumnEnriched>
} }
} }
} }
export interface ViewV2ColumnEnriched extends RelationSchemaField {
name: string
type: FieldType
}