@@ -14,6 +14,7 @@ import {
14
14
CSpinner ,
15
15
} from '@coreui/react'
16
16
import useQuery from 'src/hooks/useQuery'
17
+ import PropTypes from 'prop-types'
17
18
import { Field , Form , FormSpy } from 'react-final-form'
18
19
import { RFFCFormInput , RFFCFormSelect } from 'src/components/forms'
19
20
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
@@ -25,6 +26,7 @@ import {
25
26
faCheck ,
26
27
faCross ,
27
28
faTimes ,
29
+ faSync ,
28
30
faExclamation ,
29
31
} from '@fortawesome/free-solid-svg-icons'
30
32
import { CippTable , cellBooleanFormatter } from 'src/components/tables'
@@ -38,10 +40,15 @@ import { CellTip, cellGenericFormatter } from 'src/components/tables/CellGeneric
38
40
import { useExecBestPracticeAnalyserMutation } from 'src/store/api/reports'
39
41
import { ModalService } from 'src/components/utilities'
40
42
import { cellTableFormatter } from 'src/components/tables/CellTable'
41
- const RefreshAction = ( ) => {
42
- const [ execBestPracticeAnalyser , { isLoading, isSuccess, error } ] =
43
- useExecBestPracticeAnalyserMutation ( )
44
43
44
+ const RefreshAction = ( { singleTenant = false , refreshFunction = null } ) => {
45
+ const tenantDomain = useSelector ( ( state ) => state . app . currentTenant . defaultDomainName )
46
+ const [ execBestPracticeAnalyser , { isLoading, isSuccess, error } ] =
47
+ useLazyGenericGetRequestQuery ( )
48
+ var params = { }
49
+ if ( singleTenant ) {
50
+ params [ 'TenantFilter' ] = tenantDomain
51
+ }
45
52
const showModal = ( ) =>
46
53
ModalService . confirm ( {
47
54
body : (
@@ -51,18 +58,39 @@ const RefreshAction = () => {
51
58
< i > Please note: this runs at 3:00 AM UTC automatically every day.</ i >
52
59
</ div >
53
60
) ,
54
- onConfirm : ( ) => execBestPracticeAnalyser ( ) ,
61
+ onConfirm : ( ) =>
62
+ execBestPracticeAnalyser ( {
63
+ path : 'api/BestPracticeAnalyser_OrchestrationStarter' ,
64
+ params : params ,
65
+ } ) ,
55
66
} )
56
67
57
68
return (
58
- < CButton onClick = { showModal } size = "sm" className = "m-1" >
59
- { isLoading && < CSpinner size = "sm" /> }
60
- { error && < FontAwesomeIcon icon = { faExclamationTriangle } className = "pe-1" /> }
61
- { isSuccess && < FontAwesomeIcon icon = { faCheck } className = "pe-1" /> }
62
- Force Refresh All Data
63
- </ CButton >
69
+ < >
70
+ < CButton onClick = { showModal } size = "sm" className = "m-1" >
71
+ { isLoading && < CSpinner size = "sm" /> }
72
+ { error && < FontAwesomeIcon icon = { faExclamationTriangle } className = "pe-1" /> }
73
+ { isSuccess && < FontAwesomeIcon icon = { faCheck } className = "pe-1" /> }
74
+ { ( singleTenant && 'Refresh Tenant Data' ) || 'Force Refresh All Data' }
75
+ </ CButton >
76
+ { refreshFunction !== null && (
77
+ < CButton
78
+ onClick = { ( ) => {
79
+ refreshFunction ( ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) )
80
+ } }
81
+ className = "m-1"
82
+ size = "sm"
83
+ >
84
+ < FontAwesomeIcon icon = { faSync } />
85
+ </ CButton >
86
+ ) }
87
+ </ >
64
88
)
65
89
}
90
+ RefreshAction . propTypes = {
91
+ singleTenant : PropTypes . bool ,
92
+ refreshFunction : PropTypes . func ,
93
+ }
66
94
67
95
const getsubcolumns = ( data ) => {
68
96
const flatObj = data && data . length > 0 ? data : [ { data : 'No Data Found' } ]
@@ -96,6 +124,7 @@ const getNestedValue = (obj, path) => {
96
124
}
97
125
const BestPracticeAnalyser = ( ) => {
98
126
const [ reportTemplate , setReportTemplate ] = useState ( 'CIPP Best Practices v1.0 - Table view' )
127
+ const [ refreshValue , setRefreshValue ] = useState ( '' )
99
128
const { data : templates = [ ] , isLoading : templatesfetch } = useGenericGetRequestQuery ( {
100
129
path : 'api/listBPATemplates' ,
101
130
} )
@@ -184,9 +213,10 @@ const BestPracticeAnalyser = () => {
184
213
tenantFilter : tenant . customerId ,
185
214
Report : reportTemplate ,
186
215
SearchNow : SearchNow ,
216
+ refresh : refreshValue ,
187
217
} ,
188
218
} )
189
- } , [ Report , execGraphRequest , tenant . defaultDomainName , query ] )
219
+ } , [ Report , execGraphRequest , tenant . defaultDomainName , query , refreshValue , reportTemplate ] )
190
220
191
221
return (
192
222
< >
@@ -264,7 +294,12 @@ const BestPracticeAnalyser = () => {
264
294
data = { graphrequest . data . Data }
265
295
isFetching = { graphrequest . isFetching }
266
296
tableProps = { {
267
- actions : [ < RefreshAction key = "refresh-action-button" /> ] ,
297
+ actions : [
298
+ < RefreshAction
299
+ key = "refresh-action-button"
300
+ refreshFunction = { setRefreshValue }
301
+ /> ,
302
+ ] ,
268
303
} }
269
304
/>
270
305
</ CCardBody >
@@ -273,6 +308,13 @@ const BestPracticeAnalyser = () => {
273
308
{ graphrequest . isSuccess && QueryColumns . set && graphrequest . data . Style == 'Tenant' && (
274
309
< >
275
310
< CRow >
311
+ < div width = "30px" className = "mb-3" >
312
+ < RefreshAction
313
+ key = "refresh-action-button"
314
+ singleTenant = { true }
315
+ refreshFunction = { setRefreshValue }
316
+ />
317
+ </ div >
276
318
{ graphrequest . data . Columns . map ( ( info , idx ) => (
277
319
< CCol md = { 12 } xl = { 4 } className = "mb-3" >
278
320
< CCard className = "h-100" >
0 commit comments