From 6619684a75d25f65903d7e355717fddf50a23f61 Mon Sep 17 00:00:00 2001 From: lohxt1 Date: Thu, 24 Oct 2024 12:56:56 +0530 Subject: [PATCH] fix: selected global env switch --- .../EnvironmentSettings/EnvironmentList/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/EnvironmentList/index.js b/packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/EnvironmentList/index.js index 444b72f2d9..ebd953a0d5 100644 --- a/packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/EnvironmentList/index.js +++ b/packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/EnvironmentList/index.js @@ -7,6 +7,7 @@ import StyledWrapper from './StyledWrapper'; import ConfirmSwitchEnv from './ConfirmSwitchEnv'; import ManageSecrets from 'components/Environments/EnvironmentSettings/ManageSecrets/index'; import ImportEnvironment from '../ImportEnvironment'; +import { isEqual } from 'lodash'; const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironment, setSelectedEnvironment, isModified, setIsModified }) => { const [openCreateModal, setOpenCreateModal] = useState(false); @@ -26,7 +27,18 @@ const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironme return; } + if (selectedEnvironment) { + const _selectedEnvironment = environments?.find(env => env?.uid === selectedEnvironment?.uid); + const hasSelectedEnvironmentChanged = !isEqual(selectedEnvironment, _selectedEnvironment); + if (hasSelectedEnvironmentChanged) { + setSelectedEnvironment(_selectedEnvironment); + } + setOriginalEnvironmentVariables(selectedEnvironment.variables); + return; + } + const environment = environments?.find(env => env.uid === activeEnvironmentUid) || environments?.[0]; + setSelectedEnvironment(environment); setOriginalEnvironmentVariables(environment?.variables || []); }, [environments, activeEnvironmentUid]);