1
0
Fork 0
mirror of synced 2024-09-09 22:16:26 +12:00

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

View file

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