From d92e80689970e12e7c99f3a3adfa5f03f4b414ea Mon Sep 17 00:00:00 2001 From: lohit Date: Thu, 24 Oct 2024 15:00:14 +0530 Subject: [PATCH] fix: selected global env switch (#3344) --- .../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 444b72f2d..ebd953a0d 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]);