feat: auto focus newly created environment

This commit is contained in:
Anoop M D 2023-02-07 18:11:34 +05:30
parent 3c1a6ca71e
commit 3805cef0c4
2 changed files with 29 additions and 6 deletions

View File

@ -17,13 +17,14 @@ import {
findEnvironmentInCollection,
isItemARequest,
isItemAFolder,
refreshUidsInItem,
refreshUidsInItem
} from 'utils/collections';
import { collectionSchema, itemSchema, environmentSchema, environmentsSchema } from '@usebruno/schema';
import { waitForNextTick } from 'utils/common';
import { sendNetworkRequest, cancelNetworkRequest } from 'utils/network';
import {
updateLastAction,
resetRunResults,
requestCancelled,
responseReceived,
@ -574,6 +575,13 @@ export const addEnvironment = (name, collectionUid) => (dispatch, getState) => {
ipcRenderer
.invoke('renderer:create-environment', collection.pathname, name)
.then(dispatch(updateLastAction({
collectionUid,
lastAction: {
type: 'ADD_ENVIRONMENT',
payload: name
}
})))
.then(resolve)
.catch(reject);
});

View File

@ -38,6 +38,14 @@ export const collectionsSlice = createSlice({
createCollection: (state, action) => {
const collectionUids = map(state.collections, (c) => c.uid);
const collection = action.payload;
// last action is used to track the last action performed on the collection
// this is optional
// this is used in scenarios where we want to know the last action performed on the collection
// and take some extra action based on that
// for example, when a env is created, we want to auto select it the env modal
collection.lastAction = null;
collapseCollection(collection);
addDepth(collection.items);
if (!collectionUids.includes(collection.uid)) {
@ -54,13 +62,12 @@ export const collectionsSlice = createSlice({
removeCollection: (state, action) => {
state.collections = filter(state.collections, (c) => c.uid !== action.payload.collectionUid);
},
addEnvironment: (state, action) => {
const { environment, collectionUid } = action.payload;
updateLastAction: (state, action) => {
const { collectionUid, lastAction } = action.payload;
const collection = findCollectionByUid(state.collections, collectionUid);
if (collection) {
collection.environments = collection.environments || [];
collection.environments.push(environment);
collection.lastAction = lastAction;
}
},
collectionUnlinkEnvFileEvent: (state, action) => {
@ -846,6 +853,14 @@ export const collectionsSlice = createSlice({
existingEnv.variables = environment.variables;
} else {
collection.environments.push(environment);
const lastAction = collection.lastAction;
if(lastAction && lastAction.type === 'ADD_ENVIRONMENT') {
collection.lastAction = null;
if(lastAction.payload === environment.name) {
collection.activeEnvironmentUid = environment.uid;
}
}
}
}
},
@ -952,7 +967,7 @@ export const {
createCollection,
renameCollection,
removeCollection,
addEnvironment,
updateLastAction,
collectionUnlinkEnvFileEvent,
saveEnvironment,
selectEnvironment,