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