@@ -5,8 +5,10 @@ import { $workflowCategories } from 'app/store/nanostores/workflowCategories';
5
5
import { useAppDispatch , useAppSelector } from 'app/store/storeHooks' ;
6
6
import { WORKFLOW_TAGS , type WorkflowTag } from 'features/nodes/store/types' ;
7
7
import {
8
+ selectWorkflowIsRecent ,
8
9
selectWorkflowLibrarySelectedTags ,
9
10
selectWorkflowSelectedCategories ,
11
+ workflowIsRecentChanged ,
10
12
workflowSelectedCategoriesChanged ,
11
13
workflowSelectedTagsRese ,
12
14
workflowSelectedTagToggled ,
@@ -18,7 +20,7 @@ import { memo, useCallback, useMemo } from 'react';
18
20
import { useTranslation } from 'react-i18next' ;
19
21
import { PiArrowCounterClockwiseBold , PiUsersBold } from 'react-icons/pi' ;
20
22
import { useDispatch } from 'react-redux' ;
21
- import { useGetCountsQuery , useListWorkflowsQuery } from 'services/api/endpoints/workflows' ;
23
+ import { useGetCountsQuery } from 'services/api/endpoints/workflows' ;
22
24
import type { S } from 'services/api/types' ;
23
25
24
26
export const WorkflowLibrarySideNav = ( ) => {
@@ -27,21 +29,31 @@ export const WorkflowLibrarySideNav = () => {
27
29
const categories = useAppSelector ( selectWorkflowSelectedCategories ) ;
28
30
const categoryOptions = useStore ( $workflowCategories ) ;
29
31
const selectedTags = useAppSelector ( selectWorkflowLibrarySelectedTags ) ;
32
+ const isRecent = useAppSelector ( selectWorkflowIsRecent ) ;
30
33
31
34
const selectYourWorkflows = useCallback ( ( ) => {
32
35
dispatch ( workflowSelectedCategoriesChanged ( categoryOptions . includes ( 'project' ) ? [ 'user' , 'project' ] : [ 'user' ] ) ) ;
36
+ dispatch ( workflowIsRecentChanged ( undefined ) ) ;
33
37
} , [ categoryOptions , dispatch ] ) ;
34
38
35
39
const selectPrivateWorkflows = useCallback ( ( ) => {
36
40
dispatch ( workflowSelectedCategoriesChanged ( [ 'user' ] ) ) ;
41
+ dispatch ( workflowIsRecentChanged ( undefined ) ) ;
37
42
} , [ dispatch ] ) ;
38
43
39
44
const selectSharedWorkflows = useCallback ( ( ) => {
40
45
dispatch ( workflowSelectedCategoriesChanged ( [ 'project' ] ) ) ;
46
+ dispatch ( workflowIsRecentChanged ( undefined ) ) ;
41
47
} , [ dispatch ] ) ;
42
48
43
49
const selectDefaultWorkflows = useCallback ( ( ) => {
44
50
dispatch ( workflowSelectedCategoriesChanged ( [ 'default' ] ) ) ;
51
+ dispatch ( workflowIsRecentChanged ( undefined ) ) ;
52
+ } , [ dispatch ] ) ;
53
+
54
+ const selectRecentWorkflows = useCallback ( ( ) => {
55
+ dispatch ( workflowIsRecentChanged ( true ) ) ;
56
+ dispatch ( workflowSelectedCategoriesChanged ( [ 'default' , 'user' , 'project' ] ) ) ;
45
57
} , [ dispatch ] ) ;
46
58
47
59
const resetTags = useCallback ( ( ) => {
@@ -50,33 +62,34 @@ export const WorkflowLibrarySideNav = () => {
50
62
51
63
const isYourWorkflowsSelected = useMemo ( ( ) => {
52
64
if ( categoryOptions . includes ( 'project' ) ) {
53
- return categories . includes ( 'user' ) && categories . includes ( 'project' ) ;
65
+ return categories . includes ( 'user' ) && categories . includes ( 'project' ) && isRecent === undefined ;
54
66
} else {
55
- return categories . includes ( 'user' ) ;
67
+ return categories . includes ( 'user' ) && isRecent === undefined ;
56
68
}
57
- } , [ categoryOptions , categories ] ) ;
69
+ } , [ categoryOptions , categories , isRecent ] ) ;
58
70
59
71
const isPrivateWorkflowsExclusivelySelected = useMemo ( ( ) => {
60
- return categories . length === 1 && categories . includes ( 'user' ) ;
61
- } , [ categories ] ) ;
72
+ return categories . length === 1 && categories . includes ( 'user' ) && isRecent === undefined ;
73
+ } , [ categories , isRecent ] ) ;
62
74
63
75
const isSharedWorkflowsExclusivelySelected = useMemo ( ( ) => {
64
- return categories . length === 1 && categories . includes ( 'project' ) ;
65
- } , [ categories ] ) ;
76
+ return categories . length === 1 && categories . includes ( 'project' ) && isRecent === undefined ;
77
+ } , [ categories , isRecent ] ) ;
66
78
67
79
const isDefaultWorkflowsExclusivelySelected = useMemo ( ( ) => {
68
- return categories . length === 1 && categories . includes ( 'default' ) ;
69
- } , [ categories ] ) ;
80
+ return categories . length === 1 && categories . includes ( 'default' ) && isRecent === undefined ;
81
+ } , [ categories , isRecent ] ) ;
82
+
83
+ const isRecentWorkflowsSelected = useMemo ( ( ) => {
84
+ return categories . length === 3 && ! ! isRecent ;
85
+ } , [ categories , isRecent ] ) ;
70
86
71
87
return (
72
88
< Flex h = "full" minH = { 0 } overflow = "hidden" flexDir = "column" w = { 64 } gap = { 1 } >
73
89
< Flex flexDir = "column" w = "full" pb = { 2 } >
74
- < Text px = { 3 } py = { 2 } fontSize = "md" fontWeight = "semibold" >
90
+ < CategoryButton isSelected = { isRecentWorkflowsSelected } onClick = { selectRecentWorkflows } >
75
91
{ t ( 'workflows.recentlyOpened' ) }
76
- </ Text >
77
- < Flex flexDir = "column" gap = { 2 } pl = { 4 } >
78
- < RecentWorkflows />
79
- </ Flex >
92
+ </ CategoryButton >
80
93
</ Flex >
81
94
< Flex flexDir = "column" w = "full" pb = { 2 } >
82
95
< CategoryButton isSelected = { isYourWorkflowsSelected } onClick = { selectYourWorkflows } >
@@ -148,36 +161,6 @@ export const WorkflowLibrarySideNav = () => {
148
161
) ;
149
162
} ;
150
163
151
- const recentWorkflowsQueryArg = {
152
- page : 0 ,
153
- per_page : 5 ,
154
- order_by : 'opened_at' ,
155
- direction : 'DESC' ,
156
- is_recent : true ,
157
- } satisfies Parameters < typeof useListWorkflowsQuery > [ 0 ] ;
158
-
159
- const RecentWorkflows = memo ( ( ) => {
160
- const { t } = useTranslation ( ) ;
161
- const { data, isLoading } = useListWorkflowsQuery ( recentWorkflowsQueryArg ) ;
162
-
163
- if ( isLoading ) {
164
- return < Text variant = "subtext" > { t ( 'common.loading' ) } </ Text > ;
165
- }
166
-
167
- if ( ! data ) {
168
- return < Text variant = "subtext" > { t ( 'workflows.noRecentWorkflows' ) } </ Text > ;
169
- }
170
-
171
- return (
172
- < >
173
- { data . items . map ( ( workflow ) => {
174
- return < RecentWorkflowButton key = { workflow . workflow_id } workflow = { workflow } /> ;
175
- } ) }
176
- </ >
177
- ) ;
178
- } ) ;
179
- RecentWorkflows . displayName = 'RecentWorkflows' ;
180
-
181
164
const RecentWorkflowButton = memo ( ( { workflow } : { workflow : S [ 'WorkflowRecordListItemWithThumbnailDTO' ] } ) => {
182
165
const loadWorkflow = useLoadWorkflow ( ) ;
183
166
const load = useCallback ( ( ) => {
0 commit comments