Merge pull request #7116 from Budibase/fix/remove-dynamic-var-filtering

Removed query filtering on dynamic variables in binding drawer
This commit is contained in:
deanhannigan 2022-08-11 12:12:39 +01:00 committed by GitHub
commit bd36d9e16f
1 changed files with 20 additions and 8 deletions

View File

@ -55,13 +55,16 @@
let saveId, url let saveId, url
let response, schema, enabledHeaders let response, schema, enabledHeaders
let authConfigId let authConfigId
let dynamicVariables, addVariableModal, varBinding let dynamicVariables, addVariableModal, varBinding, globalDynamicBindings
let restBindings = getRestBindings() let restBindings = getRestBindings()
$: staticVariables = datasource?.config?.staticVariables || {} $: staticVariables = datasource?.config?.staticVariables || {}
$: customRequestBindings = toBindingsArray(requestBindings, "Binding") $: customRequestBindings = toBindingsArray(requestBindings, "Binding")
$: dynamicRequestBindings = toBindingsArray(dynamicVariables, "Dynamic") $: globalDynamicRequestBindings = toBindingsArray(
globalDynamicBindings,
"Dynamic"
)
$: dataSourceStaticBindings = toBindingsArray( $: dataSourceStaticBindings = toBindingsArray(
staticVariables, staticVariables,
"Datasource.Static" "Datasource.Static"
@ -70,7 +73,7 @@
$: mergedBindings = [ $: mergedBindings = [
...restBindings, ...restBindings,
...customRequestBindings, ...customRequestBindings,
...dynamicRequestBindings, ...globalDynamicRequestBindings,
...dataSourceStaticBindings, ...dataSourceStaticBindings,
] ]
@ -231,11 +234,11 @@
] ]
// convert dynamic variables list to simple key/val object // convert dynamic variables list to simple key/val object
const getDynamicVariables = (datasource, queryId) => { const getDynamicVariables = (datasource, queryId, matchFn) => {
const variablesList = datasource?.config?.dynamicVariables const variablesList = datasource?.config?.dynamicVariables
if (variablesList && variablesList.length > 0) { if (variablesList && variablesList.length > 0) {
const filtered = queryId const filtered = queryId
? variablesList.filter(variable => variable.queryId === queryId) ? variablesList.filter(variable => matchFn(variable, queryId))
: variablesList : variablesList
return filtered.reduce( return filtered.reduce(
(acc, next) => ({ ...acc, [next.name]: next.value }), (acc, next) => ({ ...acc, [next.name]: next.value }),
@ -367,12 +370,21 @@
if (query && !query.fields.pagination) { if (query && !query.fields.pagination) {
query.fields.pagination = {} query.fields.pagination = {}
} }
dynamicVariables = getDynamicVariables(datasource, query._id) dynamicVariables = getDynamicVariables(
datasource,
query._id,
(variable, queryId) => variable.queryId === queryId
)
globalDynamicBindings = getDynamicVariables(
datasource,
query._id,
(variable, queryId) => variable.queryId !== queryId
)
prettifyQueryRequestBody( prettifyQueryRequestBody(
query, query,
requestBindings, requestBindings,
dynamicVariables, globalDynamicBindings,
staticVariables, staticVariables,
restBindings restBindings
) )
@ -437,7 +449,7 @@
valuePlaceholder="Default" valuePlaceholder="Default"
bindings={[ bindings={[
...restBindings, ...restBindings,
...dynamicRequestBindings, ...globalDynamicRequestBindings,
...dataSourceStaticBindings, ...dataSourceStaticBindings,
]} ]}
bindingDrawerLeft="260px" bindingDrawerLeft="260px"