Skip to content

Commit 9fc827d

Browse files
authored
Merge pull request #62 from FlowTestAI/collapsible-attribute
Remember clicks in collections sidebar
2 parents 44bb080 + 7f5e8d5 commit 9fc827d

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
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/components/molecules/sidebar/content/Environment.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
88
import { toast } from 'react-toastify';
99
import Tippy from '@tippyjs/react';
1010
import 'tippy.js/dist/tippy.css';
11+
import useCollectionStore from 'stores/CollectionStore';
1112

1213
const Environment = ({ collectionId, collection }) => {
13-
const [isExpanded, setIsExpanded] = useState(false);
14+
//const [isExpanded, setIsExpanded] = useState(false);
15+
const clickEnvironments = useCollectionStore((state) => state.clickEnvironments);
1416
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
1517
const [envToDelete, setEnvToDelete] = useState('');
1618

@@ -26,7 +28,8 @@ const Environment = ({ collectionId, collection }) => {
2628
const clickFromElementDataSet = event.target.dataset;
2729
const clickFrom = clickFromElementDataSet?.clickFrom;
2830
if (!clickFrom || clickFrom !== 'env-options-menu') {
29-
return setIsExpanded((prev) => !prev);
31+
//return setIsExpanded((prev) => !prev);
32+
clickEnvironments(collectionId);
3033
}
3134
}}
3235
>
@@ -42,7 +45,7 @@ const Environment = ({ collectionId, collection }) => {
4245
pathName={collection.pathname}
4346
/>
4447
</div>
45-
{isExpanded && (
48+
{collection.envCollapsed === false && (
4649
<>
4750
{collection.environments?.map((environment, index) => (
4851
<ul

src/stores/CollectionStore.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ 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: [],
28+
envCollapsed: true,
2729
};
2830
if (!get().collections.find((c) => c.pathname === pathname)) {
2931
set((state) => ({ collections: [...state.collections, collectionObj] }));
@@ -53,6 +55,7 @@ const useCollectionStore = create((set, get) => ({
5355
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
5456
name: directoryName,
5557
type: OBJ_TYPES.folder,
58+
collapsed: true,
5659
items: [],
5760
};
5861
currentSubItems.push(childItem);
@@ -192,6 +195,7 @@ const useCollectionStore = create((set, get) => ({
192195
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
193196
name: directoryName,
194197
type: OBJ_TYPES.folder,
198+
collapsed: true,
195199
items: [],
196200
};
197201
currentSubItems.push(childItem);
@@ -305,6 +309,36 @@ const useCollectionStore = create((set, get) => ({
305309
}),
306310
);
307311
},
312+
clickItem: (item, collectionId) => {
313+
set(
314+
produce((state) => {
315+
if (item) {
316+
if (item.type === OBJ_TYPES.collection) {
317+
const collection = state.collections.find((c) => c.id === collectionId);
318+
if (collection) {
319+
collection.collapsed = !collection.collapsed;
320+
}
321+
} else if (item.type === OBJ_TYPES.folder) {
322+
const collection = state.collections.find((c) => c.id === collectionId);
323+
if (collection) {
324+
const findItem = findItemInCollectionTree(item, collection);
325+
findItem.collapsed = !findItem.collapsed;
326+
}
327+
}
328+
}
329+
}),
330+
);
331+
},
332+
clickEnvironments: (collectionId) => {
333+
set(
334+
produce((state) => {
335+
const collection = state.collections.find((c) => c.id === collectionId);
336+
if (collection) {
337+
collection.envCollapsed = !collection.envCollapsed;
338+
}
339+
}),
340+
);
341+
},
308342
}));
309343

310344
export default useCollectionStore;

0 commit comments

Comments
 (0)