Extend view metadata

This commit is contained in:
Adria Navarro 2024-05-24 14:28:04 +02:00
parent ee77e08b3c
commit a0c2843236
2 changed files with 10 additions and 5 deletions

View File

@ -3,7 +3,7 @@ import {
CreateViewRequest, CreateViewRequest,
Ctx, Ctx,
RequiredKeys, RequiredKeys,
UIFieldMetadata, ViewUIFieldMetadata,
UpdateViewRequest, UpdateViewRequest,
ViewResponse, ViewResponse,
ViewResponseEnriched, ViewResponseEnriched,
@ -18,20 +18,21 @@ async function parseSchema(view: CreateViewRequest) {
const finalViewSchema = const finalViewSchema =
view.schema && view.schema &&
Object.entries(view.schema).reduce((p, [fieldName, schemaValue]) => { Object.entries(view.schema).reduce((p, [fieldName, schemaValue]) => {
const fieldSchema: RequiredKeys<UIFieldMetadata> = { const fieldSchema: RequiredKeys<ViewUIFieldMetadata> = {
order: schemaValue.order, order: schemaValue.order,
width: schemaValue.width, width: schemaValue.width,
visible: schemaValue.visible, visible: schemaValue.visible,
readonly: schemaValue.readonly,
icon: schemaValue.icon, icon: schemaValue.icon,
} }
Object.entries(fieldSchema) Object.entries(fieldSchema)
.filter(([, val]) => val === undefined) .filter(([, val]) => val === undefined)
.forEach(([key]) => { .forEach(([key]) => {
delete fieldSchema[key as keyof UIFieldMetadata] delete fieldSchema[key as keyof ViewUIFieldMetadata]
}) })
p[fieldName] = fieldSchema p[fieldName] = fieldSchema
return p return p
}, {} as Record<string, RequiredKeys<UIFieldMetadata>>) }, {} as Record<string, RequiredKeys<ViewUIFieldMetadata>>)
for (let [key, column] of Object.entries(finalViewSchema)) { for (let [key, column] of Object.entries(finalViewSchema)) {
if (!column.visible) { if (!column.visible) {
delete finalViewSchema[key] delete finalViewSchema[key]

View File

@ -33,6 +33,10 @@ export interface View {
groupBy?: string groupBy?: string
} }
export type ViewUIFieldMetadata = UIFieldMetadata & {
readonly?: boolean
}
export interface ViewV2 { export interface ViewV2 {
version: 2 version: 2
id: string id: string
@ -45,7 +49,7 @@ export interface ViewV2 {
order?: SortOrder order?: SortOrder
type?: SortType type?: SortType
} }
schema?: Record<string, UIFieldMetadata> schema?: Record<string, ViewUIFieldMetadata>
} }
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema