Browse Source
Merge pull request #2260 from Budibase/fix/views-2209
Formulas and relationships in views
gh-pages
Martin McKeaveney
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
23 additions and
9 deletions
-
packages/builder/src/components/backend/DataTable/modals/CalculateModal.svelte
-
packages/builder/src/components/backend/DataTable/modals/GroupByModal.svelte
-
packages/server/src/utilities/rowProcessor.js
|
|
|
@ -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 = [ |
|
|
|
{ |
|
|
|
@ -25,13 +26,16 @@ |
|
|
|
) |
|
|
|
$: 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) |
|
|
|
) |
|
|
|
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) |
|
|
|
|
|
|
|
@ -11,7 +11,11 @@ |
|
|
|
$: 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() { |
|
|
|
|
|
|
|
@ -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) |
|
|
|
|