fix: preserve global environment color during script execution (#7427)

When executing requests with pre-request or post-response scripts, the
global environment color property was being stripped from YAML files.
This happened because the save operation only passed `variables` through
the IPC chain, and the workspace-environments store created a new
environment object without preserving the existing `color` property.

The fix passes the `color` property through the entire IPC chain:
- Redux actions now include `color` in the save-global-environment IPC call
- IPC handler accepts and forwards `color` to both stores
- workspace-environments store includes `color` when creating the environment object
- global-environments store preserves `color` when updating

Fixes #7348

Co-authored-by: Chirag Chandrashekhar <cchirag85@gmail.com>
This commit is contained in:
Chirag Chandrashekhar
2026-03-27 19:56:19 +05:30
committed by GitHub
parent 7ef3981656
commit 13e97f0367
4 changed files with 14 additions and 5 deletions

View File

@@ -226,6 +226,7 @@ export const saveGlobalEnvironment = ({ variables, environmentUid }) => (dispatc
.then(() => ipcRenderer.invoke('renderer:save-global-environment', {
environmentUid,
variables,
color: environment.color,
workspaceUid,
workspacePath
}))
@@ -310,6 +311,7 @@ export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) =>
.then(() => ipcRenderer.invoke('renderer:save-global-environment', {
environmentUid,
variables,
color: environment.color,
workspaceUid,
workspacePath
}))

View File

@@ -78,13 +78,13 @@ const registerGlobalEnvironmentsIpc = (mainWindow, workspaceEnvironmentsManager)
}
});
ipcMain.handle('renderer:save-global-environment', async (event, { environmentUid, variables, workspaceUid, workspacePath }) => {
ipcMain.handle('renderer:save-global-environment', async (event, { environmentUid, variables, color, workspaceUid, workspacePath }) => {
try {
if (workspacePath && workspaceEnvironmentsManager) {
return await workspaceEnvironmentsManager.saveGlobalEnvironmentByPath(workspacePath, { environmentUid, variables });
return await workspaceEnvironmentsManager.saveGlobalEnvironmentByPath(workspacePath, { environmentUid, variables, color });
}
globalEnvironmentsStore.saveGlobalEnvironment({ environmentUid, variables });
globalEnvironmentsStore.saveGlobalEnvironment({ environmentUid, variables, color });
} catch (error) {
console.error('Error in renderer:save-global-environment:', error);
return Promise.reject(error);

View File

@@ -139,12 +139,15 @@ class GlobalEnvironmentsStore {
this.setGlobalEnvironments(globalEnvironments);
}
saveGlobalEnvironment({ environmentUid: globalEnvironmentUid, variables }) {
saveGlobalEnvironment({ environmentUid: globalEnvironmentUid, variables, color }) {
let globalEnvironments = this.getGlobalEnvironments();
const environment = globalEnvironments.find((env) => env?.uid == globalEnvironmentUid);
globalEnvironments = globalEnvironments.filter((env) => env?.uid !== globalEnvironmentUid);
if (environment) {
environment.variables = variables;
if (color !== undefined) {
environment.color = color;
}
}
globalEnvironments.push(environment);
this.setGlobalEnvironments(globalEnvironments);

View File

@@ -161,7 +161,7 @@ class GlobalEnvironmentsManager {
}
}
async saveGlobalEnvironment(workspacePath, { environmentUid, variables }) {
async saveGlobalEnvironment(workspacePath, { environmentUid, variables, color }) {
try {
if (!workspacePath) {
throw new Error('Workspace path is required');
@@ -178,6 +178,10 @@ class GlobalEnvironmentsManager {
variables: variables
};
if (color) {
environment.color = color;
}
if (this.envHasSecrets(environment)) {
environmentSecretsStore.storeEnvSecrets(workspacePath, environment);
}