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

Fix/ Handle Folder settings stale uids (fixes: #3864) #3866

Closed
Closed
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 @@ -19,13 +19,13 @@ const Headers = ({ collection, folder }) => {
const addHeader = () => {
dispatch(
addFolderHeader({
collectionUid: collection.uid,
folderUid: folder.uid
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};

const handleSave = () => dispatch(saveFolderRoot(collection.uid, folder.uid));
const handleSave = () => dispatch(saveFolderRoot(collection?.uid, folder?.uid));
const handleHeaderValueChange = (e, _header, type) => {
const header = cloneDeep(_header);
switch (type) {
Expand All @@ -45,18 +45,18 @@ const Headers = ({ collection, folder }) => {
dispatch(
updateFolderHeader({
header: header,
collectionUid: collection.uid,
folderUid: folder.uid
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};

const handleRemoveHeader = (header) => {
dispatch(
deleteFolderHeader({
headerUid: header.uid,
collectionUid: collection.uid,
folderUid: folder.uid
headerUid: header?.uid,
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};
Expand All @@ -78,7 +78,7 @@ const Headers = ({ collection, folder }) => {
{headers && headers.length
? headers.map((header) => {
return (
<tr key={header.uid}>
<tr key={header?.uid}>
<td>
<SingleLineEditor
value={header.name}
Expand Down
10 changes: 5 additions & 5 deletions packages/bruno-app/src/components/FolderSettings/Script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const Script = ({ collection, folder }) => {
dispatch(
updateFolderRequestScript({
script: value,
collectionUid: collection.uid,
folderUid: folder.uid
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};
Expand All @@ -29,14 +29,14 @@ const Script = ({ collection, folder }) => {
dispatch(
updateFolderResponseScript({
script: value,
collectionUid: collection.uid,
folderUid: folder.uid
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};

const handleSave = () => {
dispatch(saveFolderRoot(collection.uid, folder.uid));
dispatch(saveFolderRoot(collection?.uid, folder?.uid));
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const Tests = ({ collection, folder }) => {
dispatch(
updateFolderTests({
tests: value,
collectionUid: collection.uid,
folderUid: folder.uid
collectionUid: collection?.uid,
folderUid: folder?.uid
})
);
};

const handleSave = () => dispatch(saveFolderRoot(collection.uid, folder.uid));
const handleSave = () => dispatch(saveFolderRoot(collection?.uid, folder?.uid));

return (
<StyledWrapper className="w-full flex flex-col h-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ const VarsTable = ({ folder, collection, vars, varType }) => {
const addVar = () => {
dispatch(
addFolderVar({
collectionUid: collection.uid,
folderUid: folder.uid,
collectionUid: collection?.uid,
folderUid: folder?.uid,
type: varType
})
);
};

const onSave = () => dispatch(saveFolderRoot(collection.uid, folder.uid));
const onSave = () => dispatch(saveFolderRoot(collection?.uid, folder?.uid));
const handleVarChange = (e, v, type) => {
const _var = cloneDeep(v);
switch (type) {
Expand Down Expand Up @@ -55,8 +55,8 @@ const VarsTable = ({ folder, collection, vars, varType }) => {
updateFolderVar({
type: varType,
var: _var,
folderUid: folder.uid,
collectionUid: collection.uid
folderUid: folder?.uid,
collectionUid: collection?.uid
})
);
};
Expand All @@ -65,9 +65,9 @@ const VarsTable = ({ folder, collection, vars, varType }) => {
dispatch(
deleteFolderVar({
type: varType,
varUid: _var.uid,
folderUid: folder.uid,
collectionUid: collection.uid
varUid: _var?.uid,
folderUid: folder?.uid,
collectionUid: collection?.uid
})
);
};
Expand Down Expand Up @@ -99,7 +99,7 @@ const VarsTable = ({ folder, collection, vars, varType }) => {
{vars && vars.length
? vars.map((_var) => {
return (
<tr key={_var.uid}>
<tr key={_var?.uid}>
<td>
<input
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Vars = ({ collection, folder }) => {
const dispatch = useDispatch();
const requestVars = get(folder, 'root.request.vars.req', []);
const responseVars = get(folder, 'root.request.vars.res', []);
const handleSave = () => dispatch(saveFolderRoot(collection.uid, folder.uid));
const handleSave = () => dispatch(saveFolderRoot(collection?.uid, folder?.uid));
return (
<StyledWrapper className="w-full flex flex-col">
<div className="flex-1 mt-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const RenameCollectionItem = ({ collection, item, onClose }) => {
}
dispatch(renameItem(values.name, item.uid, collection.uid))
.then(() => {
isFolder && dispatch(closeTabs({ tabUids: [item.uid] }));
isFolder && item?.uid && dispatch(closeTabs({ tabUids: [item.uid] }));
toast.success(isFolder ? 'Folder renamed' : 'Request renamed');
onClose();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classnames from 'classnames';
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 { addTab, closeTabs, focusTab } from 'providers/ReduxStore/slices/tabs';
import { moveItem, showInFolder, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
import Dropdown from 'components/Dropdown';
Expand Down Expand Up @@ -54,7 +54,14 @@ const CollectionItem = ({ item, collection, searchText }) => {
accept: `COLLECTION_ITEM_${collection.uid}`,
drop: (draggedItem) => {
if (draggedItem.uid !== item.uid) {
dispatch(moveItem(collection.uid, draggedItem.uid, item.uid));
dispatch(moveItem(collection.uid, draggedItem.uid, item.uid)).then(() => {
if (isItemAFolder(draggedItem)) {
dispatch(closeTabs({ tabUids: [draggedItem.uid] }));
toast.success('Folder moved!');
} else {
toast.success('Request moved!');
}
});
}
},
canDrop: (draggedItem) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import Dropdown from 'components/Dropdown';
import { collapseCollection } from 'providers/ReduxStore/slices/collections';
import { mountCollection, moveItemToRootOfCollection } from 'providers/ReduxStore/slices/collections/actions';
import { useDispatch } from 'react-redux';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import { addTab, closeTabs } from 'providers/ReduxStore/slices/tabs';
import NewRequest from 'components/Sidebar/NewRequest';
import NewFolder from 'components/Sidebar/NewFolder';
import CollectionItem from './CollectionItem';
import RemoveCollection from './RemoveCollection';
import ExportCollection from './ExportCollection';
import { doesCollectionHaveItemsMatchingSearchText } from 'utils/collections/search';
import { isItemAFolder, isItemARequest } from 'utils/collections';
import { isItemAFolder, isItemARequest, transformCollectionToSaveToExportAsFile } from 'utils/collections';
import { toast } from 'react-hot-toast';
import exportCollection from 'utils/collections/export';

import RenameCollection from './RenameCollection';
import StyledWrapper from './StyledWrapper';
Expand Down Expand Up @@ -108,7 +110,14 @@ const Collection = ({ collection, searchText }) => {
const [{ isOver }, drop] = useDrop({
accept: `COLLECTION_ITEM_${collection.uid}`,
drop: (draggedItem) => {
dispatch(moveItemToRootOfCollection(collection.uid, draggedItem.uid));
dispatch(moveItemToRootOfCollection(collection.uid, draggedItem.uid)).then(() => {
if (isItemAFolder(draggedItem)) {
dispatch(closeTabs({ tabUids: [draggedItem.uid] }));
toast.success('Folder moved!');
} else {
toast.success('Request moved!');
}
});
},
canDrop: (draggedItem) => {
// todo need to make sure that draggedItem belongs to the collection
Expand Down