Merge pull request #14072 from Budibase/handle-view-visibility-schema
Handle view visibility schema
This commit is contained in:
commit
c9b2f90af8
|
@ -25,7 +25,9 @@ export async function searchView(
|
||||||
ctx.throw(400, `This method only supports viewsV2`)
|
ctx.throw(400, `This method only supports viewsV2`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const viewFields = Object.keys(view.schema || {})
|
const viewFields = Object.entries(view.schema || {})
|
||||||
|
.filter(([_, value]) => value.visible)
|
||||||
|
.map(([key]) => key)
|
||||||
const { body } = ctx.request
|
const { body } = ctx.request
|
||||||
|
|
||||||
// Enrich saved query with ephemeral query params.
|
// Enrich saved query with ephemeral query params.
|
||||||
|
|
|
@ -33,11 +33,6 @@ async function parseSchema(view: CreateViewRequest) {
|
||||||
p[fieldName] = fieldSchema
|
p[fieldName] = fieldSchema
|
||||||
return p
|
return p
|
||||||
}, {} as Record<string, RequiredKeys<ViewUIFieldMetadata>>)
|
}, {} as Record<string, RequiredKeys<ViewUIFieldMetadata>>)
|
||||||
for (let [key, column] of Object.entries(finalViewSchema)) {
|
|
||||||
if (!column.visible && !column.readonly) {
|
|
||||||
delete finalViewSchema[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return finalViewSchema
|
return finalViewSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,6 +218,10 @@ describe.each([
|
||||||
order: 1,
|
order: 1,
|
||||||
width: 100,
|
width: 100,
|
||||||
},
|
},
|
||||||
|
Category: {
|
||||||
|
visible: false,
|
||||||
|
icon: "ic",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
id: createdView.id,
|
id: createdView.id,
|
||||||
version: 2,
|
version: 2,
|
||||||
|
@ -269,9 +273,8 @@ describe.each([
|
||||||
...newView,
|
...newView,
|
||||||
schema: {
|
schema: {
|
||||||
id: { visible: true },
|
id: { visible: true },
|
||||||
Price: {
|
Price: { visible: true },
|
||||||
visible: true,
|
Category: { visible: false },
|
||||||
},
|
|
||||||
},
|
},
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
version: 2,
|
version: 2,
|
||||||
|
@ -759,6 +762,7 @@ describe.each([
|
||||||
order: 1,
|
order: 1,
|
||||||
width: 100,
|
width: 100,
|
||||||
},
|
},
|
||||||
|
Category: { visible: false, icon: "ic" },
|
||||||
},
|
},
|
||||||
id: view.id,
|
id: view.id,
|
||||||
version: 2,
|
version: 2,
|
||||||
|
@ -873,30 +877,23 @@ describe.each([
|
||||||
await db.getDB(config.appId!).put(tableToUpdate)
|
await db.getDB(config.appId!).put(tableToUpdate)
|
||||||
|
|
||||||
view = await config.api.viewV2.get(view.id)
|
view = await config.api.viewV2.get(view.id)
|
||||||
await config.api.viewV2.update({
|
await config.api.viewV2.update(
|
||||||
...view,
|
{
|
||||||
schema: {
|
...view,
|
||||||
...view.schema,
|
schema: {
|
||||||
Price: {
|
...view.schema,
|
||||||
visible: false,
|
Price: {
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
{
|
||||||
|
status: 400,
|
||||||
expect(await config.api.viewV2.get(view.id)).toEqual(
|
body: {
|
||||||
expect.objectContaining({
|
message: 'You can\'t hide "id" because it is a required field.',
|
||||||
schema: {
|
status: 400,
|
||||||
id: expect.objectContaining({
|
|
||||||
visible: false,
|
|
||||||
}),
|
|
||||||
Price: expect.objectContaining({
|
|
||||||
visible: false,
|
|
||||||
}),
|
|
||||||
Category: expect.objectContaining({
|
|
||||||
visible: true,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -938,7 +935,6 @@ describe.each([
|
||||||
Category: { visible: true },
|
Category: { visible: true },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(res.schema?.Price).toBeUndefined()
|
|
||||||
|
|
||||||
const view = await config.api.viewV2.get(res.id)
|
const view = await config.api.viewV2.get(res.id)
|
||||||
const updatedTable = await config.api.table.get(table._id!)
|
const updatedTable = await config.api.table.get(table._id!)
|
||||||
|
@ -1205,6 +1201,7 @@ describe.each([
|
||||||
],
|
],
|
||||||
schema: {
|
schema: {
|
||||||
id: { visible: true },
|
id: { visible: true },
|
||||||
|
one: { visible: false },
|
||||||
two: { visible: true },
|
two: { visible: true },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -160,14 +160,10 @@ export function enrichSchema(
|
||||||
for (const key of Object.keys(schema)) {
|
for (const key of Object.keys(schema)) {
|
||||||
// if nothing specified in view, then it is not visible
|
// if nothing specified in view, then it is not visible
|
||||||
const ui = view.schema?.[key] || { visible: false }
|
const ui = view.schema?.[key] || { visible: false }
|
||||||
if (ui.visible === false) {
|
schema[key] = {
|
||||||
schema[key].visible = false
|
...schema[key],
|
||||||
} else {
|
...ui,
|
||||||
schema[key] = {
|
order: anyViewOrder ? ui?.order ?? undefined : schema[key].order,
|
||||||
...schema[key],
|
|
||||||
...ui,
|
|
||||||
order: anyViewOrder ? ui?.order ?? undefined : schema[key].order,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue