mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-22 05:38:40 +01:00
feat: auto focus newly created environment
This commit is contained in:
parent
3c1a6ca71e
commit
3805cef0c4
@ -17,13 +17,14 @@ import {
|
|||||||
findEnvironmentInCollection,
|
findEnvironmentInCollection,
|
||||||
isItemARequest,
|
isItemARequest,
|
||||||
isItemAFolder,
|
isItemAFolder,
|
||||||
refreshUidsInItem,
|
refreshUidsInItem
|
||||||
} from 'utils/collections';
|
} from 'utils/collections';
|
||||||
import { collectionSchema, itemSchema, environmentSchema, environmentsSchema } from '@usebruno/schema';
|
import { collectionSchema, itemSchema, environmentSchema, environmentsSchema } from '@usebruno/schema';
|
||||||
import { waitForNextTick } from 'utils/common';
|
import { waitForNextTick } from 'utils/common';
|
||||||
import { sendNetworkRequest, cancelNetworkRequest } from 'utils/network';
|
import { sendNetworkRequest, cancelNetworkRequest } from 'utils/network';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
updateLastAction,
|
||||||
resetRunResults,
|
resetRunResults,
|
||||||
requestCancelled,
|
requestCancelled,
|
||||||
responseReceived,
|
responseReceived,
|
||||||
@ -574,6 +575,13 @@ export const addEnvironment = (name, collectionUid) => (dispatch, getState) => {
|
|||||||
|
|
||||||
ipcRenderer
|
ipcRenderer
|
||||||
.invoke('renderer:create-environment', collection.pathname, name)
|
.invoke('renderer:create-environment', collection.pathname, name)
|
||||||
|
.then(dispatch(updateLastAction({
|
||||||
|
collectionUid,
|
||||||
|
lastAction: {
|
||||||
|
type: 'ADD_ENVIRONMENT',
|
||||||
|
payload: name
|
||||||
|
}
|
||||||
|
})))
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,14 @@ export const collectionsSlice = createSlice({
|
|||||||
createCollection: (state, action) => {
|
createCollection: (state, action) => {
|
||||||
const collectionUids = map(state.collections, (c) => c.uid);
|
const collectionUids = map(state.collections, (c) => c.uid);
|
||||||
const collection = action.payload;
|
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);
|
collapseCollection(collection);
|
||||||
addDepth(collection.items);
|
addDepth(collection.items);
|
||||||
if (!collectionUids.includes(collection.uid)) {
|
if (!collectionUids.includes(collection.uid)) {
|
||||||
@ -54,13 +62,12 @@ export const collectionsSlice = createSlice({
|
|||||||
removeCollection: (state, action) => {
|
removeCollection: (state, action) => {
|
||||||
state.collections = filter(state.collections, (c) => c.uid !== action.payload.collectionUid);
|
state.collections = filter(state.collections, (c) => c.uid !== action.payload.collectionUid);
|
||||||
},
|
},
|
||||||
addEnvironment: (state, action) => {
|
updateLastAction: (state, action) => {
|
||||||
const { environment, collectionUid } = action.payload;
|
const { collectionUid, lastAction } = action.payload;
|
||||||
const collection = findCollectionByUid(state.collections, collectionUid);
|
const collection = findCollectionByUid(state.collections, collectionUid);
|
||||||
|
|
||||||
if (collection) {
|
if (collection) {
|
||||||
collection.environments = collection.environments || [];
|
collection.lastAction = lastAction;
|
||||||
collection.environments.push(environment);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
collectionUnlinkEnvFileEvent: (state, action) => {
|
collectionUnlinkEnvFileEvent: (state, action) => {
|
||||||
@ -846,6 +853,14 @@ export const collectionsSlice = createSlice({
|
|||||||
existingEnv.variables = environment.variables;
|
existingEnv.variables = environment.variables;
|
||||||
} else {
|
} else {
|
||||||
collection.environments.push(environment);
|
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,
|
createCollection,
|
||||||
renameCollection,
|
renameCollection,
|
||||||
removeCollection,
|
removeCollection,
|
||||||
addEnvironment,
|
updateLastAction,
|
||||||
collectionUnlinkEnvFileEvent,
|
collectionUnlinkEnvFileEvent,
|
||||||
saveEnvironment,
|
saveEnvironment,
|
||||||
selectEnvironment,
|
selectEnvironment,
|
||||||
|
Loading…
Reference in New Issue
Block a user