Getting the static formulas being processed on input, not re-processing on output.
This commit is contained in:
parent
d565819494
commit
50eff577f9
|
@ -435,6 +435,7 @@
|
|||
error={errors.relatedName}
|
||||
/>
|
||||
{:else if field.type === FORMULA_TYPE}
|
||||
{#if !table.sql}
|
||||
<Select
|
||||
label="Formula type"
|
||||
bind:value={field.formulaType}
|
||||
|
@ -447,6 +448,7 @@
|
|||
tooltip="Dynamic formula are calculated when retrieved, but cannot be filtered,
|
||||
while static formula are calculated when the row is saved."
|
||||
/>
|
||||
{/if}
|
||||
<ModalBindableInput
|
||||
title="Formula"
|
||||
label="Formula"
|
||||
|
|
|
@ -37,22 +37,30 @@ class QueryBuilder {
|
|||
}
|
||||
|
||||
setLimit(limit) {
|
||||
if (limit != null) {
|
||||
this.limit = limit
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
setSort(sort) {
|
||||
if (sort != null) {
|
||||
this.sort = sort
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
setSortOrder(sortOrder) {
|
||||
if (sortOrder != null) {
|
||||
this.sortOrder = sortOrder
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
setSortType(sortType) {
|
||||
if (sortType != null) {
|
||||
this.sortType = sortType
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ exports.RelationshipTypes = {
|
|||
MANY_TO_MANY: "many-to-many",
|
||||
}
|
||||
|
||||
exports.FormulaTypes = {
|
||||
STATIC: "static",
|
||||
DYNAMIC: "dynamic",
|
||||
}
|
||||
|
||||
exports.AuthTypes = {
|
||||
APP: "app",
|
||||
BUILDER: "builder",
|
||||
|
|
|
@ -229,11 +229,12 @@ exports.inputProcessing = (
|
|||
}
|
||||
continue
|
||||
}
|
||||
// specific case to delete formula values if they get saved
|
||||
// type coercion cannot completely remove the field, so have to do it here
|
||||
// remove any formula values, they are to be generated
|
||||
if (field.type === FieldTypes.FORMULA) {
|
||||
delete clonedRow[key]
|
||||
} else {
|
||||
}
|
||||
// otherwise coerce what is there to correct types
|
||||
else {
|
||||
clonedRow[key] = exports.coerce(value, field.type)
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +244,9 @@ exports.inputProcessing = (
|
|||
clonedRow._rev = row._rev
|
||||
}
|
||||
|
||||
// now process the static formulas
|
||||
clonedRow = processFormulas(table, clonedRow, { dynamic: false })
|
||||
|
||||
// handle auto columns - this returns an object like {table, row}
|
||||
return processAutoColumn(user, copiedTable, clonedRow, opts)
|
||||
}
|
||||
|
@ -273,7 +277,7 @@ exports.outputProcessing = async (
|
|||
let enriched = await linkRows.attachFullLinkedDocs(ctx, table, rows)
|
||||
|
||||
// process formulas
|
||||
enriched = processFormulas(table, enriched)
|
||||
enriched = processFormulas(table, enriched, { dynamic: true })
|
||||
|
||||
// update the attachments URL depending on hosting
|
||||
for (let [property, column] of Object.entries(table.schema)) {
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
const { FieldTypes } = require("../../constants")
|
||||
const { FieldTypes, FormulaTypes } = require("../../constants")
|
||||
const { processStringSync } = require("@budibase/string-templates")
|
||||
|
||||
/**
|
||||
* Looks through the rows provided and finds formulas - which it then processes.
|
||||
*/
|
||||
exports.processFormulas = (table, rows) => {
|
||||
exports.processFormulas = (table, rows, { dynamic } = { dynamic: true }) => {
|
||||
const single = !Array.isArray(rows)
|
||||
if (single) {
|
||||
rows = [rows]
|
||||
}
|
||||
for (let [column, schema] of Object.entries(table.schema)) {
|
||||
if (schema.type !== FieldTypes.FORMULA) {
|
||||
const isStatic = schema.formulaType === FormulaTypes.STATIC
|
||||
if (
|
||||
schema.type !== FieldTypes.FORMULA ||
|
||||
(dynamic && isStatic) ||
|
||||
(!dynamic && !isStatic)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
// iterate through rows and process formula
|
||||
|
|
Loading…
Reference in New Issue