@@ -2,13 +2,18 @@ import React, { forwardRef, useMemo, useState } from "react";
2
2
import { Link } from "react-router-dom" ;
3
3
import dayjs from "dayjs" ;
4
4
import {
5
+ Dropdown ,
6
+ DropdownItem ,
7
+ DropdownList ,
5
8
EmptyState ,
6
9
EmptyStateActions ,
7
10
EmptyStateBody ,
8
11
EmptyStateFooter ,
9
12
EmptyStateHeader ,
10
13
EmptyStateIcon ,
11
14
EmptyStateVariant ,
15
+ MenuToggle ,
16
+ MenuToggleElement ,
12
17
NotificationDrawer ,
13
18
NotificationDrawerBody ,
14
19
NotificationDrawerHeader ,
@@ -18,15 +23,16 @@ import {
18
23
NotificationDrawerListItemHeader ,
19
24
Tooltip ,
20
25
} from "@patternfly/react-core" ;
21
- import { CubesIcon } from "@patternfly/react-icons" ;
26
+ import { CubesIcon , EllipsisVIcon } from "@patternfly/react-icons" ;
22
27
import { css } from "@patternfly/react-styles" ;
23
28
24
- import { TaskState } from "@app/api/models" ;
29
+ import { Task , TaskState } from "@app/api/models" ;
25
30
import { useTaskManagerContext } from "./TaskManagerContext" ;
26
31
import { useServerTasks } from "@app/queries/tasks" ;
27
32
28
33
import "./TaskManagerDrawer.css" ;
29
34
import { TaskStateIcon } from "../Icons" ;
35
+ import { useTaskActions } from "@app/pages/tasks/useTaskActions" ;
30
36
31
37
/** A version of `Task` specific for the task manager drawer components */
32
38
interface TaskManagerTask {
@@ -47,6 +53,9 @@ interface TaskManagerTask {
47
53
applicationId : number ;
48
54
applicationName : string ;
49
55
preemptEnabled : boolean ;
56
+
57
+ // full object to be used with library functions
58
+ _ : Task ;
50
59
}
51
60
52
61
const PAGE_SIZE = 20 ;
@@ -61,6 +70,9 @@ export const TaskManagerDrawer: React.FC<TaskManagerDrawerProps> = forwardRef(
61
70
const { tasks } = useTaskManagerData ( ) ;
62
71
63
72
const [ expandedItems , setExpandedItems ] = useState < number [ ] > ( [ ] ) ;
73
+ const [ taskWithExpandedActions , setTaskWithExpandedAction ] = useState <
74
+ number | boolean
75
+ > ( false ) ;
64
76
65
77
const closeDrawer = ( ) => {
66
78
setIsExpanded ( ! isExpanded ) ;
@@ -109,6 +121,10 @@ export const TaskManagerDrawer: React.FC<TaskManagerDrawerProps> = forwardRef(
109
121
: expandedItems . filter ( ( i ) => i !== task . id )
110
122
) ;
111
123
} }
124
+ actionsExpanded = { task . id === taskWithExpandedActions }
125
+ onActionsExpandToggle = { ( flag : boolean ) =>
126
+ setTaskWithExpandedAction ( flag && task . id )
127
+ }
112
128
/>
113
129
) ) }
114
130
</ NotificationDrawerList >
@@ -130,13 +146,22 @@ const TaskItem: React.FC<{
130
146
task : TaskManagerTask ;
131
147
expanded : boolean ;
132
148
onExpandToggle : ( expand : boolean ) => void ;
133
- } > = ( { task, expanded, onExpandToggle } ) => {
149
+ actionsExpanded : boolean ;
150
+ onActionsExpandToggle : ( expand : boolean ) => void ;
151
+ } > = ( {
152
+ task,
153
+ expanded,
154
+ onExpandToggle,
155
+ actionsExpanded,
156
+ onActionsExpandToggle,
157
+ } ) => {
134
158
const starttime = dayjs ( task . started ?? task . createTime ) ;
135
159
const title = expanded
136
160
? `${ task . id } (${ task . addon } )`
137
161
: `${ task . id } (${ task . addon } ) - ${ task . applicationName } - ${
138
162
task . priority ?? 0
139
163
} `;
164
+ const taskActionItems = useTaskActions ( task . _ ) ;
140
165
141
166
return (
142
167
< NotificationDrawerListItem
@@ -153,7 +178,36 @@ const TaskItem: React.FC<{
153
178
title = { title }
154
179
icon = { < TaskStateToIcon taskState = { task . state } /> }
155
180
>
156
- { /* Put the item's action menu here */ }
181
+ < Dropdown
182
+ onSelect = { ( ) => onActionsExpandToggle ( false ) }
183
+ isOpen = { actionsExpanded }
184
+ onOpenChange = { ( ) => onActionsExpandToggle ( false ) }
185
+ popperProps = { { position : "right" } }
186
+ toggle = { ( toggleRef : React . Ref < MenuToggleElement > ) => (
187
+ < MenuToggle
188
+ ref = { toggleRef }
189
+ isExpanded = { actionsExpanded }
190
+ isDisabled = { taskActionItems . every ( ( { isDisabled } ) => isDisabled ) }
191
+ onClick = { ( ) => onActionsExpandToggle ( ! actionsExpanded ) }
192
+ variant = "plain"
193
+ aria-label = { `Actions for task ${ task . name } ` }
194
+ >
195
+ < EllipsisVIcon aria-hidden = "true" />
196
+ </ MenuToggle >
197
+ ) }
198
+ >
199
+ < DropdownList >
200
+ { taskActionItems . map ( ( { title, onClick, isDisabled } ) => (
201
+ < DropdownItem
202
+ key = { title }
203
+ onClick = { onClick }
204
+ isDisabled = { isDisabled }
205
+ >
206
+ { title }
207
+ </ DropdownItem >
208
+ ) ) }
209
+ </ DropdownList >
210
+ </ Dropdown >
157
211
</ NotificationDrawerListItemHeader >
158
212
{ expanded ? (
159
213
< NotificationDrawerListItemBody
@@ -217,6 +271,8 @@ const useTaskManagerData = () => {
217
271
applicationName : task . application . name ,
218
272
preemptEnabled : task ?. policy ?. preemptEnabled ?? false ,
219
273
274
+ _ : task ,
275
+
220
276
// TODO: Add any checks that could be needed later...
221
277
// - isCancelable (does the current user own the task? other things to check?)
222
278
// - isPreemptionToggleAllowed
0 commit comments