@@ -13,14 +13,19 @@ import {
13
13
CSidebarBrand ,
14
14
CButton ,
15
15
CFormSwitch ,
16
+ CLink ,
16
17
} from '@coreui/react'
17
18
import { AppHeaderSearch } from 'src/components/header'
18
- import { TenantSelector } from '../utilities'
19
+ import { CippActionsOffcanvas , TenantSelector } from '../utilities'
19
20
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
20
21
import { faBars } from '@fortawesome/free-solid-svg-icons'
21
22
import { setCurrentTheme , setUserSettings , toggleSidebarShow } from 'src/store/features/app'
22
23
import { useMediaPredicate } from 'react-media-hook'
23
- import { useGenericGetRequestQuery , useLoadAlertsDashQuery } from 'src/store/api/app'
24
+ import {
25
+ useGenericGetRequestQuery ,
26
+ useLazyGenericGetRequestQuery ,
27
+ useLoadAlertsDashQuery ,
28
+ } from 'src/store/api/app'
24
29
import { useLocation } from 'react-router-dom'
25
30
26
31
const AppHeader = ( ) => {
@@ -31,6 +36,11 @@ const AppHeader = () => {
31
36
const sidebarShow = useSelector ( ( state ) => state . app . sidebarShow )
32
37
const currentTheme = useSelector ( ( state ) => state . app . currentTheme )
33
38
const preferredTheme = useMediaPredicate ( '(prefers-color-scheme: dark)' ) ? 'impact' : 'cyberdrain'
39
+ const [ cippQueueExtendedInfo , setCippQueueExtendedInfo ] = useState ( [ ] )
40
+ const [ cippQueueVisible , setCippQueueVisible ] = useState ( false )
41
+ const [ cippQueueRefresh , setCippQueueRefresh ] = useState (
42
+ ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ,
43
+ )
34
44
const { data : dashboard } = useLoadAlertsDashQuery ( )
35
45
const {
36
46
data : userSettings ,
@@ -54,6 +64,49 @@ const AppHeader = () => {
54
64
userSettings ,
55
65
] )
56
66
67
+ const [ getCippQueueList , cippQueueList ] = useLazyGenericGetRequestQuery ( )
68
+
69
+ function loadCippQueue ( ) {
70
+ setCippQueueVisible ( true )
71
+ getCippQueueList ( { path : 'api/ListCippQueue' , params : { refresh : cippQueueRefresh } } )
72
+ }
73
+
74
+ function refreshCippQueue ( ) {
75
+ setCippQueueRefresh ( ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) )
76
+ loadCippQueue ( )
77
+ }
78
+
79
+ useEffect ( ( ) => {
80
+ if ( cippQueueList . isFetching || cippQueueList . isLoading ) {
81
+ setCippQueueExtendedInfo ( [
82
+ {
83
+ label : 'Fetching recent jobs' ,
84
+ value : 'Please wait' ,
85
+ timestamp : Date ( ) ,
86
+ link : '#' ,
87
+ } ,
88
+ ] )
89
+ }
90
+ if (
91
+ cippQueueList . isSuccess &&
92
+ Array . isArray ( cippQueueList . data ) &&
93
+ cippQueueList . data . length > 0
94
+ ) {
95
+ setCippQueueExtendedInfo (
96
+ cippQueueList . data ?. map ( ( job ) => ( {
97
+ label : `${ job . Name } ` ,
98
+ value : job . Status ,
99
+ link : job . Link ,
100
+ timestamp : job . Timestamp ,
101
+ } ) ) ,
102
+ )
103
+ } else {
104
+ setCippQueueExtendedInfo ( [
105
+ { label : 'No jobs to display' , value : '' , timpestamp : Date ( ) , link : '#' } ,
106
+ ] )
107
+ }
108
+ } , [ cippQueueList ] )
109
+
57
110
const SwitchTheme = ( ) => {
58
111
let targetTheme = preferredTheme
59
112
if ( isDark ) {
@@ -97,6 +150,11 @@ const AppHeader = () => {
97
150
< CNavItem >
98
151
< AppHeaderSearch />
99
152
</ CNavItem >
153
+ < CNavItem >
154
+ < CButton variant = "ghost" onClick = { ( ) => loadCippQueue ( ) } >
155
+ < FontAwesomeIcon icon = { 'history' } className = "me-2" />
156
+ </ CButton >
157
+ </ CNavItem >
100
158
< CNavItem >
101
159
< div className = "custom-switch-wrapper primary" >
102
160
< CFormSwitch
@@ -134,6 +192,26 @@ const AppHeader = () => {
134
192
</ div >
135
193
) ) }
136
194
</ div >
195
+ < CippActionsOffcanvas
196
+ title = "Recent Jobs"
197
+ extendedInfo = { [ ] }
198
+ cards = { cippQueueExtendedInfo }
199
+ refreshFunction = { refreshCippQueue }
200
+ actions = { [
201
+ {
202
+ label : 'Clear History' ,
203
+ color : 'info' ,
204
+ modal : true ,
205
+ modalUrl : `/api/RemoveCippQueue` ,
206
+ modalMessage : 'Are you sure you want clear the history?' ,
207
+ icon : < FontAwesomeIcon icon = "trash" className = "me-2" /> ,
208
+ } ,
209
+ ] }
210
+ placement = "end"
211
+ visible = { cippQueueVisible }
212
+ id = "cipp-queue"
213
+ hideFunction = { ( ) => setCippQueueVisible ( false ) }
214
+ />
137
215
</ >
138
216
)
139
217
}
0 commit comments