From 76ce26c6b5b6aed33a01594e9ce560f63bf4acd2 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Jul 2022 11:14:06 +0100 Subject: [PATCH 1/3] Adding more logging to server log for cloud etc. --- packages/server/src/automations/steps/serverLog.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/server/src/automations/steps/serverLog.js b/packages/server/src/automations/steps/serverLog.js index b88a731d56..19bbc36abf 100644 --- a/packages/server/src/automations/steps/serverLog.js +++ b/packages/server/src/automations/steps/serverLog.js @@ -31,15 +31,21 @@ exports.definition = { type: "boolean", description: "Whether the action was successful", }, + message: { + type: "string", + description: "What was output", + }, }, - required: ["success"], + required: ["success", "message"], }, }, } exports.run = async function ({ inputs, appId }) { - console.log(`App ${appId} - ${inputs.text}`) + const message = `App ${appId} - ${inputs.text}` + console.log(message) return { success: true, + message, } } From 348f7e2d1cab20ede39a12586339e962f414b3f4 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Jul 2022 13:39:11 +0100 Subject: [PATCH 2/3] Fixing some issues with automations + lucene filtering (with string templating on the backend) as well as type coercion in the query rows action. --- packages/frontend-core/src/utils/lucene.js | 5 +++- .../server/src/automations/steps/queryRows.js | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/utils/lucene.js b/packages/frontend-core/src/utils/lucene.js index 1001ec26a8..9554c2201a 100644 --- a/packages/frontend-core/src/utils/lucene.js +++ b/packages/frontend-core/src/utils/lucene.js @@ -1,6 +1,8 @@ import { Helpers } from "@budibase/bbui" import { OperatorOptions, SqlNumberTypeRangeMap } from "../constants" +const HBS_REGEX = /{{([^{].*?)}}/g + /** * Returns the valid operator options for a certain data type * @param type the data type @@ -98,6 +100,7 @@ export const buildLuceneQuery = filter => { if (Array.isArray(filter)) { filter.forEach(expression => { let { operator, field, type, value, externalType } = expression + const isHbs = typeof value === "string" && value.match(HBS_REGEX)?.length > 0 // Parse all values into correct types if (type === "datetime" && value) { value = new Date(value).toISOString() @@ -105,7 +108,7 @@ export const buildLuceneQuery = filter => { if (type === "number" && !Array.isArray(value)) { if (operator === "oneOf") { value = value.split(",").map(item => parseFloat(item)) - } else { + } else if (!isHbs) { value = parseFloat(value) } } diff --git a/packages/server/src/automations/steps/queryRows.js b/packages/server/src/automations/steps/queryRows.js index b6d1938995..58e7313dd2 100644 --- a/packages/server/src/automations/steps/queryRows.js +++ b/packages/server/src/automations/steps/queryRows.js @@ -82,6 +82,27 @@ async function getTable(appId, tableId) { return ctx.body } +function typeCoercion(filters, table) { + if (!filters || !table) { + return filters + } + for (let key of Object.keys(filters)) { + if (typeof filters[key] === "object") { + for (let [property, value] of Object.entries(filters[key])) { + const column = table.schema[property] + // convert string inputs + if (!column || typeof value !== "string") { + continue + } + if (column.type === FieldTypes.NUMBER) { + filters[key][property] = parseFloat(value) + } + } + } + } + return filters +} + exports.run = async function ({ inputs, appId }) { const { tableId, filters, sortColumn, sortOrder, limit } = inputs const table = await getTable(appId, tableId) @@ -99,7 +120,7 @@ exports.run = async function ({ inputs, appId }) { sortType, limit, sort: sortColumn, - query: filters || {}, + query: typeCoercion(filters || {}, table), // default to ascending, like data tab sortOrder: sortOrder || SortOrders.ASCENDING, }, From b20ef0c14655404174dcdec3f82096fb4399c565 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 28 Jul 2022 13:40:04 +0100 Subject: [PATCH 3/3] Linting. --- packages/frontend-core/src/utils/lucene.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/utils/lucene.js b/packages/frontend-core/src/utils/lucene.js index 9554c2201a..29c2ca684a 100644 --- a/packages/frontend-core/src/utils/lucene.js +++ b/packages/frontend-core/src/utils/lucene.js @@ -100,7 +100,8 @@ export const buildLuceneQuery = filter => { if (Array.isArray(filter)) { filter.forEach(expression => { let { operator, field, type, value, externalType } = expression - const isHbs = typeof value === "string" && value.match(HBS_REGEX)?.length > 0 + const isHbs = + typeof value === "string" && value.match(HBS_REGEX)?.length > 0 // Parse all values into correct types if (type === "datetime" && value) { value = new Date(value).toISOString()