PR comments.
This commit is contained in:
parent
83b1919019
commit
149579cf5c
|
@ -387,7 +387,7 @@
|
||||||
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY
|
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY
|
||||||
} else if (editableColumn.type === FieldType.FORMULA) {
|
} else if (editableColumn.type === FieldType.FORMULA) {
|
||||||
editableColumn.formulaType = "dynamic"
|
editableColumn.formulaType = "dynamic"
|
||||||
editableColumn.responseType = FIELDS.STRING.type
|
editableColumn.responseType = field.responseType || FIELDS.STRING.type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,7 +784,7 @@
|
||||||
]}
|
]}
|
||||||
getOptionLabel={option => option.name}
|
getOptionLabel={option => option.name}
|
||||||
getOptionValue={option => option.type}
|
getOptionValue={option => option.type}
|
||||||
tooltip="Formulas by default will return a string - however if you need a native type the response can be coerced."
|
tooltip="Formulas by default will return a string - however if you need a another type the response can be coerced."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3308,6 +3308,14 @@ datasourceDescribe(
|
||||||
expect(rows[0].formula).toBe(2)
|
expect(rows[0].formula).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should coerce handlebars to string (default)", async () => {
|
||||||
|
await updateFormulaColumn("{{ add 1 1 }}", {
|
||||||
|
responseType: FieldType.STRING,
|
||||||
|
})
|
||||||
|
const { rows } = await config.api.row.search(table._id!)
|
||||||
|
expect(rows[0].formula).toBe("2")
|
||||||
|
})
|
||||||
|
|
||||||
isInternal &&
|
isInternal &&
|
||||||
it("should coerce a static handlebars formula", async () => {
|
it("should coerce a static handlebars formula", async () => {
|
||||||
await updateFormulaColumn(encodeJS("return 1"), {
|
await updateFormulaColumn(encodeJS("return 1"), {
|
||||||
|
|
|
@ -100,8 +100,9 @@ export async function processFormulas<T extends Row | Row[]>(
|
||||||
const result = processStringSync(formula, context)
|
const result = processStringSync(formula, context)
|
||||||
try {
|
try {
|
||||||
return responseType ? coerce(result, responseType) : result
|
return responseType ? coerce(result, responseType) : result
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
// if the coercion fails, we return empty row contents
|
// if the coercion fails, we return empty row contents
|
||||||
|
span?.addTags({ coercionError: err.message })
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue