Skip to content

Commit be166c8

Browse files
committed
Remember clicks in collections sidebar
1 parent 44bb080 commit be166c8

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import 'tippy.js/dist/tippy.css';
1010
import { DirectoryOptionsActions } from 'constants/WorkspaceDirectory';
1111
import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
1212
import { deleteFlowTest } from 'service/collection';
13+
import useCollectionStore from 'stores/CollectionStore';
1314

1415
const Collection = ({ collectionId, item, depth }) => {
15-
const [isExpanded, setIsExpanded] = useState(false);
16+
//const [isExpanded, setIsExpanded] = useState(false);
17+
const clickItem = useCollectionStore((state) => state.clickItem);
1618
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
1719
const [flowTestPathToDelete, setFlowTestPathToDelete] = useState('');
20+
1821
const messageForConfirmActionModal =
1922
'Do you wish to delete this flowtest? This action deletes it from disk and cannot be undone';
23+
2024
const getListDisplayTitle = () => {
2125
if (item.type === OBJ_TYPES.collection) {
2226
// this is for collections tab thus we have archive box icon
@@ -27,7 +31,8 @@ const Collection = ({ collectionId, item, depth }) => {
2731
const clickFromElementDataSet = event.target.dataset;
2832
const clickFrom = clickFromElementDataSet?.clickFrom;
2933
if (!clickFrom || clickFrom !== 'options-menu') {
30-
return setIsExpanded((prev) => !prev);
34+
clickItem(item, collectionId);
35+
//return setIsExpanded((prev) => !prev);
3136
}
3237
}}
3338
>
@@ -90,7 +95,8 @@ const Collection = ({ collectionId, item, depth }) => {
9095
onClick={(event) => {
9196
const clickFrom = event.target.dataset?.clickFrom;
9297
if (!clickFrom || clickFrom !== 'options-menu') {
93-
return setIsExpanded((prev) => !prev);
98+
clickItem(item, collectionId);
99+
//return setIsExpanded((prev) => !prev);
94100
}
95101
}}
96102
>
@@ -113,7 +119,7 @@ const Collection = ({ collectionId, item, depth }) => {
113119
<>
114120
<li>
115121
{getListDisplayTitle()}
116-
{isExpanded && (
122+
{item.collapsed === false && (
117123
<>
118124
{item.items?.map((childItem, index) => (
119125
<ul

src/stores/CollectionStore.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const useCollectionStore = create((set, get) => ({
2121
type: OBJ_TYPES.collection,
2222
name: name,
2323
pathname: pathname,
24+
collapsed: true,
2425
nodes: nodes,
2526
items: [],
2627
environments: [],
@@ -53,6 +54,7 @@ const useCollectionStore = create((set, get) => ({
5354
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
5455
name: directoryName,
5556
type: OBJ_TYPES.folder,
57+
collapsed: true,
5658
items: [],
5759
};
5860
currentSubItems.push(childItem);
@@ -192,6 +194,7 @@ const useCollectionStore = create((set, get) => ({
192194
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
193195
name: directoryName,
194196
type: OBJ_TYPES.folder,
197+
collapsed: true,
195198
items: [],
196199
};
197200
currentSubItems.push(childItem);
@@ -305,6 +308,26 @@ const useCollectionStore = create((set, get) => ({
305308
}),
306309
);
307310
},
311+
clickItem: (item, collectionId) => {
312+
set(
313+
produce((state) => {
314+
if (item) {
315+
if (item.type === OBJ_TYPES.collection) {
316+
const collection = state.collections.find((c) => c.id === collectionId);
317+
if (collection) {
318+
collection.collapsed = !collection.collapsed;
319+
}
320+
} else if (item.type === OBJ_TYPES.folder) {
321+
const collection = state.collections.find((c) => c.id === collectionId);
322+
if (collection) {
323+
const findItem = findItemInCollectionTree(item, collection);
324+
findItem.collapsed = !findItem.collapsed;
325+
}
326+
}
327+
}
328+
}),
329+
);
330+
},
308331
}));
309332

310333
export default useCollectionStore;

0 commit comments

Comments
 (0)