mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
feat: save unsaved request changes before renaming (#2018)
* feat: show unsaved changes alert while renaming request * fix: save unsaved request changes silently instead of showing dialog * fix: save unsaved request changes before renaming
This commit is contained in:
parent
65dbf9c8ba
commit
0173d8812d
@ -4,7 +4,7 @@ import * as Yup from 'yup';
|
||||
import Modal from 'components/Modal';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { isItemAFolder } from 'utils/tabs';
|
||||
import { renameItem } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { renameItem, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
|
||||
const RenameCollectionItem = ({ collection, item, onClose }) => {
|
||||
const dispatch = useDispatch();
|
||||
@ -21,7 +21,12 @@ const RenameCollectionItem = ({ collection, item, onClose }) => {
|
||||
.max(50, 'must be 50 characters or less')
|
||||
.required('name is required')
|
||||
}),
|
||||
onSubmit: (values) => {
|
||||
onSubmit: async (values) => {
|
||||
// if there is unsaved changes in the request,
|
||||
// save them before renaming the request
|
||||
if (!isFolder && item.draft) {
|
||||
await dispatch(saveRequest(item.uid, collection.uid, true));
|
||||
}
|
||||
dispatch(renameItem(values.name, item.uid, collection.uid));
|
||||
onClose();
|
||||
}
|
||||
|
@ -6,9 +6,8 @@ import { useDrag, useDrop } from 'react-dnd';
|
||||
import { IconChevronRight, IconDots } from '@tabler/icons';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
|
||||
import { moveItem, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
|
||||
import { moveItem } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import Dropdown from 'components/Dropdown';
|
||||
import NewRequest from 'components/Sidebar/NewRequest';
|
||||
import NewFolder from 'components/Sidebar/NewFolder';
|
||||
|
@ -55,7 +55,7 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState)
|
||||
});
|
||||
};
|
||||
|
||||
export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => {
|
||||
export const saveRequest = (itemUid, collectionUid, saveSilently) => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
||||
|
||||
@ -76,7 +76,11 @@ export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => {
|
||||
itemSchema
|
||||
.validate(itemToSave)
|
||||
.then(() => ipcRenderer.invoke('renderer:save-request', item.pathname, itemToSave))
|
||||
.then(() => toast.success('Request saved successfully'))
|
||||
.then(() => {
|
||||
if (!saveSilently) {
|
||||
toast.success('Request saved successfully');
|
||||
}
|
||||
})
|
||||
.then(resolve)
|
||||
.catch((err) => {
|
||||
toast.error('Failed to save request!');
|
||||
|
Loading…
Reference in New Issue
Block a user