feat: add validation to prevent duplicate global environment names (#3450)

This commit is contained in:
Pragadesh-45 2024-11-20 18:07:37 +05:30 committed by GitHub
parent 44debfd9b9
commit a752921413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -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);
});

View File

@ -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,