Merge branch 'master' of github.com:Budibase/budibase into develop
This commit is contained in:
commit
c723deded3
|
@ -1,6 +1,8 @@
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { OperatorOptions, SqlNumberTypeRangeMap } from "../constants"
|
import { OperatorOptions, SqlNumberTypeRangeMap } from "../constants"
|
||||||
|
|
||||||
|
const HBS_REGEX = /{{([^{].*?)}}/g
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the valid operator options for a certain data type
|
* Returns the valid operator options for a certain data type
|
||||||
* @param type the data type
|
* @param type the data type
|
||||||
|
@ -98,6 +100,8 @@ export const buildLuceneQuery = filter => {
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
filter.forEach(expression => {
|
filter.forEach(expression => {
|
||||||
let { operator, field, type, value, externalType } = 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
|
// Parse all values into correct types
|
||||||
if (type === "datetime") {
|
if (type === "datetime") {
|
||||||
// Ensure date value is a valid date and parse into correct format
|
// Ensure date value is a valid date and parse into correct format
|
||||||
|
@ -113,7 +117,7 @@ export const buildLuceneQuery = filter => {
|
||||||
if (type === "number" && !Array.isArray(value)) {
|
if (type === "number" && !Array.isArray(value)) {
|
||||||
if (operator === "oneOf") {
|
if (operator === "oneOf") {
|
||||||
value = value.split(",").map(item => parseFloat(item))
|
value = value.split(",").map(item => parseFloat(item))
|
||||||
} else {
|
} else if (!isHbs) {
|
||||||
value = parseFloat(value)
|
value = parseFloat(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,27 @@ async function getTable(appId, tableId) {
|
||||||
return ctx.body
|
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 }) {
|
exports.run = async function ({ inputs, appId }) {
|
||||||
const { tableId, filters, sortColumn, sortOrder, limit } = inputs
|
const { tableId, filters, sortColumn, sortOrder, limit } = inputs
|
||||||
const table = await getTable(appId, tableId)
|
const table = await getTable(appId, tableId)
|
||||||
|
@ -99,7 +120,7 @@ exports.run = async function ({ inputs, appId }) {
|
||||||
sortType,
|
sortType,
|
||||||
limit,
|
limit,
|
||||||
sort: sortColumn,
|
sort: sortColumn,
|
||||||
query: filters || {},
|
query: typeCoercion(filters || {}, table),
|
||||||
// default to ascending, like data tab
|
// default to ascending, like data tab
|
||||||
sortOrder: sortOrder || SortOrders.ASCENDING,
|
sortOrder: sortOrder || SortOrders.ASCENDING,
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,15 +31,21 @@ exports.definition = {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
description: "Whether the action was successful",
|
description: "Whether the action was successful",
|
||||||
},
|
},
|
||||||
|
message: {
|
||||||
|
type: "string",
|
||||||
|
description: "What was output",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
required: ["success"],
|
required: ["success", "message"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.run = async function ({ inputs, appId }) {
|
exports.run = async function ({ inputs, appId }) {
|
||||||
console.log(`App ${appId} - ${inputs.text}`)
|
const message = `App ${appId} - ${inputs.text}`
|
||||||
|
console.log(message)
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue