From 159cc9d277d4418a4946a96a831b206532e197c8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 May 2022 15:26:19 +0100 Subject: [PATCH 01/11] Fixes for #4736 - I believe the issue was that the dynamic variables were not being saved, removing the need for the user to be aware of this, also making it possible to pass the entire data structure from one call to another if desired. --- .../_components/DynamicVariableModal.svelte | 4 ++++ .../datasource/[selectedDatasource]/rest/[query]/index.svelte | 1 + packages/string-templates/src/helpers/index.js | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte index 61d0a1993c..5c0cd0f883 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte @@ -1,5 +1,8 @@ diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index e870c2f6db..2baa6aab41 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -299,6 +299,7 @@ {dynamicVariables} bind:binding={varBinding} bind:this={addVariableModal} + on:change={saveQuery} /> {#if query && queryConfig}
diff --git a/packages/string-templates/src/helpers/index.js b/packages/string-templates/src/helpers/index.js index ad4082e3a4..2d5b910847 100644 --- a/packages/string-templates/src/helpers/index.js +++ b/packages/string-templates/src/helpers/index.js @@ -25,7 +25,7 @@ const HELPERS = [ if ( value != null && typeof value === "object" && - value.toString() === "[object Object]" + (value.toString() === "[object Object]" || Array.isArray(value)) ) { return new SafeString(JSON.stringify(value)) } From b4b65362f9a34a92868c4ca8097d78737d1cd08d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 May 2022 16:13:54 +0100 Subject: [PATCH 02/11] Fix for #5669 comment, when using SQL tables with spaces in names, we use a raw knex function for like to achieve lower case searching, this needs to handle spaces in columns and delimiting. --- packages/server/src/integrations/base/sql.ts | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index 2e14eae870..782f61e49e 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -21,6 +21,31 @@ type KnexQuery = Knex.QueryBuilder | Knex const MIN_ISO_DATE = "0000-00-00T00:00:00.000Z" const MAX_ISO_DATE = "9999-00-00T00:00:00.000Z" +function likeKey(client: string, key: string): string { + if (!key.includes(" ")) { + return key + } + let start: string, end: string + switch (client) { + case SqlClients.MY_SQL: + start = end = "`" + break + case SqlClients.ORACLE: + case SqlClients.POSTGRES: + start = end = '"' + break + case SqlClients.MS_SQL: + start = "[" + end = "]" + break + default: + throw "Unknown client" + } + const parts = key.split(".") + key = parts.map(part => `${start}${part}${end}`).join(".") + return key +} + function parse(input: any) { if (Array.isArray(input)) { return JSON.stringify(input) @@ -125,7 +150,9 @@ class InternalBuilder { } else { const rawFnc = `${fnc}Raw` // @ts-ignore - query = query[rawFnc](`LOWER(${key}) LIKE ?`, [`%${value}%`]) + query = query[rawFnc](`LOWER(${likeKey(this.client, key)}) LIKE ?`, [ + `%${value}%`, + ]) } }) } From fb1f941c7673fcb0f765c43066224744e9ab0cb8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 May 2022 16:32:04 +0100 Subject: [PATCH 03/11] Adding to the REST query UI to make it more obvious when it needs saved, such as the user has changed a dynamic variable. --- .../rest/[query]/index.svelte | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 2baa6aab41..d2914146ce 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -37,7 +37,7 @@ import AccessLevelSelect from "components/integration/AccessLevelSelect.svelte" import DynamicVariableModal from "../../_components/DynamicVariableModal.svelte" import Placeholder from "assets/bb-spaceship.svg" - import { cloneDeep } from "lodash/fp" + import { cloneDeep, isEqual } from "lodash/fp" import { RawRestBodyTypes } from "constants/backend" let query, datasource @@ -47,6 +47,7 @@ let response, schema, enabledHeaders let authConfigId let dynamicVariables, addVariableModal, varBinding + let baseQuery, baseDatasource, baseVariables $: datasourceType = datasource?.source $: integrationInfo = $integrations[datasourceType] @@ -62,6 +63,15 @@ $: hasSchema = Object.keys(schema || {}).length !== 0 || Object.keys(query?.schema || {}).length !== 0 + $: baseQuery = !baseQuery ? cloneDeep(query) : baseQuery + $: baseDatasource = !baseDatasource ? cloneDeep(datasource) : baseDatasource + $: baseVariables = !baseVariables + ? cloneDeep(dynamicVariables) + : baseVariables + $: hasChanged = + !isEqual(baseQuery, query) || + !isEqual(baseDatasource, datasource) || + !isEqual(baseVariables, dynamicVariables) function getSelectedQuery() { return cloneDeep( @@ -120,6 +130,9 @@ datasource.config.dynamicVariables = rebuildVariables(saveId) datasource = await datasources.save(datasource) } + baseQuery = query + baseDatasource = datasource + baseVariables = dynamicVariables } catch (err) { notifications.error(`Error saving query`) } @@ -333,7 +346,7 @@