Merge pull request #2260 from Budibase/fix/views-2209

Formulas and relationships in views
This commit is contained in:
Martin McKeaveney 2021-08-05 16:43:59 +01:00 committed by GitHub
commit 05ec5dc70c
3 changed files with 23 additions and 9 deletions

View File

@ -2,6 +2,7 @@
import { Select, Label, notifications, ModalContent } from "@budibase/bbui" import { Select, Label, notifications, ModalContent } from "@budibase/bbui"
import { tables, views } from "stores/backend" import { tables, views } from "stores/backend"
import analytics from "analytics" import analytics from "analytics"
import { FIELDS } from "constants/backend"
const CALCULATIONS = [ const CALCULATIONS = [
{ {
@ -25,13 +26,16 @@
) )
$: fields = $: fields =
viewTable && viewTable &&
Object.keys(viewTable.schema).filter( Object.keys(viewTable.schema).filter(fieldName => {
field => const field = viewTable.schema[fieldName]
view.calculation === "count" || return (
// don't want to perform calculations based on auto ID field.type !== FIELDS.FORMULA.type &&
(viewTable.schema[field].type === "number" && field.type !== FIELDS.LINK.type &&
!viewTable.schema[field].autocolumn) (view.calculation === "count" ||
) // don't want to perform calculations based on auto ID
(field.type === "number" && !field.autocolumn))
)
})
function saveView() { function saveView() {
views.save(view) views.save(view)

View File

@ -11,7 +11,11 @@
$: fields = $: fields =
viewTable && viewTable &&
Object.entries(viewTable.schema) 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) .map(([key]) => key)
function saveView() { function saveView() {

View File

@ -184,7 +184,13 @@ exports.inputProcessing = (user = {}, table, row) => {
} }
continue 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} // handle auto columns - this returns an object like {table, row}
return processAutoColumn(user, copiedTable, clonedRow) return processAutoColumn(user, copiedTable, clonedRow)