1
0
Fork 0
mirror of synced 2024-10-03 10:36:59 +13:00

Some minor UI tweaks.

This commit is contained in:
mike12345567 2021-12-17 18:21:36 +00:00
parent 0afc34af69
commit ab77c081bd
3 changed files with 25 additions and 5 deletions

View file

@ -137,9 +137,9 @@ export function getDynamicVariables(datasource, queryId) {
// convert dynamic variables object back to a list, enrich with query id
export function rebuildVariables(datasource, queryId, variables) {
let finalVars = []
let newVariables = []
if (variables) {
finalVars = Object.entries(variables).map(entry => {
newVariables = Object.entries(variables).map(entry => {
return {
name: entry[0],
value: entry[1],
@ -147,7 +147,15 @@ export function rebuildVariables(datasource, queryId, variables) {
}
})
}
return [...(datasource?.config?.dynamicVariables || []), ...finalVars]
let existing = datasource?.config?.dynamicVariables || []
// filter out any by same name
existing = existing.filter(
variable =>
!newVariables.find(
newVar => newVar.name.toLowerCase() === variable.name.toLowerCase()
)
)
return [...existing, ...newVariables]
}
export function shouldShowVariables(dynamicVariables, variablesReadOnly) {

View file

@ -1,5 +1,5 @@
<script>
import { Input, ModalContent, Modal } from "@budibase/bbui"
import { Input, ModalContent, Modal, Body } from "@budibase/bbui"
export let dynamicVariables
export let datasource
@ -45,6 +45,10 @@
onConfirm={saveVariable}
disabled={!valid}
>
<Body size="S"
>Specify a name for your new dynamic variable, this must be unique across
your datasource.</Body
>
<Input label="Variable name" bind:value={name} on:input {error} />
</ModalContent>
</Modal>

View file

@ -16,6 +16,10 @@ class QueryRunner {
this.queryId = input.queryId
this.noRecursiveQuery = flags.noRecursiveQuery
this.cachedVariables = []
// allows the response from a query to be stored throughout this
// execution so that if it needs to be re-used for another variable
// it can be
this.queryResponse = {}
this.hasRerun = false
}
@ -102,7 +106,11 @@ class QueryRunner {
name = variable.name
let value = await threadUtils.checkCacheForDynamicVariable(queryId, name)
if (!value) {
value = await this.runAnotherQuery(queryId, parameters)
value = this.queryResponse[queryId]
? this.queryResponse[queryId]
: await this.runAnotherQuery(queryId, parameters)
// store incase this query is to be called again
this.queryResponse[queryId] = value
await threadUtils.storeDynamicVariable(queryId, name, value)
} else {
this.cachedVariables.push({ queryId, name })