From a752921413cabfcb2b38e18617a8cedca8dd96d9 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 <54320162+Pragadesh-45@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:07:37 +0530 Subject: [PATCH] feat: add validation to prevent duplicate global environment names (#3450) --- .../src/providers/ReduxStore/slices/global-environments.js | 4 +--- packages/bruno-electron/src/store/global-environments.js | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js index 7cc19a5a3..c93d6b6bd 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js @@ -92,9 +92,7 @@ export const addGlobalEnvironment = ({ name, variables = [] }) => (dispatch, get const uid = uuid(); ipcRenderer .invoke('renderer:create-global-environment', { name, uid, variables }) - .then( - dispatch(_addGlobalEnvironment({ name, uid, variables })) - ) + .then(() => dispatch(_addGlobalEnvironment({ name, uid, variables }))) .then(resolve) .catch(reject); }); diff --git a/packages/bruno-electron/src/store/global-environments.js b/packages/bruno-electron/src/store/global-environments.js index 7c0540d95..e8c03c434 100644 --- a/packages/bruno-electron/src/store/global-environments.js +++ b/packages/bruno-electron/src/store/global-environments.js @@ -63,6 +63,10 @@ class GlobalEnvironmentsStore { addGlobalEnvironment({ uid, name, variables = [] }) { let globalEnvironments = this.getGlobalEnvironments(); + const existingEnvironment = globalEnvironments.find(env => env?.name == name); + if (existingEnvironment) { + throw new Error('Environment with the same name already exists'); + } globalEnvironments.push({ uid, name,