fix: no env select issue (#3247)

This commit is contained in:
lohit 2024-10-04 16:55:49 +05:30 committed by GitHub
parent 5c5e3d18fc
commit ce8ebb0c1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 19 deletions

View File

@ -19,7 +19,7 @@ import {
runRequestEvent, runRequestEvent,
scriptEnvironmentUpdateEvent scriptEnvironmentUpdateEvent
} from 'providers/ReduxStore/slices/collections'; } 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 toast from 'react-hot-toast';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { isElectron } from 'utils/common/platform'; import { isElectron } from 'utils/common/platform';
@ -150,7 +150,7 @@ const useIpcEvents = () => {
}); });
const removeSnapshotHydrationListener = ipcRenderer.on('main:hydrate-app-with-ui-state-snapshot', (val) => { const removeSnapshotHydrationListener = ipcRenderer.on('main:hydrate-app-with-ui-state-snapshot', (val) => {
dispatch(hydrateCollectionsWithUiStateSnapshot(val)); dispatch(hydrateCollectionWithUiStateSnapshot(val));
}) })
return () => { return () => {

View File

@ -971,17 +971,19 @@ export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, g
} }
const collectionCopy = cloneDeep(collection); const collectionCopy = cloneDeep(collection);
if (environmentUid) {
const environment = findEnvironmentInCollection(collectionCopy, environmentUid); const environmentName = environmentUid
if (environment) { ? findEnvironmentInCollection(collectionCopy, environmentUid)?.name
ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName: environment?.name } }) : null;
dispatch(_selectEnvironment({ environmentUid, collectionUid }));
resolve(); if (environmentUid && !environmentName) {
} return reject(new Error('Environment not found'));
else { }
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; const collectionSnapshotData = payload;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const state = getState(); const state = getState();

View File

@ -25,11 +25,11 @@ const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids');
const { deleteCookiesForDomain, getDomainsWithCookies } = require('../utils/cookies'); const { deleteCookiesForDomain, getDomainsWithCookies } = require('../utils/cookies');
const EnvironmentSecretsStore = require('../store/env-secrets'); const EnvironmentSecretsStore = require('../store/env-secrets');
const CollectionSecurityStore = require('../store/collection-security'); 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 environmentSecretsStore = new EnvironmentSecretsStore();
const collectionSecurityStore = new CollectionSecurityStore(); const collectionSecurityStore = new CollectionSecurityStore();
const UiStateSnapshotStore = new UiStateSnapshot(); const uiStateSnapshotStore = new UiStateSnapshotStore();
const envHasSecrets = (environment = {}) => { const envHasSecrets = (environment = {}) => {
const secrets = _.filter(environment.variables, (v) => v.secret); 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 }) => { ipcMain.handle('renderer:update-ui-state-snapshot', (event, { type, data }) => {
try { try {
UiStateSnapshotStore.update({ type, data }); uiStateSnapshotStore.update({ type, data });
} catch (error) { } catch (error) {
throw new Error(error.message); throw new Error(error.message);
} }

View File

@ -1,6 +1,6 @@
const Store = require('electron-store'); const Store = require('electron-store');
class UiStateSnapshot { class UiStateSnapshotStore {
constructor() { constructor() {
this.store = new Store({ this.store = new Store({
name: 'ui-state-snapshot', name: 'ui-state-snapshot',
@ -57,4 +57,4 @@ class UiStateSnapshot {
} }
} }
module.exports = UiStateSnapshot; module.exports = UiStateSnapshotStore;