Parse view v1 schema to fix builder crashed caused by 'groupedby' views

This commit is contained in:
Dean 2023-10-20 15:35:16 +01:00
parent 0010e07b47
commit 871891c2a2
2 changed files with 39 additions and 21 deletions

View File

@ -24,17 +24,21 @@
let selectedRows = []
let customRenderers = []
let parsedSchema = {}
$: if (schema) {
parsedSchema = Object.keys(schema).reduce((acc, key) => {
acc[key] = { ...schema[key] }
if (!canBeSortColumn(acc[key].type)) {
acc[key].sortable = false
}
return acc
}, {})
}
$: selectedRows, dispatch("selectionUpdated", selectedRows)
$: isUsersTable = tableId === TableNames.USERS
$: data && resetSelectedRows()
$: {
Object.values(schema || {}).forEach(col => {
if (!canBeSortColumn(col.type)) {
col.sortable = false
}
})
}
$: {
if (isUsersTable) {
customRenderers = [
@ -44,24 +48,24 @@
},
]
UNEDITABLE_USER_FIELDS.forEach(field => {
if (schema[field]) {
schema[field].editable = false
if (parsedSchema[field]) {
parsedSchema[field].editable = false
}
})
if (schema.email) {
schema.email.displayName = "Email"
if (parsedSchema.email) {
parsedSchema.email.displayName = "Email"
}
if (schema.roleId) {
schema.roleId.displayName = "Role"
if (parsedSchema.roleId) {
parsedSchema.roleId.displayName = "Role"
}
if (schema.firstName) {
schema.firstName.displayName = "First Name"
if (parsedSchema.firstName) {
parsedSchema.firstName.displayName = "First Name"
}
if (schema.lastName) {
schema.lastName.displayName = "Last Name"
if (parsedSchema.lastName) {
parsedSchema.lastName.displayName = "Last Name"
}
if (schema.status) {
schema.status.displayName = "Status"
if (parsedSchema.status) {
parsedSchema.status.displayName = "Status"
}
}
}
@ -97,7 +101,7 @@
<div class="table-wrapper">
<Table
{data}
{schema}
schema={parsedSchema}
{loading}
{customRenderers}
{rowCount}

View File

@ -19,7 +19,21 @@
let loading = false
let type = "internal"
// Grouped views have a fixed schema layout
const parseSchema = view => {
if (!view.groupBy) {
return view.schema
}
const { group, field, value } = view.schema
return {
group,
field: { type: field },
value: { type: value },
}
}
$: name = view.name
$: schema = parseSchema(view)
$: calculation = view.calculation
$: supportedFormats = Object.values(ROW_EXPORT_FORMATS).filter(key => {
@ -61,7 +75,7 @@
<Table
title={decodeURI(name)}
schema={view.schema}
{schema}
tableId={view.tableId}
{data}
{loading}