Skip to content

Commit e5fbf35

Browse files
committed
Add confirmation dialog when deleting env, collection, folder and flowtest
1 parent dc6db64 commit e5fbf35

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

src/components/atoms/Tabs.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const Tabs = () => {
1616
'before:absolute before:h-[0.25rem] before:w-full before:bg-slate-300 before:content-[""] before:bottom-0 before:left-0';
1717
const tabCommonStyles =
1818
'tab flex items-center gap-x-2 border-r border-neutral-300 bg-transparent pr-0 tracking-[0.15em] transition duration-500 ease-in text-sm';
19-
const messageForConfirmActionModal =
20-
'Changes for the flow test are not saved, are you sure that you wants to close it?';
19+
const messageForConfirmActionModal = 'You have unsaved changes in the flowtest, are you sure you want to close it?';
2120
const handleCloseTab = (event) => {
2221
event.stopPropagation();
2322
event.preventDefault();
@@ -70,9 +69,6 @@ const Tabs = () => {
7069
open={confirmActionModalOpen}
7170
message={messageForConfirmActionModal}
7271
actionFn={() => {
73-
console.log(
74-
`I AHVEN BEEN CLICIKED : closingTabId: ${closingTabId} : closingCollectionId: ${closingCollectionId}`,
75-
);
7672
closeTab(closingTabId, closingCollectionId);
7773
setConfirmActionModalOpen(false);
7874
}}

src/components/molecules/sidebar/content/Collections.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import { DirectoryOptionsActions } from 'constants/WorkspaceDirectory';
55
import { deleteCollection, deleteFolder, deleteFlowTest } from 'service/collection';
66
import NewLabelModal from 'components/molecules/modals/sidebar/NewLabelModal';
77
import Collection from './Collection';
8+
import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
89

910
const Collections = ({ collections }) => {
1011
const [newLabelModalOpen, setNewLabelModal] = useState(false);
12+
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
13+
1114
const [selectedMenuItem, setSelectedMenuItem] = useState('');
1215
const [selectedPathName, setSelectedPathName] = useState('');
1316
const [selectedCollectionId, setSelectedCollectionId] = useState('');
17+
const [selectedItemType, setSelectedItemType] = useState('');
18+
19+
const messageForConfirmActionModal = `Do you wish to delete ${selectedItemType}`;
1420

1521
const handleDeleteMenuItem = (menuItemType, path, collectionId) => {
1622
if (menuItemType === OBJ_TYPES.collection) {
@@ -70,7 +76,8 @@ const Collections = ({ collections }) => {
7076
setNewLabelModal(true);
7177
break;
7278
case DirectoryOptionsActions.delete.value:
73-
handleDeleteMenuItem(itemType, pathName, collections[0].id);
79+
setSelectedItemType(itemType);
80+
setConfirmActionModalOpen(true);
7481
break;
7582
default:
7683
// need to return an error here
@@ -91,6 +98,15 @@ const Collections = ({ collections }) => {
9198
collectionId={selectedCollectionId}
9299
menuOption={selectedMenuItem}
93100
/>
101+
<ConfirmActionModal
102+
closeFn={() => setConfirmActionModalOpen(false)}
103+
open={confirmActionModalOpen}
104+
message={messageForConfirmActionModal}
105+
actionFn={() => {
106+
handleDeleteMenuItem(selectedItemType, selectedPathName, selectedCollectionId);
107+
setConfirmActionModalOpen(false);
108+
}}
109+
/>
94110
</div>
95111
);
96112
};

src/components/molecules/sidebar/content/Environment.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import { ArchiveBoxIcon, DocumentIcon, TrashIcon } from '@heroicons/react/24/out
44
import { OBJ_TYPES } from 'constants/Common';
55
import { deleteEnvironmentFile } from 'service/collection';
66
import EnvOptionsMenu from 'components/atoms/sidebar/environments/EnvOptionsMenu';
7+
import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
78

89
const Environment = ({ collectionId, collection }) => {
910
const [isExpanded, setIsExpanded] = useState(false);
11+
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
12+
const [envToDelete, setEnvToDelete] = useState('');
13+
14+
const messageForConfirmActionModal = 'Do you wish to delete this environment';
15+
1016
return (
1117
<>
1218
<li>
@@ -46,18 +52,8 @@ const Environment = ({ collectionId, collection }) => {
4652
<div
4753
className='relative inline-block p-2 text-left transition duration-200 ease-out rounded rounded-l-none hover:bg-slate-200'
4854
onClick={() => {
49-
deleteEnvironmentFile(environment.name, collectionId)
50-
.then((result) => {
51-
console.log(
52-
`Deleted environment: name = ${environment.name}, path = ${environment.pathname}, collectionId = ${collectionId}, result: ${result}`,
53-
);
54-
})
55-
.catch((error) => {
56-
// TODO: show error in UI
57-
console.log(
58-
`Error deleting environment: name = ${environment.name}, path = ${environment.pathname}, collectionId = ${collectionId} and error: ${error}`,
59-
);
60-
});
55+
setEnvToDelete(environment.name);
56+
setConfirmActionModalOpen(true);
6157
}}
6258
>
6359
<TrashIcon className='w-4 h-4' aria-hidden='true' />
@@ -69,6 +65,26 @@ const Environment = ({ collectionId, collection }) => {
6965
</>
7066
)}
7167
</li>
68+
<ConfirmActionModal
69+
closeFn={() => setConfirmActionModalOpen(false)}
70+
open={confirmActionModalOpen}
71+
message={messageForConfirmActionModal}
72+
actionFn={() => {
73+
deleteEnvironmentFile(envToDelete, collectionId)
74+
.then((result) => {
75+
console.log(
76+
`Deleted environment: name = ${envToDelete}, collectionId = ${collectionId}, result: ${result}`,
77+
);
78+
})
79+
.catch((error) => {
80+
// TODO: show error in UI
81+
console.log(
82+
`Error deleting environment: name = ${envToDelete}, collectionId = ${collectionId} and error: ${error}`,
83+
);
84+
});
85+
setConfirmActionModalOpen(false);
86+
}}
87+
/>
7288
</>
7389
);
7490
};

0 commit comments

Comments
 (0)