mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34:15 +01:00
[Feature request] Keyboard shortcut to duplicate and rename request/collection. #1610
This commit is contained in:
parent
2cd0e065bd
commit
a3ce8aa691
@ -9,7 +9,7 @@ import NetworkError from 'components/ResponsePane/NetworkError';
|
||||
import NewRequest from 'components/Sidebar/NewRequest';
|
||||
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { findCollectionByUid, findItemInCollection } from 'utils/collections';
|
||||
import { closeTabs } from 'providers/ReduxStore/slices/tabs';
|
||||
import { closeTabs, cloneRequest, renameRequest } from 'providers/ReduxStore/slices/tabs';
|
||||
|
||||
export const HotkeysContext = React.createContext();
|
||||
|
||||
@ -154,6 +154,50 @@ export const HotkeysProvider = (props) => {
|
||||
};
|
||||
}, [activeTabUid]);
|
||||
|
||||
// clone request (ctrl/cmd + d)
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+d', 'ctrl+d'], (e) => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
if (activeTab) {
|
||||
const collection = findCollectionByUid(collections, activeTab.collectionUid);
|
||||
if (collection) {
|
||||
const item = findItemInCollection(collection, activeTab.uid);
|
||||
if (item && item.uid) {
|
||||
dispatch(cloneRequest(item.uid, activeTab.collectionUid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // this stops the event bubbling
|
||||
});
|
||||
|
||||
return () => {
|
||||
Mousetrap.unbind(['command+d', 'ctrl+d']);
|
||||
};
|
||||
}, [activeTabUid, tabs, collections]);
|
||||
|
||||
// rename request (ctrl/cmd + e)
|
||||
useEffect(() => {
|
||||
Mousetrap.bind(['command+e', 'ctrl+e'], (e) => {
|
||||
const activeTab = find(tabs, (t) => t.uid === activeTabUid);
|
||||
if (activeTab) {
|
||||
const collection = findCollectionByUid(collections, activeTab.collectionUid);
|
||||
if (collection) {
|
||||
const item = findItemInCollection(collection, activeTab.uid);
|
||||
if (item && item.uid) {
|
||||
dispatch(renameRequest(item.uid, activeTab.collectionUid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false; // this stops the event bubbling
|
||||
});
|
||||
|
||||
return () => {
|
||||
Mousetrap.unbind(['command+e', 'ctrl+e']);
|
||||
};
|
||||
}, [activeTabUid, tabs, collections]);
|
||||
|
||||
return (
|
||||
<HotkeysContext.Provider {...props} value="hotkey">
|
||||
{showSaveRequestModal && (
|
||||
|
@ -101,6 +101,23 @@ export const tabsSlice = createSlice({
|
||||
const collectionUid = action.payload.collectionUid;
|
||||
state.tabs = filter(state.tabs, (t) => t.collectionUid !== collectionUid);
|
||||
state.activeTabUid = null;
|
||||
},
|
||||
cloneRequest: (state, action) => {
|
||||
const { requestId, collectionId } = action.payload;
|
||||
const tab = find(state.tabs, (t) => t.uid === requestId && t.collectionUid === collectionId);
|
||||
|
||||
if (tab) {
|
||||
const clonedTab = { ...tab, uid: action.payload.uid };
|
||||
state.tabs.push(clonedTab);
|
||||
}
|
||||
},
|
||||
renameRequest: (state, action) => {
|
||||
const { requestId, collectionId, newName } = action.payload;
|
||||
const tab = find(state.tabs, (t) => t.uid === requestId && t.collectionUid === collectionId);
|
||||
|
||||
if (tab) {
|
||||
tab.name = newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -112,7 +129,9 @@ export const {
|
||||
updateRequestPaneTab,
|
||||
updateResponsePaneTab,
|
||||
closeTabs,
|
||||
closeAllCollectionTabs
|
||||
closeAllCollectionTabs,
|
||||
cloneRequest,
|
||||
renameRequest
|
||||
} = tabsSlice.actions;
|
||||
|
||||
export default tabsSlice.reducer;
|
||||
|
Loading…
Reference in New Issue
Block a user