diff --git a/packages/bruno-app/src/providers/App/useIpcEvents.js b/packages/bruno-app/src/providers/App/useIpcEvents.js index b885ad74d..c8e022b67 100644 --- a/packages/bruno-app/src/providers/App/useIpcEvents.js +++ b/packages/bruno-app/src/providers/App/useIpcEvents.js @@ -19,7 +19,7 @@ import { runRequestEvent, scriptEnvironmentUpdateEvent } from 'providers/ReduxStore/slices/collections'; -import { collectionAddEnvFileEvent, openCollectionEvent, hydrateCollectionsWithUiStateSnapshot } from 'providers/ReduxStore/slices/collections/actions'; +import { collectionAddEnvFileEvent, openCollectionEvent, hydrateCollectionWithUiStateSnapshot } from 'providers/ReduxStore/slices/collections/actions'; import toast from 'react-hot-toast'; import { useDispatch } from 'react-redux'; import { isElectron } from 'utils/common/platform'; @@ -150,7 +150,7 @@ const useIpcEvents = () => { }); const removeSnapshotHydrationListener = ipcRenderer.on('main:hydrate-app-with-ui-state-snapshot', (val) => { - dispatch(hydrateCollectionsWithUiStateSnapshot(val)); + dispatch(hydrateCollectionWithUiStateSnapshot(val)); }) return () => { diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index e582b0f1f..79635241e 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -971,17 +971,19 @@ export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, g } const collectionCopy = cloneDeep(collection); - if (environmentUid) { - const environment = findEnvironmentInCollection(collectionCopy, environmentUid); - if (environment) { - ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName: environment?.name } }) - dispatch(_selectEnvironment({ environmentUid, collectionUid })); - resolve(); - } - else { - return reject(new Error('Environment not found')); - } - } + + const environmentName = environmentUid + ? findEnvironmentInCollection(collectionCopy, environmentUid)?.name + : null; + + if (environmentUid && !environmentName) { + return reject(new Error('Environment not found')); + } + + ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName }}); + + dispatch(_selectEnvironment({ environmentUid, collectionUid })); + resolve(); }); }; @@ -1146,7 +1148,7 @@ export const saveCollectionSecurityConfig = (collectionUid, securityConfig) => ( }; -export const hydrateCollectionsWithUiStateSnapshot = (payload) => (dispatch, getState) => { +export const hydrateCollectionWithUiStateSnapshot = (payload) => (dispatch, getState) => { const collectionSnapshotData = payload; return new Promise((resolve, reject) => { const state = getState(); diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index 0aa2058c2..0421060dd 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -25,11 +25,11 @@ const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids'); const { deleteCookiesForDomain, getDomainsWithCookies } = require('../utils/cookies'); const EnvironmentSecretsStore = require('../store/env-secrets'); const CollectionSecurityStore = require('../store/collection-security'); -const UiStateSnapshot = require('../store/ui-state-snapshot'); +const UiStateSnapshotStore = require('../store/ui-state-snapshot'); const environmentSecretsStore = new EnvironmentSecretsStore(); const collectionSecurityStore = new CollectionSecurityStore(); -const UiStateSnapshotStore = new UiStateSnapshot(); +const uiStateSnapshotStore = new UiStateSnapshotStore(); const envHasSecrets = (environment = {}) => { const secrets = _.filter(environment.variables, (v) => v.secret); @@ -700,7 +700,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection ipcMain.handle('renderer:update-ui-state-snapshot', (event, { type, data }) => { try { - UiStateSnapshotStore.update({ type, data }); + uiStateSnapshotStore.update({ type, data }); } catch (error) { throw new Error(error.message); } diff --git a/packages/bruno-electron/src/store/ui-state-snapshot.js b/packages/bruno-electron/src/store/ui-state-snapshot.js index b3d1909b6..a130c36de 100644 --- a/packages/bruno-electron/src/store/ui-state-snapshot.js +++ b/packages/bruno-electron/src/store/ui-state-snapshot.js @@ -1,6 +1,6 @@ const Store = require('electron-store'); -class UiStateSnapshot { +class UiStateSnapshotStore { constructor() { this.store = new Store({ name: 'ui-state-snapshot', @@ -57,4 +57,4 @@ class UiStateSnapshot { } } -module.exports = UiStateSnapshot; +module.exports = UiStateSnapshotStore;