Fixing issues with query dynamic variables being able to overwrite/appearing in other queries.
This commit is contained in:
parent
d61cb6c037
commit
85aa2c27b5
|
@ -60,9 +60,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Body size="S"
|
<Body size="S"
|
||||||
>Variables enabled you to store and reuse values in queries. Static variables
|
>Variables enable you to store and re-use values in queries, with the choice
|
||||||
use constant values while dynamic values can be bound to the response headers
|
of a static value such as a token using static variables, or a value from a
|
||||||
or body of a query</Body
|
query response using dynamic variables.</Body
|
||||||
>
|
>
|
||||||
<Heading size="XS">Static</Heading>
|
<Heading size="XS">Static</Heading>
|
||||||
<Layout noPadding gap="XS">
|
<Layout noPadding gap="XS">
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
<Heading size="XS">Dynamic</Heading>
|
<Heading size="XS">Dynamic</Heading>
|
||||||
<Body size="S">
|
<Body size="S">
|
||||||
Dynamic variables are evaluated when a dependant query is executed. The value
|
Dynamic variables are evaluated when a dependant query is executed. The value
|
||||||
is cached for 24 hours and will re-evaluate if the dependendent query fails.
|
is cached for a period of time and will be refreshed if a query fails.
|
||||||
</Body>
|
</Body>
|
||||||
<ViewDynamicVariables {queries} {datasource} />
|
<ViewDynamicVariables {queries} {datasource} />
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,13 @@ export function flipHeaderState(headersActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert dynamic variables list to simple key/val object
|
// convert dynamic variables list to simple key/val object
|
||||||
export function variablesToObject(datasource) {
|
export function getDynamicVariables(datasource, queryId) {
|
||||||
const variablesList = datasource?.config?.dynamicVariables
|
const variablesList = datasource?.config?.dynamicVariables
|
||||||
if (variablesList && variablesList.length > 0) {
|
if (variablesList && variablesList.length > 0) {
|
||||||
return variablesList.reduce(
|
const filtered = queryId
|
||||||
|
? variablesList.filter(variable => variable.queryId === queryId)
|
||||||
|
: variablesList
|
||||||
|
return filtered.reduce(
|
||||||
(acc, next) => ({ ...acc, [next.name]: next.value }),
|
(acc, next) => ({ ...acc, [next.name]: next.value }),
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
@ -133,10 +136,10 @@ export function variablesToObject(datasource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert dynamic variables object back to a list, enrich with query id
|
// convert dynamic variables object back to a list, enrich with query id
|
||||||
export function rebuildVariables(queryId, variables) {
|
export function rebuildVariables(datasource, queryId, variables) {
|
||||||
let vars = []
|
let finalVars = []
|
||||||
if (variables) {
|
if (variables) {
|
||||||
vars = Object.entries(variables).map(entry => {
|
finalVars = Object.entries(variables).map(entry => {
|
||||||
return {
|
return {
|
||||||
name: entry[0],
|
name: entry[0],
|
||||||
value: entry[1],
|
value: entry[1],
|
||||||
|
@ -144,7 +147,7 @@ export function rebuildVariables(queryId, variables) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return vars
|
return [...(datasource?.config?.dynamicVariables || []), ...finalVars]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldShowVariables(dynamicVariables, variablesReadOnly) {
|
export function shouldShowVariables(dynamicVariables, variablesReadOnly) {
|
||||||
|
@ -173,7 +176,7 @@ export default {
|
||||||
keyValueToQueryParameters,
|
keyValueToQueryParameters,
|
||||||
queryParametersToKeyValue,
|
queryParametersToKeyValue,
|
||||||
schemaToFields,
|
schemaToFields,
|
||||||
variablesToObject,
|
getDynamicVariables,
|
||||||
rebuildVariables,
|
rebuildVariables,
|
||||||
shouldShowVariables,
|
shouldShowVariables,
|
||||||
buildAuthConfigs,
|
buildAuthConfigs,
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
import { Input, ModalContent, Modal } from "@budibase/bbui"
|
import { Input, ModalContent, Modal } from "@budibase/bbui"
|
||||||
|
|
||||||
export let dynamicVariables
|
export let dynamicVariables
|
||||||
|
export let datasource
|
||||||
export let binding
|
export let binding
|
||||||
|
|
||||||
let name, modal, valid
|
let name, modal, valid, allVariableNames
|
||||||
|
|
||||||
export const show = () => {
|
export const show = () => {
|
||||||
modal.show()
|
modal.show()
|
||||||
|
@ -17,11 +18,15 @@
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const varKeys = Object.keys(vars || {})
|
return !allVariableNames.find(
|
||||||
return varKeys.find(key => key.toLowerCase() === name.toLowerCase()) == null
|
varName => varName.toLowerCase() === name.toLowerCase()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
$: valid = checkValid(dynamicVariables, name)
|
$: valid = checkValid(dynamicVariables, name)
|
||||||
|
$: allVariableNames = (datasource?.config?.dynamicVariables || []).map(
|
||||||
|
variable => variable.name
|
||||||
|
)
|
||||||
$: error = name && !valid ? "Variable name is already in use." : null
|
$: error = name && !valid ? "Variable name is already in use." : null
|
||||||
|
|
||||||
async function saveVariable() {
|
async function saveVariable() {
|
||||||
|
|
|
@ -116,6 +116,7 @@
|
||||||
|
|
||||||
if (dynamicVariables) {
|
if (dynamicVariables) {
|
||||||
datasource.config.dynamicVariables = restUtils.rebuildVariables(
|
datasource.config.dynamicVariables = restUtils.rebuildVariables(
|
||||||
|
datasource,
|
||||||
saveId,
|
saveId,
|
||||||
dynamicVariables
|
dynamicVariables
|
||||||
)
|
)
|
||||||
|
@ -213,7 +214,7 @@
|
||||||
if (query && !query.fields.bodyType) {
|
if (query && !query.fields.bodyType) {
|
||||||
query.fields.bodyType = "none"
|
query.fields.bodyType = "none"
|
||||||
}
|
}
|
||||||
dynamicVariables = restUtils.variablesToObject(datasource)
|
dynamicVariables = restUtils.getDynamicVariables(datasource, query._id)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -396,9 +397,10 @@
|
||||||
{#if showVariablesTab}
|
{#if showVariablesTab}
|
||||||
<Tab title="Dynamic Variables">
|
<Tab title="Dynamic Variables">
|
||||||
<Layout noPadding gap="S">
|
<Layout noPadding gap="S">
|
||||||
<Body size="S"
|
<Body size="S">
|
||||||
>{"Create dynamic variables to use body and headers results in other queries"}</Body
|
Create dynamic variables based on response body or headers
|
||||||
>
|
from other queries.
|
||||||
|
</Body>
|
||||||
<KeyValueBuilder
|
<KeyValueBuilder
|
||||||
bind:object={dynamicVariables}
|
bind:object={dynamicVariables}
|
||||||
name="Variable"
|
name="Variable"
|
||||||
|
|
Loading…
Reference in New Issue