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] = {
visible: fieldSchema.visible,
readonly: fieldSchema.readonly,
order: fieldSchema.order,
width: fieldSchema.width,
icon: fieldSchema.icon,
}
return acc
}, {})

View File

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

View File

@ -38,8 +38,7 @@ export type ViewFieldMetadata = UIFieldMetadata & {
columns?: Record<string, RelationSchemaField>
}
export type RelationSchemaField = {
visible?: boolean
export type RelationSchemaField = UIFieldMetadata & {
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 {
schema?: {
[key: string]: FieldSchema & {
columns?: Record<string, FieldSchema & RelationSchemaField>
columns?: Record<string, ViewV2ColumnEnriched>
}
}
}
export interface ViewV2ColumnEnriched extends RelationSchemaField {
name: string
type: FieldType
}