From bf1bf1956adc1eba06150b43f9625f86ac494784 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 10 Oct 2024 14:42:52 +0100 Subject: [PATCH] Fix edge cases when saving view calcultion schema --- .../buttons/grid/GridViewCalculationButton.svelte | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte index 6ccabaaf43..f147179bc2 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte @@ -12,7 +12,7 @@ const { definition, datasource, rows } = getContext("grid") const calculationTypeOptions = [ { - label: "Average (mean)", + label: "Average", value: CalculationType.AVG, }, { @@ -149,7 +149,8 @@ // Add 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] = { calculationType: calc.type, field: calc.field, @@ -160,16 +161,16 @@ // Add groupings for (let grouping of groupings) { schema[grouping.field] = { + ...$definition.schema[grouping.field], visible: true, } } - // Ensure primary display is visible + // Ensure primary display is valid let primaryDisplay = $definition.primaryDisplay if (!primaryDisplay || !schema[primaryDisplay]) { primaryDisplay = groupings[0]?.field } - console.log("pd", primaryDisplay, groupings) // Save changes await datasource.actions.saveDefinition({