+
+
+
Hold on..
+
+
+ Do you want to save the changes you made to the following{' '}
+ {currentDrafts.length} {pluralizeWord('request', currentDrafts.length)}?
+
+
+
+ {currentDrafts.slice(0, MAX_UNSAVED_REQUESTS_TO_SHOW).map((item) => {
+ return (
+ -
+ {item.filename}
+
+ );
+ })}
+
+
+ {currentDrafts.length > MAX_UNSAVED_REQUESTS_TO_SHOW && (
+
+ ...{currentDrafts.length - MAX_UNSAVED_REQUESTS_TO_SHOW} additional{' '}
+ {pluralizeWord('request', currentDrafts.length - MAX_UNSAVED_REQUESTS_TO_SHOW)} not shown
+
+ )}
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default ConfirmCollectionCloseDrafts;
diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollection/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollection/index.js
index 17b6dc007..44007deb6 100644
--- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollection/index.js
+++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/RemoveCollection/index.js
@@ -1,15 +1,24 @@
-import React from 'react';
+import React, { useMemo } from 'react';
import toast from 'react-hot-toast';
import Modal from 'components/Modal';
import { useDispatch, useSelector } from 'react-redux';
import { IconFiles } from '@tabler/icons';
import { removeCollection } from 'providers/ReduxStore/slices/collections/actions';
-import { findCollectionByUid } from 'utils/collections/index';
+import { findCollectionByUid, flattenItems, isItemARequest, hasRequestChanges } from 'utils/collections/index';
+import filter from 'lodash/filter';
+import ConfirmCollectionCloseDrafts from './ConfirmCollectionCloseDrafts';
const RemoveCollection = ({ onClose, collectionUid }) => {
const dispatch = useDispatch();
const collection = useSelector(state => findCollectionByUid(state.collections.collections, collectionUid));
+ // Detect drafts in the collection
+ const drafts = useMemo(() => {
+ if (!collection) return [];
+ const items = flattenItems(collection.items);
+ return filter(items, (item) => isItemARequest(item) && hasRequestChanges(item));
+ }, [collection]);
+
const onConfirm = () => {
dispatch(removeCollection(collection.uid))
.then(() => {
@@ -19,6 +28,12 @@ const RemoveCollection = ({ onClose, collectionUid }) => {
.catch(() => toast.error('An error occurred while closing the collection'));
};
+ // If there are drafts, show the draft confirmation modal
+ if (drafts.length > 0) {
+ return