diff --git a/packages/builder/src/helpers/data/utils.js b/packages/builder/src/helpers/data/utils.js index c8eb7a4d3b..6d7843e0e5 100644 --- a/packages/builder/src/helpers/data/utils.js +++ b/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 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) { diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte index 2941826427..61d0a1993c 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/DynamicVariableModal.svelte @@ -1,5 +1,5 @@