4
4
*/
5
5
6
6
import React , { useState , useEffect } from 'react' ;
7
- import { useSelector } from 'react-redux' ;
7
+ import { useDispatch , useSelector } from 'react-redux' ;
8
8
import { debounce } from 'lodash' ;
9
9
import {
10
10
EuiInMemoryTable ,
@@ -13,8 +13,9 @@ import {
13
13
EuiFlexItem ,
14
14
EuiFilterSelectItem ,
15
15
EuiFieldSearch ,
16
+ EuiLoadingSpinner ,
16
17
} from '@elastic/eui' ;
17
- import { AppState } from '../../../store' ;
18
+ import { AppState , deleteWorkflow } from '../../../store' ;
18
19
import { Workflow } from '../../../../common' ;
19
20
import { columns } from './columns' ;
20
21
import { MultiSelectFilter } from '../../../general_components' ;
@@ -33,7 +34,10 @@ const sorting = {
33
34
* The searchable list of created workflows.
34
35
*/
35
36
export function WorkflowList ( props : WorkflowListProps ) {
36
- const { workflows } = useSelector ( ( state : AppState ) => state . workflows ) ;
37
+ const dispatch = useDispatch ( ) ;
38
+ const { workflows, loading } = useSelector (
39
+ ( state : AppState ) => state . workflows
40
+ ) ;
37
41
38
42
// search bar state
39
43
const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
@@ -58,6 +62,19 @@ export function WorkflowList(props: WorkflowListProps) {
58
62
) ;
59
63
} , [ selectedStates , searchQuery , workflows ] ) ;
60
64
65
+ const tableActions = [
66
+ {
67
+ name : 'Delete' ,
68
+ description : 'Delete this workflow' ,
69
+ type : 'icon' ,
70
+ icon : 'trash' ,
71
+ color : 'danger' ,
72
+ onClick : ( item : Workflow ) => {
73
+ dispatch ( deleteWorkflow ( item . id ) ) ;
74
+ } ,
75
+ } ,
76
+ ] ;
77
+
61
78
return (
62
79
< EuiFlexGroup direction = "column" >
63
80
< EuiFlexItem >
@@ -80,10 +97,18 @@ export function WorkflowList(props: WorkflowListProps) {
80
97
< EuiInMemoryTable < Workflow >
81
98
items = { filteredWorkflows }
82
99
rowHeader = "name"
83
- columns = { columns }
100
+ // @ts -ignore
101
+ columns = { columns ( tableActions ) }
84
102
sorting = { sorting }
85
103
pagination = { true }
86
- message = { 'No existing workflows found' }
104
+ message = {
105
+ loading === true ? (
106
+ < EuiLoadingSpinner size = "xl" />
107
+ ) : (
108
+ 'No existing workflows found'
109
+ )
110
+ }
111
+ hasActions = { true }
87
112
/>
88
113
</ EuiFlexItem >
89
114
</ EuiFlexGroup >
0 commit comments