Render view groupBy array options as tags (#8764)
* Fix to properly render groupBy options as tags * Fixes for viewBuilder function definition and some typescript updates
This commit is contained in:
parent
7e00976f95
commit
79fa4e42c2
|
@ -316,7 +316,13 @@ export async function checkForViewUpdates(
|
||||||
|
|
||||||
// Update view if required
|
// Update view if required
|
||||||
if (needsUpdated) {
|
if (needsUpdated) {
|
||||||
const newViewTemplate = viewTemplate(view.meta)
|
const groupByField: any = Object.values(table.schema).find(
|
||||||
|
(field: any) => field.name == view.groupBy
|
||||||
|
)
|
||||||
|
const newViewTemplate = viewTemplate(
|
||||||
|
view.meta,
|
||||||
|
groupByField?.type === FieldTypes.ARRAY
|
||||||
|
)
|
||||||
await saveView(null, view.name, newViewTemplate)
|
await saveView(null, view.name, newViewTemplate)
|
||||||
if (!newViewTemplate.meta.schema) {
|
if (!newViewTemplate.meta.schema) {
|
||||||
newViewTemplate.meta.schema = table.schema
|
newViewTemplate.meta.schema = table.schema
|
||||||
|
|
|
@ -25,7 +25,15 @@ export async function fetch(ctx: BBContext) {
|
||||||
export async function save(ctx: BBContext) {
|
export async function save(ctx: BBContext) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const { originalName, ...viewToSave } = ctx.request.body
|
const { originalName, ...viewToSave } = ctx.request.body
|
||||||
const view = viewTemplate(viewToSave)
|
|
||||||
|
const existingTable = await db.get(ctx.request.body.tableId)
|
||||||
|
const table = cloneDeep(existingTable)
|
||||||
|
|
||||||
|
const groupByField: any = Object.values(table.schema).find(
|
||||||
|
(field: any) => field.name == viewToSave.groupBy
|
||||||
|
)
|
||||||
|
|
||||||
|
const view = viewTemplate(viewToSave, groupByField?.type === FieldTypes.ARRAY)
|
||||||
const viewName = viewToSave.name
|
const viewName = viewToSave.name
|
||||||
|
|
||||||
if (!viewName) {
|
if (!viewName) {
|
||||||
|
@ -35,8 +43,6 @@ export async function save(ctx: BBContext) {
|
||||||
await saveView(originalName, viewName, view)
|
await saveView(originalName, viewName, view)
|
||||||
|
|
||||||
// add views to table document
|
// add views to table document
|
||||||
const existingTable = await db.get(ctx.request.body.tableId)
|
|
||||||
const table = cloneDeep(existingTable)
|
|
||||||
if (!table.views) table.views = {}
|
if (!table.views) table.views = {}
|
||||||
if (!view.meta.schema) {
|
if (!view.meta.schema) {
|
||||||
view.meta.schema = table.schema
|
view.meta.schema = table.schema
|
||||||
|
|
|
@ -6,6 +6,7 @@ type ViewTemplateOpts = {
|
||||||
groupBy: string
|
groupBy: string
|
||||||
filters: ViewFilter[]
|
filters: ViewFilter[]
|
||||||
calculation: string
|
calculation: string
|
||||||
|
groupByMulti: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const TOKEN_MAP: Record<string, string> = {
|
const TOKEN_MAP: Record<string, string> = {
|
||||||
|
@ -41,6 +42,12 @@ const GROUP_PROPERTY: Record<string, { type: string }> = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GROUP_PROPERTY_MULTI: Record<string, { type: string }> = {
|
||||||
|
group: {
|
||||||
|
type: "array",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const FIELD_PROPERTY: Record<string, { type: string }> = {
|
const FIELD_PROPERTY: Record<string, { type: string }> = {
|
||||||
field: {
|
field: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
@ -136,13 +143,10 @@ function parseEmitExpression(field: string, groupBy: string) {
|
||||||
* filters: Array of filter objects containing predicates that are parsed into a JS expression
|
* filters: Array of filter objects containing predicates that are parsed into a JS expression
|
||||||
* calculation: an optional calculation to be performed over the view data.
|
* calculation: an optional calculation to be performed over the view data.
|
||||||
*/
|
*/
|
||||||
export = function ({
|
export = function (
|
||||||
field,
|
{ field, tableId, groupBy, filters = [], calculation }: ViewTemplateOpts,
|
||||||
tableId,
|
groupByMulti?: boolean
|
||||||
groupBy,
|
) {
|
||||||
filters = [],
|
|
||||||
calculation,
|
|
||||||
}: ViewTemplateOpts) {
|
|
||||||
// first filter can't have a conjunction
|
// first filter can't have a conjunction
|
||||||
if (filters && filters.length > 0 && filters[0].conjunction) {
|
if (filters && filters.length > 0 && filters[0].conjunction) {
|
||||||
delete filters[0].conjunction
|
delete filters[0].conjunction
|
||||||
|
@ -151,9 +155,11 @@ export = function ({
|
||||||
let schema = null,
|
let schema = null,
|
||||||
statFilter = null
|
statFilter = null
|
||||||
|
|
||||||
|
let groupBySchema = groupByMulti ? GROUP_PROPERTY_MULTI : GROUP_PROPERTY
|
||||||
|
|
||||||
if (calculation) {
|
if (calculation) {
|
||||||
schema = {
|
schema = {
|
||||||
...(groupBy ? GROUP_PROPERTY : FIELD_PROPERTY),
|
...(groupBy ? groupBySchema : FIELD_PROPERTY),
|
||||||
...SCHEMA_MAP[calculation],
|
...SCHEMA_MAP[calculation],
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Reference in New Issue