From 3dac1e2a786512e84661637357c63e232ad2f5e7 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 15 Oct 2020 15:02:22 +0100 Subject: [PATCH] allow users to remove a calculation --- .../src/components/backend/DataTable/ViewDataTable.svelte | 5 ++++- .../backend/DataTable/buttons/CalculateButton.svelte | 6 +++++- .../backend/DataTable/popovers/CalculatePopover.svelte | 1 - packages/server/src/api/controllers/view/viewBuilder.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte index 593030985d..5b56e3d125 100644 --- a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte @@ -9,12 +9,14 @@ export let view = {} let data = [] + let loading = false $: name = view.name // Fetch rows for specified view $: { if (!name.startsWith("all_")) { + loading = true fetchViewData(name, view.field, view.groupBy, view.calculation) } } @@ -31,10 +33,11 @@ const QUERY_VIEW_URL = `/api/views/${name}?${params}` const response = await api.get(QUERY_VIEW_URL) data = await response.json() + loading = false } - +
{#if view.calculation} diff --git a/packages/builder/src/components/backend/DataTable/buttons/CalculateButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/CalculateButton.svelte index efe3dcd79d..0452491247 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/CalculateButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/CalculateButton.svelte @@ -9,7 +9,11 @@
- + Calculate diff --git a/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte b/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte index 1a14e64475..23965a63e0 100644 --- a/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte +++ b/packages/builder/src/components/backend/DataTable/popovers/CalculatePopover.svelte @@ -34,7 +34,6 @@ ) function saveView() { - if (!view.calculation) view.calculation = "stats" backendUiStore.actions.views.save(view) notifier.success(`View ${view.name} saved.`) onClosed() diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 550480d52c..e9fa29856d 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -109,7 +109,7 @@ function viewTemplate({ field, tableId, groupBy, filters = [], calculation }) { const emitExpression = parseEmitExpression(field, groupBy) - const reduction = field ? { reduce: `_${calculation}` } : {} + const reduction = field && calculation ? { reduce: `_${calculation}` } : {} let schema = null