From 5909ce62f7fac1281defe9b26830d2a1c9b08cef Mon Sep 17 00:00:00 2001 From: Dean Date: Fri, 5 Aug 2022 15:16:04 +0100 Subject: [PATCH 1/2] Removed query filtering on dynamic variables in binding drawer --- .../[selectedDatasource]/rest/[query]/index.svelte | 9 +++------ 1 file changed, 3 insertions(+), 6 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 5ccc173318..8ecd88243e 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 @@ -231,13 +231,10 @@ ] // convert dynamic variables list to simple key/val object - const getDynamicVariables = (datasource, queryId) => { + const getDynamicVariables = datasource => { const variablesList = datasource?.config?.dynamicVariables if (variablesList && variablesList.length > 0) { - const filtered = queryId - ? variablesList.filter(variable => variable.queryId === queryId) - : variablesList - return filtered.reduce( + return variablesList.reduce( (acc, next) => ({ ...acc, [next.name]: next.value }), {} ) @@ -367,7 +364,7 @@ if (query && !query.fields.pagination) { query.fields.pagination = {} } - dynamicVariables = getDynamicVariables(datasource, query._id) + dynamicVariables = getDynamicVariables(datasource) prettifyQueryRequestBody( query, From de0e8b3d1e50125a89edb54ef66f5903581d1418 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 8 Aug 2022 10:33:39 +0100 Subject: [PATCH 2/2] Walked back previous change. Ensured filtering of global bindings surfaces appropriate values. Filtering logic separated for global and local dynamic variables. --- .../rest/[query]/index.svelte | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 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 8ecd88243e..b0a93f8eec 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 @@ -55,13 +55,16 @@ let saveId, url let response, schema, enabledHeaders let authConfigId - let dynamicVariables, addVariableModal, varBinding + let dynamicVariables, addVariableModal, varBinding, globalDynamicBindings let restBindings = getRestBindings() $: staticVariables = datasource?.config?.staticVariables || {} $: customRequestBindings = toBindingsArray(requestBindings, "Binding") - $: dynamicRequestBindings = toBindingsArray(dynamicVariables, "Dynamic") + $: globalDynamicRequestBindings = toBindingsArray( + globalDynamicBindings, + "Dynamic" + ) $: dataSourceStaticBindings = toBindingsArray( staticVariables, "Datasource.Static" @@ -70,7 +73,7 @@ $: mergedBindings = [ ...restBindings, ...customRequestBindings, - ...dynamicRequestBindings, + ...globalDynamicRequestBindings, ...dataSourceStaticBindings, ] @@ -231,10 +234,13 @@ ] // convert dynamic variables list to simple key/val object - const getDynamicVariables = datasource => { + const getDynamicVariables = (datasource, queryId, matchFn) => { const variablesList = datasource?.config?.dynamicVariables if (variablesList && variablesList.length > 0) { - return variablesList.reduce( + const filtered = queryId + ? variablesList.filter(variable => matchFn(variable, queryId)) + : variablesList + return filtered.reduce( (acc, next) => ({ ...acc, [next.name]: next.value }), {} ) @@ -364,12 +370,21 @@ if (query && !query.fields.pagination) { query.fields.pagination = {} } - dynamicVariables = getDynamicVariables(datasource) + dynamicVariables = getDynamicVariables( + datasource, + query._id, + (variable, queryId) => variable.queryId === queryId + ) + globalDynamicBindings = getDynamicVariables( + datasource, + query._id, + (variable, queryId) => variable.queryId !== queryId + ) prettifyQueryRequestBody( query, requestBindings, - dynamicVariables, + globalDynamicBindings, staticVariables, restBindings ) @@ -434,7 +449,7 @@ valuePlaceholder="Default" bindings={[ ...restBindings, - ...dynamicRequestBindings, + ...globalDynamicRequestBindings, ...dataSourceStaticBindings, ]} bindingDrawerLeft="260px"