mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-20 12:48:41 +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;
|
export default Wrapper;
|
||||||
|
@ -98,7 +98,7 @@ const Collection = ({ collection, searchText }) => {
|
|||||||
{showRenameCollectionModal && <RenameCollection collection={collection} onClose={() => setShowRenameCollectionModal(false)} />}
|
{showRenameCollectionModal && <RenameCollection collection={collection} onClose={() => setShowRenameCollectionModal(false)} />}
|
||||||
{showRemoveCollectionModal && <RemoveCollection collection={collection} onClose={() => setShowRemoveCollectionModal(false)} />}
|
{showRemoveCollectionModal && <RemoveCollection collection={collection} onClose={() => setShowRemoveCollectionModal(false)} />}
|
||||||
<div className="flex py-1 collection-name items-center" ref={drop}>
|
<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)' }} />
|
<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 className="ml-1" id="sidebar-collection-name">{collection.name}</div>
|
||||||
</div>
|
</div>
|
||||||
@ -122,8 +122,7 @@ const Collection = ({ collection, searchText }) => {
|
|||||||
>
|
>
|
||||||
New Folder
|
New Folder
|
||||||
</div>
|
</div>
|
||||||
{/* Todo: implement rename collection */}
|
<div
|
||||||
{/* <div
|
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
menuDropdownTippyRef.current.hide();
|
menuDropdownTippyRef.current.hide();
|
||||||
@ -131,7 +130,7 @@ const Collection = ({ collection, searchText }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Rename
|
Rename
|
||||||
</div> */}
|
</div>
|
||||||
<div
|
<div
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
requestSentEvent,
|
requestSentEvent,
|
||||||
requestQueuedEvent,
|
requestQueuedEvent,
|
||||||
testResultsEvent,
|
testResultsEvent,
|
||||||
scriptEnvironmentUpdateEvent
|
scriptEnvironmentUpdateEvent,
|
||||||
|
collectionRenamedEvent
|
||||||
} from 'providers/ReduxStore/slices/collections';
|
} from 'providers/ReduxStore/slices/collections';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions';
|
import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
@ -100,6 +101,10 @@ const useCollectionTreeSync = () => {
|
|||||||
dispatch(testResultsEvent(val));
|
dispatch(testResultsEvent(val));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const _collectionRenamed = (val) => {
|
||||||
|
dispatch(collectionRenamedEvent(val));
|
||||||
|
};
|
||||||
|
|
||||||
ipcRenderer.invoke('renderer:ready');
|
ipcRenderer.invoke('renderer:ready');
|
||||||
|
|
||||||
const removeListener1 = ipcRenderer.on('main:collection-opened', _openCollection);
|
const removeListener1 = ipcRenderer.on('main:collection-opened', _openCollection);
|
||||||
@ -110,6 +115,7 @@ const useCollectionTreeSync = () => {
|
|||||||
const removeListener6 = ipcRenderer.on('main:script-environment-update', _scriptEnvironmentUpdate);
|
const removeListener6 = ipcRenderer.on('main:script-environment-update', _scriptEnvironmentUpdate);
|
||||||
const removeListener7 = ipcRenderer.on('main:http-request-queued', _httpRequestQueued);
|
const removeListener7 = ipcRenderer.on('main:http-request-queued', _httpRequestQueued);
|
||||||
const removeListener8 = ipcRenderer.on('main:test-results', _testResults);
|
const removeListener8 = ipcRenderer.on('main:test-results', _testResults);
|
||||||
|
const removeListener9 = ipcRenderer.on('main:collection-renamed', _collectionRenamed);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
removeListener1();
|
removeListener1();
|
||||||
@ -120,6 +126,7 @@ const useCollectionTreeSync = () => {
|
|||||||
removeListener6();
|
removeListener6();
|
||||||
removeListener7();
|
removeListener7();
|
||||||
removeListener8();
|
removeListener8();
|
||||||
|
removeListener9();
|
||||||
};
|
};
|
||||||
}, [isElectron]);
|
}, [isElectron]);
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
moveCollectionItemToRootOfCollection,
|
moveCollectionItemToRootOfCollection,
|
||||||
findCollectionByUid,
|
findCollectionByUid,
|
||||||
recursivelyGetAllItemUids,
|
recursivelyGetAllItemUids,
|
||||||
transformCollectionToSaveToIdb,
|
|
||||||
transformRequestToSaveToFilesystem,
|
transformRequestToSaveToFilesystem,
|
||||||
findParentItemInCollection,
|
findParentItemInCollection,
|
||||||
findEnvironmentInCollection,
|
findEnvironmentInCollection,
|
||||||
@ -48,26 +47,16 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState)
|
|||||||
const state = getState();
|
const state = getState();
|
||||||
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
||||||
|
|
||||||
if (collection) {
|
return new Promise((resolve, reject) => {
|
||||||
const collectionCopy = cloneDeep(collection);
|
if (!collection) {
|
||||||
collectionCopy.name = newName;
|
return reject(new Error('Collection not found'));
|
||||||
const collectionToSave = transformCollectionToSaveToIdb(collectionCopy, {
|
}
|
||||||
ignoreDraft: true
|
|
||||||
});
|
|
||||||
|
|
||||||
collectionSchema
|
ipcRenderer
|
||||||
.validate(collectionToSave)
|
.invoke('renderer:rename-collection', newName, collection.pathname)
|
||||||
.then(() => saveCollectionToIdb(window.__idb, collectionToSave))
|
.then(resolve)
|
||||||
.then(() => {
|
.catch(reject);
|
||||||
dispatch(
|
});
|
||||||
_renameCollection({
|
|
||||||
newName: newName,
|
|
||||||
collectionUid: collectionUid
|
|
||||||
})
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.catch((err) => console.log(err));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => {
|
export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => {
|
||||||
|
@ -11,6 +11,7 @@ import { createSlice } from '@reduxjs/toolkit';
|
|||||||
import splitOnFirst from 'split-on-first';
|
import splitOnFirst from 'split-on-first';
|
||||||
import {
|
import {
|
||||||
findCollectionByUid,
|
findCollectionByUid,
|
||||||
|
findCollectionByPathname,
|
||||||
findItemInCollection,
|
findItemInCollection,
|
||||||
findEnvironmentInCollection,
|
findEnvironmentInCollection,
|
||||||
findItemInCollectionByPathname,
|
findItemInCollectionByPathname,
|
||||||
@ -840,6 +841,14 @@ export const collectionsSlice = createSlice({
|
|||||||
item.testResults = results;
|
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,
|
collectionUnlinkFileEvent,
|
||||||
collectionUnlinkDirectoryEvent,
|
collectionUnlinkDirectoryEvent,
|
||||||
collectionAddEnvFileEvent,
|
collectionAddEnvFileEvent,
|
||||||
testResultsEvent
|
testResultsEvent,
|
||||||
|
collectionRenamedEvent
|
||||||
} = collectionsSlice.actions;
|
} = collectionsSlice.actions;
|
||||||
|
|
||||||
export default collectionsSlice.reducer;
|
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
|
// new request
|
||||||
ipcMain.handle('renderer:new-request', async (event, pathname, request) => {
|
ipcMain.handle('renderer:new-request', async (event, pathname, request) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user