PR comments.

This commit is contained in:
mike12345567 2024-11-18 15:39:55 +00:00
parent 83b1919019
commit 149579cf5c
3 changed files with 12 additions and 3 deletions

View File

@ -387,7 +387,7 @@
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY
} else if (editableColumn.type === FieldType.FORMULA) {
editableColumn.formulaType = "dynamic"
editableColumn.responseType = FIELDS.STRING.type
editableColumn.responseType = field.responseType || FIELDS.STRING.type
}
}
@ -784,7 +784,7 @@
]}
getOptionLabel={option => option.name}
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>

View File

@ -3308,6 +3308,14 @@ datasourceDescribe(
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 &&
it("should coerce a static handlebars formula", async () => {
await updateFormulaColumn(encodeJS("return 1"), {

View File

@ -100,8 +100,9 @@ export async function processFormulas<T extends Row | Row[]>(
const result = processStringSync(formula, context)
try {
return responseType ? coerce(result, responseType) : result
} catch (err) {
} catch (err: any) {
// if the coercion fails, we return empty row contents
span?.addTags({ coercionError: err.message })
return undefined
}
}),