mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
fix: env draft loss on color change and rename (#7130)
This commit is contained in:
@@ -93,6 +93,7 @@ const EnvironmentVariablesTable = ({
|
||||
}, []);
|
||||
|
||||
const prevEnvUidRef = useRef(null);
|
||||
const prevEnvVariablesRef = useRef(environment.variables);
|
||||
const mountedRef = useRef(false);
|
||||
|
||||
let _collection = collection ? cloneDeep(collection) : {};
|
||||
@@ -168,11 +169,13 @@ const EnvironmentVariablesTable = ({
|
||||
useEffect(() => {
|
||||
const isMount = !mountedRef.current;
|
||||
const envChanged = prevEnvUidRef.current !== null && prevEnvUidRef.current !== environment.uid;
|
||||
const variablesReloaded = !isMount && !envChanged && prevEnvVariablesRef.current !== environment.variables;
|
||||
|
||||
prevEnvUidRef.current = environment.uid;
|
||||
prevEnvVariablesRef.current = environment.variables;
|
||||
mountedRef.current = true;
|
||||
|
||||
if ((isMount || envChanged) && hasDraftForThisEnv && draft?.variables) {
|
||||
if ((isMount || envChanged || variablesReloaded) && hasDraftForThisEnv && draft?.variables) {
|
||||
formik.setValues([
|
||||
...draft.variables,
|
||||
{
|
||||
@@ -185,7 +188,7 @@ const EnvironmentVariablesTable = ({
|
||||
}
|
||||
]);
|
||||
}
|
||||
}, [environment.uid, hasDraftForThisEnv, draft?.variables]);
|
||||
}, [environment.uid, environment.variables, hasDraftForThisEnv, draft?.variables]);
|
||||
|
||||
const savedValuesJson = useMemo(() => {
|
||||
return JSON.stringify((environment.variables || []).map(stripEnvVarUid));
|
||||
|
||||
@@ -183,6 +183,13 @@ export const renameGlobalEnvironment = ({ name: newName, environmentUid }) => (d
|
||||
.invoke('renderer:get-global-environments', { workspaceUid, workspacePath })
|
||||
.then((data) => {
|
||||
dispatch(updateGlobalEnvironments(data));
|
||||
if (resolvedUid !== environmentUid) {
|
||||
const currentState = getState();
|
||||
const draft = currentState.globalEnvironments.globalEnvironmentDraft;
|
||||
if (draft?.environmentUid === environmentUid) {
|
||||
dispatch(setGlobalEnvironmentDraft({ environmentUid: resolvedUid, variables: draft.variables }));
|
||||
}
|
||||
}
|
||||
return resolvedUid;
|
||||
});
|
||||
})
|
||||
|
||||
@@ -597,6 +597,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
|
||||
throw new Error(`environment: ${newEnvFilePath} already exists`);
|
||||
}
|
||||
|
||||
moveRequestUid(envFilePath, newEnvFilePath);
|
||||
fs.renameSync(envFilePath, newEnvFilePath);
|
||||
|
||||
environmentSecretsStore.renameEnvironment(collectionPathname, environmentName, newName);
|
||||
|
||||
Reference in New Issue
Block a user