From 4db2ee1843268d64098c7b9b5ec7a83a685c2e7b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 11 May 2021 18:33:25 +0100 Subject: [PATCH] Allow data provider filtering using dates and date ranges, and allow filtering using a value or binding for any type --- packages/bbui/src/Form/Core/Combobox.svelte | 2 -- packages/builder/src/actions.js | 6 +++-- .../FilterEditor/FilterBuilder.svelte | 14 +++++++++-- .../src/api/controllers/search/utils.js | 6 ++--- .../src/DataProvider.svelte | 25 ++++++++++--------- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/packages/bbui/src/Form/Core/Combobox.svelte b/packages/bbui/src/Form/Core/Combobox.svelte index 2a5b2b7cf4..e5346ed9a8 100644 --- a/packages/bbui/src/Form/Core/Combobox.svelte +++ b/packages/bbui/src/Form/Core/Combobox.svelte @@ -43,8 +43,6 @@ const onChange = e => { selectOption(e.target.value) } - - $: console.log(disabled)
{ lightness: 0.7, softness: 0.9, seed: null, + version: null, } // Applies a gradient background @@ -15,6 +16,7 @@ export const gradient = (node, config = {}) => { } const { saturation, lightness, softness, points } = config const seed = config.seed || Math.random().toString(32).substring(2) + const version = config.version ?? 0 // Hash function which returns a fixed hash between specified limits // for a given seed and a given version @@ -69,10 +71,10 @@ export const gradient = (node, config = {}) => { ) } - let css = `opacity:0.9;background:${randomHSL(seed, 0, 0.7)};` + let css = `opacity:0.9;background:${randomHSL(seed, version, 0.7)};` css += "background-image:" for (let i = 0; i < points - 1; i++) { - css += `${randomGradientPoint(seed, i)},` + css += `${randomGradientPoint(seed, version + i)},` } css += `${randomGradientPoint(seed, points)};` node.style = css diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterBuilder.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterBuilder.svelte index 7afbaa5b7d..5017d39d41 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterBuilder.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterBuilder.svelte @@ -5,6 +5,7 @@ Button, Select, Combobox, + Input, } from "@budibase/bbui" import { store, currentAsset } from "builderStore" import { getBindableProperties } from "builderStore/dataBinding" @@ -68,6 +69,7 @@ field: null, operator: OperatorOptions.Equals.value, value: null, + valueType: "Value", }, ] } @@ -168,7 +170,13 @@ on:change={e => onOperatorChange(expression, e.detail)} placeholder={null} /> - {#if ["string", "longform", "number"].includes(expression.type)} + {:else if expression.type === "options"} diff --git a/packages/server/src/api/controllers/search/utils.js b/packages/server/src/api/controllers/search/utils.js index 7827850428..3310f89bf7 100644 --- a/packages/server/src/api/controllers/search/utils.js +++ b/packages/server/src/api/controllers/search/utils.js @@ -39,7 +39,6 @@ function buildSearchUrl({ if (bookmark) { url += `&bookmark=${bookmark}` } - console.log(url) return checkSlashesInUrl(url) } @@ -142,13 +141,12 @@ class QueryBuilder { if (!value) { return null } - if (isNaN(value.low) || value.low == null || value.low === "") { + if (value.low == null || value.low === "") { return null } - if (isNaN(value.high) || value.high == null || value.high === "") { + if (value.high == null || value.high === "") { return null } - console.log(value) return `${key}:[${value.low} TO ${value.high}]` }) } diff --git a/packages/standard-components/src/DataProvider.svelte b/packages/standard-components/src/DataProvider.svelte index 38dd9f3955..512a4c594d 100644 --- a/packages/standard-components/src/DataProvider.svelte +++ b/packages/standard-components/src/DataProvider.svelte @@ -83,20 +83,21 @@ notEmpty: {}, } if (Array.isArray(filter)) { - filter.forEach(expression => { - if (expression.operator.startsWith("range")) { - let range = { - low: Number.MIN_SAFE_INTEGER, - high: Number.MAX_SAFE_INTEGER, + filter.forEach(({ operator, field, type, value }) => { + if (operator.startsWith("range")) { + if (!query.range[field]) { + query.range[field] = { + low: type === "number" ? Number.MIN_SAFE_INTEGER : "0000", + high: type === "number" ? Number.MAX_SAFE_INTEGER : "9999", + } } - if (expression.operator === "rangeLow") { - range.low = expression.value - } else if (expression.operator === "rangeHigh") { - range.high = expression.value + if (operator === "rangeLow") { + query.range[field].low = value + } else if (operator === "rangeHigh") { + query.range[field].high = value } - query.range[expression.field] = range - } else if (query[expression.operator]) { - query[expression.operator][expression.field] = expression.value + } else if (query[operator]) { + query[operator][field] = value } }) }