mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-03 04:29:09 +01:00
feat: rename collection
This commit is contained in:
parent
d4f05fa843
commit
be49ef5f12
@ -52,6 +52,12 @@ const Wrapper = styled.div`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#sidebar-collection-name {
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
`;
|
||||
|
||||
export default Wrapper;
|
||||
|
@ -98,7 +98,7 @@ const Collection = ({ collection, searchText }) => {
|
||||
{showRenameCollectionModal && <RenameCollection collection={collection} onClose={() => setShowRenameCollectionModal(false)} />}
|
||||
{showRemoveCollectionModal && <RemoveCollection collection={collection} onClose={() => setShowRemoveCollectionModal(false)} />}
|
||||
<div className="flex py-1 collection-name items-center" ref={drop}>
|
||||
<div className="flex flex-grow items-center" onClick={handleClick}>
|
||||
<div className="flex flex-grow items-center overflow-hidden" onClick={handleClick}>
|
||||
<IconChevronRight size={16} strokeWidth={2} className={iconClassName} style={{ width: 16, color: 'rgb(160 160 160)' }} />
|
||||
<div className="ml-1" id="sidebar-collection-name">{collection.name}</div>
|
||||
</div>
|
||||
@ -122,8 +122,7 @@ const Collection = ({ collection, searchText }) => {
|
||||
>
|
||||
New Folder
|
||||
</div>
|
||||
{/* Todo: implement rename collection */}
|
||||
{/* <div
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={(e) => {
|
||||
menuDropdownTippyRef.current.hide();
|
||||
@ -131,7 +130,7 @@ const Collection = ({ collection, searchText }) => {
|
||||
}}
|
||||
>
|
||||
Rename
|
||||
</div> */}
|
||||
</div>
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={(e) => {
|
||||
|
@ -10,7 +10,8 @@ import {
|
||||
requestSentEvent,
|
||||
requestQueuedEvent,
|
||||
testResultsEvent,
|
||||
scriptEnvironmentUpdateEvent
|
||||
scriptEnvironmentUpdateEvent,
|
||||
collectionRenamedEvent
|
||||
} from 'providers/ReduxStore/slices/collections';
|
||||
import toast from 'react-hot-toast';
|
||||
import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions';
|
||||
@ -100,6 +101,10 @@ const useCollectionTreeSync = () => {
|
||||
dispatch(testResultsEvent(val));
|
||||
};
|
||||
|
||||
const _collectionRenamed = (val) => {
|
||||
dispatch(collectionRenamedEvent(val));
|
||||
};
|
||||
|
||||
ipcRenderer.invoke('renderer:ready');
|
||||
|
||||
const removeListener1 = ipcRenderer.on('main:collection-opened', _openCollection);
|
||||
@ -110,6 +115,7 @@ const useCollectionTreeSync = () => {
|
||||
const removeListener6 = ipcRenderer.on('main:script-environment-update', _scriptEnvironmentUpdate);
|
||||
const removeListener7 = ipcRenderer.on('main:http-request-queued', _httpRequestQueued);
|
||||
const removeListener8 = ipcRenderer.on('main:test-results', _testResults);
|
||||
const removeListener9 = ipcRenderer.on('main:collection-renamed', _collectionRenamed);
|
||||
|
||||
return () => {
|
||||
removeListener1();
|
||||
@ -120,6 +126,7 @@ const useCollectionTreeSync = () => {
|
||||
removeListener6();
|
||||
removeListener7();
|
||||
removeListener8();
|
||||
removeListener9();
|
||||
};
|
||||
}, [isElectron]);
|
||||
};
|
||||
|
@ -11,7 +11,6 @@ import {
|
||||
moveCollectionItemToRootOfCollection,
|
||||
findCollectionByUid,
|
||||
recursivelyGetAllItemUids,
|
||||
transformCollectionToSaveToIdb,
|
||||
transformRequestToSaveToFilesystem,
|
||||
findParentItemInCollection,
|
||||
findEnvironmentInCollection,
|
||||
@ -48,26 +47,16 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState)
|
||||
const state = getState();
|
||||
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
||||
|
||||
if (collection) {
|
||||
const collectionCopy = cloneDeep(collection);
|
||||
collectionCopy.name = newName;
|
||||
const collectionToSave = transformCollectionToSaveToIdb(collectionCopy, {
|
||||
ignoreDraft: true
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!collection) {
|
||||
return reject(new Error('Collection not found'));
|
||||
}
|
||||
|
||||
collectionSchema
|
||||
.validate(collectionToSave)
|
||||
.then(() => saveCollectionToIdb(window.__idb, collectionToSave))
|
||||
.then(() => {
|
||||
dispatch(
|
||||
_renameCollection({
|
||||
newName: newName,
|
||||
collectionUid: collectionUid
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
ipcRenderer
|
||||
.invoke('renderer:rename-collection', newName, collection.pathname)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => {
|
||||
|
@ -11,6 +11,7 @@ import { createSlice } from '@reduxjs/toolkit';
|
||||
import splitOnFirst from 'split-on-first';
|
||||
import {
|
||||
findCollectionByUid,
|
||||
findCollectionByPathname,
|
||||
findItemInCollection,
|
||||
findEnvironmentInCollection,
|
||||
findItemInCollectionByPathname,
|
||||
@ -840,6 +841,14 @@ export const collectionsSlice = createSlice({
|
||||
item.testResults = results;
|
||||
}
|
||||
}
|
||||
},
|
||||
collectionRenamedEvent: (state, action) => {
|
||||
const { collectionPathname, newName } = action.payload;
|
||||
const collection = findCollectionByPathname(state.collections, collectionPathname);
|
||||
|
||||
if (collection) {
|
||||
collection.name = newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -891,7 +900,8 @@ export const {
|
||||
collectionUnlinkFileEvent,
|
||||
collectionUnlinkDirectoryEvent,
|
||||
collectionAddEnvFileEvent,
|
||||
testResultsEvent
|
||||
testResultsEvent,
|
||||
collectionRenamedEvent
|
||||
} = collectionsSlice.actions;
|
||||
|
||||
export default collectionsSlice.reducer;
|
||||
|
@ -64,6 +64,31 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
}
|
||||
});
|
||||
|
||||
// rename collection
|
||||
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
|
||||
try {
|
||||
const brunoJsonFilePath = path.join(collectionPathname, 'bruno.json');
|
||||
const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
|
||||
const json = JSON.parse(content);
|
||||
|
||||
json.name = newName;
|
||||
|
||||
const newContent = await stringifyJson(json);
|
||||
await writeFile(brunoJsonFilePath, newContent);
|
||||
|
||||
// todo: listen for bruno.json changes and handle it in watcher
|
||||
// the app will change the name of the collection after parsing the bruno.json file contents
|
||||
mainWindow.webContents.send('main:collection-renamed', {
|
||||
collectionPathname,
|
||||
newName
|
||||
});
|
||||
|
||||
return;
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
// new request
|
||||
ipcMain.handle('renderer:new-request', async (event, pathname, request) => {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user