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(); const uid = uuid();
ipcRenderer ipcRenderer
.invoke('renderer:create-global-environment', { name, uid, variables }) .invoke('renderer:create-global-environment', { name, uid, variables })
.then( .then(() => dispatch(_addGlobalEnvironment({ name, uid, variables })))
dispatch(_addGlobalEnvironment({ name, uid, variables }))
)
.then(resolve) .then(resolve)
.catch(reject); .catch(reject);
}); });

View File

@ -63,6 +63,10 @@ class GlobalEnvironmentsStore {
addGlobalEnvironment({ uid, name, variables = [] }) { addGlobalEnvironment({ uid, name, variables = [] }) {
let globalEnvironments = this.getGlobalEnvironments(); 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({ globalEnvironments.push({
uid, uid,
name, name,