fix: selected global env switch (#3344)

This commit is contained in:
lohit 2024-10-24 15:00:14 +05:30 committed by GitHub
parent d70d4a482b
commit d92e806899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import StyledWrapper from './StyledWrapper';
import ConfirmSwitchEnv from './ConfirmSwitchEnv'; import ConfirmSwitchEnv from './ConfirmSwitchEnv';
import ManageSecrets from 'components/Environments/EnvironmentSettings/ManageSecrets/index'; import ManageSecrets from 'components/Environments/EnvironmentSettings/ManageSecrets/index';
import ImportEnvironment from '../ImportEnvironment'; import ImportEnvironment from '../ImportEnvironment';
import { isEqual } from 'lodash';
const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironment, setSelectedEnvironment, isModified, setIsModified }) => { const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironment, setSelectedEnvironment, isModified, setIsModified }) => {
const [openCreateModal, setOpenCreateModal] = useState(false); const [openCreateModal, setOpenCreateModal] = useState(false);
@ -26,7 +27,18 @@ const EnvironmentList = ({ environments, activeEnvironmentUid, selectedEnvironme
return; 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]; const environment = environments?.find(env => env.uid === activeEnvironmentUid) || environments?.[0];
setSelectedEnvironment(environment); setSelectedEnvironment(environment);
setOriginalEnvironmentVariables(environment?.variables || []); setOriginalEnvironmentVariables(environment?.variables || []);
}, [environments, activeEnvironmentUid]); }, [environments, activeEnvironmentUid]);