Skip to content

Commit f192e0a

Browse files
committed
Use proper collectionId when deleting items
1 parent 8695ff1 commit f192e0a

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

src/components/atoms/Tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Tabs = () => {
2828
setClosingCollectionId(collectionId);
2929

3030
if (isDirty) {
31-
console.log(`\n \n BHUT HI SAHIIII tabId: ${tabId} : collectionId: ${collectionId}\n \n`);
31+
console.debug(`Confirm close for tabId: ${tabId} : collectionId: ${collectionId}`);
3232
setConfirmActionModalOpen(true);
3333
return;
3434
}

src/components/atoms/sidebar/collections/OptionsMenu.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { Menu, Transition } from '@headlessui/react';
44
import { FolderPlusIcon, PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline';
55
import { EllipsisVerticalIcon } from '@heroicons/react/20/solid';
66
import { DirectoryOptionsActions } from 'constants/WorkspaceDirectory';
7+
import { OBJ_TYPES } from 'constants/Common';
78

8-
const OptionsMenu = ({ directory, itemType }) => {
9+
const OptionsMenu = ({ collectionId, directory, itemType }) => {
910
const menuItemsStyles =
1011
'group flex w-full items-center rounded px-2 py-2 text-sm text-gray-900 transition duration-200 ease-out hover:bg-slate-100';
1112
return (
@@ -43,6 +44,7 @@ const OptionsMenu = ({ directory, itemType }) => {
4344
data-options-menu-item={DirectoryOptionsActions.addNewFolder.value}
4445
data-path-name={directory.pathname}
4546
data-item-type={itemType}
47+
data-collection-id={collectionId}
4648
>
4749
<FolderPlusIcon
4850
className='w-4 h-4 mr-2'
@@ -60,6 +62,7 @@ const OptionsMenu = ({ directory, itemType }) => {
6062
data-options-menu-item={DirectoryOptionsActions.addNewFlow.value}
6163
data-path-name={directory.pathname}
6264
data-item-type={itemType}
65+
data-collection-id={collectionId}
6366
>
6467
<PencilSquareIcon
6568
className='w-4 h-4 mr-2'
@@ -79,14 +82,17 @@ const OptionsMenu = ({ directory, itemType }) => {
7982
data-options-menu-item={DirectoryOptionsActions.delete.value}
8083
data-path-name={directory.pathname}
8184
data-item-type={itemType}
85+
data-collection-id={collectionId}
8286
>
8387
<TrashIcon
8488
className='w-4 h-4 mr-2'
8589
aria-hidden='true'
8690
data-click-from='options-menu'
8791
data-item-type={itemType}
8892
/>
89-
{DirectoryOptionsActions.delete.displayValue}
93+
{itemType === OBJ_TYPES.collection
94+
? DirectoryOptionsActions.remove.displayValue
95+
: DirectoryOptionsActions.delete.displayValue}
9096
</button>
9197
</Menu.Item>
9298
</div>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const Collection = ({ collectionId, item, depth }) => {
3030
directory={item}
3131
data-item-type={OBJ_TYPES.collection}
3232
itemType={OBJ_TYPES.collection}
33+
collectionId={collectionId}
3334
/>
3435
</div>
3536
);
@@ -61,6 +62,7 @@ const Collection = ({ collectionId, item, depth }) => {
6162
directory={item}
6263
data-item-type={OBJ_TYPES.flowtest}
6364
itemType={OBJ_TYPES.flowtest}
65+
collectionId={collectionId}
6466
/>
6567
</div>
6668
);
@@ -86,6 +88,7 @@ const Collection = ({ collectionId, item, depth }) => {
8688
directory={item}
8789
data-item-type={OBJ_TYPES.folder}
8890
itemType={OBJ_TYPES.folder}
91+
collectionId={collectionId}
8992
/>
9093
</div>
9194
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ const Collections = ({ collections }) => {
6363
const itemType = clickFromElementDataSet?.itemType;
6464
const optionsMenuItem = clickFromElementDataSet?.optionsMenuItem;
6565
const pathName = clickFromElementDataSet?.pathName;
66+
const collectionId = clickFromElementDataSet?.collectionId;
6667

6768
setSelectedPathName(pathName);
68-
setSelectedCollectionId(collections[0].id);
69+
setSelectedCollectionId(collectionId);
6970
setSelectedMenuItem(optionsMenuItem);
7071

7172
switch (optionsMenuItem) {

src/constants/WorkspaceDirectory.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const DirectoryOptionsActions = {
99
value: 'delete',
1010
dataSetValue: 'delete',
1111
},
12+
remove: {
13+
displayValue: 'Remove',
14+
value: 'remove',
15+
dataSetValue: 'remove',
16+
},
1217
addNewFlow: {
1318
displayValue: 'New Flow',
1419
value: 'new-flow',

src/stores/CollectionStore.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ const useCollectionStore = create((set, get) => ({
7373
if (collection) {
7474
// if it's the collection itself
7575
if (collection.pathname === directory.pathname && collection.name === directory.name) {
76-
state.deleteCollection(collection.id);
76+
state.collections = state.collections.filter((c) => c.id != collectionId);
77+
console.log(`Collection removed: ${collectionId}`);
78+
79+
// check if there any open tabs, if yes close them
80+
useTabStore.getState().closeCollectionTabs(collectionId);
7781
} else {
7882
const item = findItemInCollectionTree(directory, collection);
7983

0 commit comments

Comments
 (0)