From 56cf236ebfa09f79c64fe434cfa6a170afb84caf Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 Aug 2021 15:22:41 +0100 Subject: [PATCH 1/2] Fix #2209 - views, calculations and group by can't support formula or link fields, making sure these aren't options in the UI. Also fixing an issue where formula values were being saved to DB. --- .../DataTable/modals/CalculateModal.svelte | 15 ++++++++++----- .../backend/DataTable/modals/GroupByModal.svelte | 2 +- packages/server/src/utilities/rowProcessor.js | 8 +++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte b/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte index 8fe753cba8..f3fb1b1984 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte @@ -2,6 +2,7 @@ import { Select, Label, notifications, ModalContent } from "@budibase/bbui" import { tables, views } from "stores/backend" import analytics from "analytics" + import { FIELDS } from "constants/backend" const CALCULATIONS = [ { @@ -26,11 +27,15 @@ $: fields = viewTable && Object.keys(viewTable.schema).filter( - field => - view.calculation === "count" || - // don't want to perform calculations based on auto ID - (viewTable.schema[field].type === "number" && - !viewTable.schema[field].autocolumn) + fieldName => { + const field = viewTable.schema[fieldName] + return field.type !== FIELDS.FORMULA.type && field.type !== FIELDS.LINK.type && + (view.calculation === "count" || + // don't want to perform calculations based on auto ID + (field.type === "number" && + !field.autocolumn)) + } + ) function saveView() { diff --git a/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte b/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte index b566a24ca8..aef6492519 100644 --- a/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte @@ -11,7 +11,7 @@ $: fields = viewTable && Object.entries(viewTable.schema) - .filter(entry => entry[1].type !== FIELDS.LINK.type) + .filter(entry => entry[1].type !== FIELDS.LINK.type && entry[1].type !== FIELDS.FORMULA.type) .map(([key]) => key) function saveView() { diff --git a/packages/server/src/utilities/rowProcessor.js b/packages/server/src/utilities/rowProcessor.js index 766bc09b2f..8467d91c57 100644 --- a/packages/server/src/utilities/rowProcessor.js +++ b/packages/server/src/utilities/rowProcessor.js @@ -184,7 +184,13 @@ exports.inputProcessing = (user = {}, table, row) => { } continue } - clonedRow[key] = exports.coerce(value, field.type) + // specific case to delete formula values if they get saved + // type coercion cannot completely remove the field, so have to do it here + if (field.type === FieldTypes.FORMULA) { + delete clonedRow[key] + } else { + clonedRow[key] = exports.coerce(value, field.type) + } } // handle auto columns - this returns an object like {table, row} return processAutoColumn(user, copiedTable, clonedRow) From b01d50a81c31f093962b02d87e145c327222b377 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 Aug 2021 15:23:26 +0100 Subject: [PATCH 2/2] Linting. --- .../DataTable/modals/CalculateModal.svelte | 21 +++++++++---------- .../DataTable/modals/GroupByModal.svelte | 6 +++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte b/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte index f3fb1b1984..660a822898 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte @@ -26,17 +26,16 @@ ) $: fields = viewTable && - Object.keys(viewTable.schema).filter( - fieldName => { - const field = viewTable.schema[fieldName] - return field.type !== FIELDS.FORMULA.type && field.type !== FIELDS.LINK.type && - (view.calculation === "count" || - // don't want to perform calculations based on auto ID - (field.type === "number" && - !field.autocolumn)) - } - - ) + Object.keys(viewTable.schema).filter(fieldName => { + const field = viewTable.schema[fieldName] + return ( + field.type !== FIELDS.FORMULA.type && + field.type !== FIELDS.LINK.type && + (view.calculation === "count" || + // don't want to perform calculations based on auto ID + (field.type === "number" && !field.autocolumn)) + ) + }) function saveView() { views.save(view) diff --git a/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte b/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte index aef6492519..b0df0ef1da 100644 --- a/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte @@ -11,7 +11,11 @@ $: fields = viewTable && Object.entries(viewTable.schema) - .filter(entry => entry[1].type !== FIELDS.LINK.type && entry[1].type !== FIELDS.FORMULA.type) + .filter( + entry => + entry[1].type !== FIELDS.LINK.type && + entry[1].type !== FIELDS.FORMULA.type + ) .map(([key]) => key) function saveView() {