Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#1630) Add contextual menu entries to reveal and edit the selected collection items #1631

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
import { moveItem } from 'providers/ReduxStore/slices/collections/actions';
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
import { shellOpenCollectionPath } from 'providers/ReduxStore/slices/collections/actions';
import Dropdown from 'components/Dropdown';
import NewRequest from 'components/Sidebar/NewRequest';
import NewFolder from 'components/Sidebar/NewFolder';
Expand Down Expand Up @@ -105,6 +106,14 @@ const CollectionItem = ({ item, collection, searchText }) => {
);
};

const handleShellRevealItem = () => {
dispatch(shellOpenCollectionPath(item.pathname, false, false));
};

const handleShellEditItem = () => {
dispatch(shellOpenCollectionPath(item.pathname, false, true));
};

const handleClick = (event) => {
//scroll to the active tab
setTimeout(scrollToTheActiveTab, 50);
Expand Down Expand Up @@ -346,6 +355,26 @@ const CollectionItem = ({ item, collection, searchText }) => {
>
Delete
</div>
<div
className="dropdown-item"
onClick={(e) => {
dropdownTippyRef.current.hide();
handleShellRevealItem();
}}
>
Open Location
</div>
{!isFolder && (
<div
className="dropdown-item"
onClick={(e) => {
dropdownTippyRef.current.hide();
handleShellEditItem();
}}
>
Edit
</div>
)}
</Dropdown>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IconChevronRight, IconDots } from '@tabler/icons';
import Dropdown from 'components/Dropdown';
import { collectionClicked } from 'providers/ReduxStore/slices/collections';
import { moveItemToRootOfCollection } from 'providers/ReduxStore/slices/collections/actions';
import { shellOpenCollectionPath } from 'providers/ReduxStore/slices/collections/actions';
import { useDispatch } from 'react-redux';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import NewRequest from 'components/Sidebar/NewRequest';
Expand Down Expand Up @@ -79,6 +80,14 @@ const Collection = ({ collection, searchText }) => {
}
};

const handleShellRevealCollection = () => {
dispatch(shellOpenCollectionPath(collection.pathname, true, false));
};

const handleShellEditCollection = () => {
dispatch(shellOpenCollectionPath(collection.pathname, true, true));
};

const viewCollectionSettings = () => {
dispatch(
addTab({
Expand Down Expand Up @@ -228,6 +237,24 @@ const Collection = ({ collection, searchText }) => {
>
Settings
</div>
<div
className="dropdown-item"
onClick={(e) => {
menuDropdownTippyRef.current.hide();
handleShellRevealCollection();
}}
>
Open Location
</div>
<div
className="dropdown-item"
onClick={(e) => {
menuDropdownTippyRef.current.hide();
handleShellEditCollection();
}}
>
Edit bruno.json
</div>
</Dropdown>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,13 @@ export const collectionAddEnvFileEvent = (payload) => (dispatch, getState) => {
export const importCollection = (collection, collectionLocation) => (dispatch, getState) => {
return new Promise((resolve, reject) => {
const { ipcRenderer } = window;

ipcRenderer.invoke('renderer:import-collection', collection, collectionLocation).then(resolve).catch(reject);
});
};

export const shellOpenCollectionPath = (itemPath, isCollection, edit) => () => {
return new Promise((resolve, reject) => {
const { ipcRenderer } = window;
ipcRenderer.invoke('renderer:shell-open', itemPath, isCollection, edit).then(resolve).catch(reject);
});
};
16 changes: 16 additions & 0 deletions packages/bruno-electron/src/ipc/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,22 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
}
});

ipcMain.handle('renderer:shell-open', async (event, itemPath, isCollection, edit) => {
if (isCollection) {
itemPath = path.join(itemPath, 'bruno.json');
}

if (fs.existsSync(itemPath)) {
const isDir = fs.statSync(itemPath).isDirectory();

if (edit && !isDir) {
shell.openPath(itemPath);
} else {
shell.showItemInFolder(itemPath);
}
}
});

ipcMain.handle('renderer:update-bruno-config', async (event, brunoConfig, collectionPath, collectionUid) => {
try {
const brunoConfigPath = path.join(collectionPath, 'bruno.json');
Expand Down
Loading