Walked back previous change. Ensured filtering of global bindings surfaces appropriate values. Filtering logic separated for global and local dynamic variables.

This commit is contained in:
Dean 2022-08-08 10:33:39 +01:00
parent 5909ce62f7
commit de0e8b3d1e
1 changed files with 23 additions and 8 deletions

View File

@ -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"