Getting the static formulas being processed on input, not re-processing on output.

This commit is contained in:
mike12345567 2022-01-20 18:04:44 +00:00
parent d66b57a44c
commit 8115f6eef2
5 changed files with 47 additions and 23 deletions

View File

@ -435,18 +435,20 @@
error={errors.relatedName}
/>
{:else if field.type === FORMULA_TYPE}
<Select
label="Formula type"
bind:value={field.formulaType}
options={[
{ label: "Dynamic", value: "dynamic" },
{ label: "Static", value: "static" },
]}
getOptionLabel={option => option.label}
getOptionValue={option => option.value}
tooltip="Dynamic formula are calculated when retrieved, but cannot be filtered,
while static formula are calculated when the row is saved."
/>
{#if !table.sql}
<Select
label="Formula type"
bind:value={field.formulaType}
options={[
{ label: "Dynamic", value: "dynamic" },
{ label: "Static", value: "static" },
]}
getOptionLabel={option => option.label}
getOptionValue={option => option.value}
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"

View File

@ -37,22 +37,30 @@ class QueryBuilder {
}
setLimit(limit) {
this.limit = limit
if (limit != null) {
this.limit = limit
}
return this
}
setSort(sort) {
this.sort = sort
if (sort != null) {
this.sort = sort
}
return this
}
setSortOrder(sortOrder) {
this.sortOrder = sortOrder
if (sortOrder != null) {
this.sortOrder = sortOrder
}
return this
}
setSortType(sortType) {
this.sortType = sortType
if (sortType != null) {
this.sortType = sortType
}
return this
}

View File

@ -58,6 +58,11 @@ exports.RelationshipTypes = {
MANY_TO_MANY: "many-to-many",
}
exports.FormulaTypes = {
STATIC: "static",
DYNAMIC: "dynamic",
}
exports.AuthTypes = {
APP: "app",
BUILDER: "builder",

View File

@ -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)) {

View File

@ -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