Improve view calculation configuration

This commit is contained in:
Andrew Kingston 2024-10-10 14:37:10 +01:00
parent c128372c70
commit f3b601d294
No known key found for this signature in database
1 changed files with 19 additions and 1 deletions

View File

@ -125,6 +125,11 @@
const deleteCalc = idx => {
calculations = calculations.toSpliced(idx, 1)
// Remove any groupings if clearing the last calculation
if (!calculations.length) {
groupings = []
}
}
const addGrouping = () => {
@ -138,6 +143,10 @@
const save = async () => {
let schema = {}
// Prune empty stuff
calculations = calculations.filter(calc => calc.type && calc.field)
groupings = groupings.filter(grouping => grouping.field)
// Add calculations
for (let calc of calculations) {
const name = `${calc.type} of ${calc.field}`
@ -154,9 +163,18 @@
visible: true,
}
}
// Ensure primary display is visible
let primaryDisplay = $definition.primaryDisplay
if (!primaryDisplay || !schema[primaryDisplay]) {
primaryDisplay = groupings[0]?.field
}
console.log("pd", primaryDisplay, groupings)
// Save changes
await datasource.actions.saveDefinition({
...$definition,
primaryDisplay: null,
primaryDisplay,
schema,
})
await rows.actions.refreshData()