Browse Source

Some minor UI tweaks.

master
mike12345567 5 years ago
parent
commit
ae510760c3
  1. 14
      packages/builder/src/helpers/data/utils.js
  2. 6
      packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte
  3. 10
      packages/server/src/threads/query.js

14
packages/builder/src/helpers/data/utils.js

@ -137,9 +137,9 @@ export function getDynamicVariables(datasource, queryId) {
// 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(datasource, queryId, variables) { export function rebuildVariables(datasource, queryId, variables) {
let finalVars = [] let newVariables = []
if (variables) { if (variables) {
finalVars = Object.entries(variables).map(entry => { newVariables = Object.entries(variables).map(entry => {
return { return {
name: entry[0], name: entry[0],
value: entry[1], 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) { export function shouldShowVariables(dynamicVariables, variablesReadOnly) {

6
packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte

@ -1,5 +1,5 @@
<script> <script>
import { Input, ModalContent, Modal } from "@budibase/bbui" import { Input, ModalContent, Modal, Body } from "@budibase/bbui"
export let dynamicVariables export let dynamicVariables
export let datasource export let datasource
@ -45,6 +45,10 @@
onConfirm={saveVariable} onConfirm={saveVariable}
disabled={!valid} 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} /> <Input label="Variable name" bind:value={name} on:input {error} />
</ModalContent> </ModalContent>
</Modal> </Modal>

10
packages/server/src/threads/query.js

@ -16,6 +16,10 @@ class QueryRunner {
this.queryId = input.queryId this.queryId = input.queryId
this.noRecursiveQuery = flags.noRecursiveQuery this.noRecursiveQuery = flags.noRecursiveQuery
this.cachedVariables = [] 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 this.hasRerun = false
} }
@ -102,7 +106,11 @@ class QueryRunner {
name = variable.name name = variable.name
let value = await threadUtils.checkCacheForDynamicVariable(queryId, name) let value = await threadUtils.checkCacheForDynamicVariable(queryId, name)
if (!value) { 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) await threadUtils.storeDynamicVariable(queryId, name, value)
} else { } else {
this.cachedVariables.push({ queryId, name }) this.cachedVariables.push({ queryId, name })

Loading…
Cancel
Save