Fix edge cases when saving view calcultion schema
This commit is contained in:
parent
f3b601d294
commit
bf1bf1956a
|
@ -12,7 +12,7 @@
|
||||||
const { definition, datasource, rows } = getContext("grid")
|
const { definition, datasource, rows } = getContext("grid")
|
||||||
const calculationTypeOptions = [
|
const calculationTypeOptions = [
|
||||||
{
|
{
|
||||||
label: "Average (mean)",
|
label: "Average",
|
||||||
value: CalculationType.AVG,
|
value: CalculationType.AVG,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,8 @@
|
||||||
|
|
||||||
// Add calculations
|
// Add calculations
|
||||||
for (let calc of calculations) {
|
for (let calc of calculations) {
|
||||||
const name = `${calc.type} of ${calc.field}`
|
const typeOption = calculationTypeOptions.find(x => x.value === calc.type)
|
||||||
|
const name = `${typeOption.label} ${calc.field}`
|
||||||
schema[name] = {
|
schema[name] = {
|
||||||
calculationType: calc.type,
|
calculationType: calc.type,
|
||||||
field: calc.field,
|
field: calc.field,
|
||||||
|
@ -160,16 +161,16 @@
|
||||||
// Add groupings
|
// Add groupings
|
||||||
for (let grouping of groupings) {
|
for (let grouping of groupings) {
|
||||||
schema[grouping.field] = {
|
schema[grouping.field] = {
|
||||||
|
...$definition.schema[grouping.field],
|
||||||
visible: true,
|
visible: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure primary display is visible
|
// Ensure primary display is valid
|
||||||
let primaryDisplay = $definition.primaryDisplay
|
let primaryDisplay = $definition.primaryDisplay
|
||||||
if (!primaryDisplay || !schema[primaryDisplay]) {
|
if (!primaryDisplay || !schema[primaryDisplay]) {
|
||||||
primaryDisplay = groupings[0]?.field
|
primaryDisplay = groupings[0]?.field
|
||||||
}
|
}
|
||||||
console.log("pd", primaryDisplay, groupings)
|
|
||||||
|
|
||||||
// Save changes
|
// Save changes
|
||||||
await datasource.actions.saveDefinition({
|
await datasource.actions.saveDefinition({
|
||||||
|
|
Loading…
Reference in New Issue