@@ -28,6 +28,13 @@ interface WorkflowNodesTabsProps {
28
28
triggerComponentDefinitions : Array < ComponentDefinitionBasic > ;
29
29
}
30
30
31
+ interface TabConfigProps {
32
+ emptyMessage : string ;
33
+ items : Array < ComponentDefinitionBasic | DefinitionType > | undefined ;
34
+ showFilter ?: boolean ;
35
+ value : string ;
36
+ }
37
+
31
38
const WorkflowNodesTabs = ( {
32
39
actionComponentDefinitions,
33
40
clusterElementComponentDefinitions,
@@ -123,6 +130,64 @@ const WorkflowNodesTabs = ({
123
130
setActiveView ,
124
131
] ) ;
125
132
133
+ const tabConfigs : TabConfigProps [ ] = useMemo (
134
+ ( ) => [
135
+ {
136
+ emptyMessage : 'No trigger components found.' ,
137
+ items : availableTriggers ,
138
+ value : 'triggers' ,
139
+ } ,
140
+ {
141
+ emptyMessage :
142
+ filterState . activeView === 'all' ? 'No action components found.' : 'No filtered components found.' ,
143
+ items : filteredComponents ,
144
+ showFilter : true ,
145
+ value : 'components' ,
146
+ } ,
147
+ {
148
+ emptyMessage : 'No flow controls found.' ,
149
+ items : availableTaskDispatchers ,
150
+ value : 'taskDispatchers' ,
151
+ } ,
152
+ {
153
+ emptyMessage : 'No cluster element components found.' ,
154
+ items : availableClusterElements ,
155
+ value : 'clusterElements' ,
156
+ } ,
157
+ ] ,
158
+ [
159
+ availableTriggers ,
160
+ filteredComponents ,
161
+ availableTaskDispatchers ,
162
+ availableClusterElements ,
163
+ filterState . activeView ,
164
+ ]
165
+ ) ;
166
+
167
+ const renderTabContent = ( config : TabConfigProps ) => (
168
+ < ScrollArea className = "overflow-y-auto px-3" >
169
+ < TabsContent className = "mt-0 w-full flex-1" value = { config . value } >
170
+ < ul className = "space-y-2" role = "list" >
171
+ { ( ! config . items || config . items . length === 0 ) && (
172
+ < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
173
+ { config . emptyMessage }
174
+ </ span >
175
+ ) }
176
+
177
+ { config . items ?. map ( ( item ) => (
178
+ < WorkflowNodesTabsItem
179
+ draggable = { itemsDraggable }
180
+ handleClick = { ( ) => onItemClick && onItemClick ( item as ClickedDefinitionType ) }
181
+ key = { item . name }
182
+ node = { item as DefinitionType }
183
+ selected = { config . value === 'components' ? selectedComponentName === item . name : undefined }
184
+ />
185
+ ) ) }
186
+ </ ul >
187
+ </ TabsContent >
188
+ </ ScrollArea >
189
+ ) ;
190
+
126
191
return (
127
192
< Tabs className = "flex h-full flex-col" onValueChange = { setActiveTab } value = { activeTab } >
128
193
< div className = "px-2" >
@@ -166,112 +231,13 @@ const WorkflowNodesTabs = ({
166
231
/>
167
232
) }
168
233
169
- { ! hideClusterElementComponents && (
170
- < ScrollArea className = "overflow-y-auto px-3" >
171
- < TabsContent className = "mt-0 w-full flex-1" value = "clusterElements" >
172
- < ul className = "space-y-2" role = "list" >
173
- { ! clusterElementComponentDefinitions ?. length && (
174
- < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
175
- No cluster element components found.
176
- </ span >
177
- ) }
234
+ { ! hideClusterElementComponents && renderTabContent ( tabConfigs [ 3 ] ) }
178
235
179
- { availableClusterElements ?. map ( ( clusterElementDefinition , index ) => (
180
- < WorkflowNodesTabsItem
181
- draggable = { itemsDraggable }
182
- handleClick = { ( ) =>
183
- onItemClick && onItemClick ( clusterElementDefinition as ClickedDefinitionType )
184
- }
185
- key = { index }
186
- node = { clusterElementDefinition }
187
- />
188
- ) ) }
189
- </ ul >
190
- </ TabsContent >
191
- </ ScrollArea >
192
- ) }
236
+ { ! hideTriggerComponents && renderTabContent ( tabConfigs [ 0 ] ) }
193
237
194
- { ! hideTriggerComponents && (
195
- < ScrollArea className = "overflow-y-auto px-3" >
196
- < TabsContent className = "mt-0 w-full flex-1" value = "triggers" >
197
- < ul className = "space-y-2" role = "list" >
198
- { ! triggerComponentDefinitions . length && (
199
- < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
200
- No trigger components found.
201
- </ span >
202
- ) }
238
+ { ! hideActionComponents && renderTabContent ( tabConfigs [ 1 ] ) }
203
239
204
- { availableTriggers . map ( ( triggerDefinition ) => (
205
- < WorkflowNodesTabsItem
206
- draggable = { itemsDraggable }
207
- handleClick = { ( ) =>
208
- onItemClick && onItemClick ( triggerDefinition as ClickedDefinitionType )
209
- }
210
- key = { triggerDefinition . name }
211
- node = { triggerDefinition as DefinitionType }
212
- />
213
- ) ) }
214
- </ ul >
215
- </ TabsContent >
216
- </ ScrollArea >
217
- ) }
218
-
219
- { ! hideActionComponents && (
220
- < ScrollArea className = "overflow-y-auto px-3" >
221
- < TabsContent className = "mt-0 w-full flex-1" value = "components" >
222
- < ul className = "space-y-2" role = "list" >
223
- { actionComponentDefinitions . length === 0 && filterState . activeView === 'all' && (
224
- < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
225
- No action components found.
226
- </ span >
227
- ) }
228
-
229
- { filteredComponents ?. length === 0 && filterState . activeView === 'filtered' && (
230
- < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
231
- No filtered components found.
232
- </ span >
233
- ) }
234
-
235
- { filteredComponents ?. map ( ( componentDefinition ) => (
236
- < WorkflowNodesTabsItem
237
- draggable = { itemsDraggable }
238
- handleClick = { ( ) =>
239
- onItemClick && onItemClick ( componentDefinition as ClickedDefinitionType )
240
- }
241
- key = { componentDefinition . name }
242
- node = { componentDefinition as DefinitionType }
243
- selected = { selectedComponentName === componentDefinition . name }
244
- />
245
- ) ) }
246
- </ ul >
247
- </ TabsContent >
248
- </ ScrollArea >
249
- ) }
250
-
251
- { ! hideTaskDispatchers && (
252
- < ScrollArea className = "overflow-y-auto px-3" >
253
- < TabsContent className = "mt-0 w-full flex-1" value = "taskDispatchers" >
254
- < ul className = "space-y-2" role = "list" >
255
- { ! taskDispatcherDefinitions . length && (
256
- < span className = "block px-3 py-2 text-xs text-content-neutral-secondary" >
257
- No flow controls found.
258
- </ span >
259
- ) }
260
-
261
- { availableTaskDispatchers . map ( ( taskDispatcherDefinition ) => (
262
- < WorkflowNodesTabsItem
263
- draggable = { itemsDraggable }
264
- handleClick = { ( ) =>
265
- onItemClick && onItemClick ( taskDispatcherDefinition as ClickedDefinitionType )
266
- }
267
- key = { taskDispatcherDefinition . name }
268
- node = { taskDispatcherDefinition as DefinitionType }
269
- />
270
- ) ) }
271
- </ ul >
272
- </ TabsContent >
273
- </ ScrollArea >
274
- ) }
240
+ { ! hideTaskDispatchers && renderTabContent ( tabConfigs [ 2 ] ) }
275
241
</ Tabs >
276
242
) ;
277
243
} ;
0 commit comments