1
1
import React , { useEffect , useState } from 'react'
2
2
import {
3
+ CBadge ,
3
4
CButton ,
4
5
CCard ,
5
6
CCardBody ,
6
7
CCardHeader ,
8
+ CCardText ,
7
9
CCardTitle ,
8
10
CCol ,
9
11
CCollapse ,
@@ -21,6 +23,9 @@ import {
21
23
faSearch ,
22
24
faExclamationTriangle ,
23
25
faCheck ,
26
+ faCross ,
27
+ faTimes ,
28
+ faExclamation ,
24
29
} from '@fortawesome/free-solid-svg-icons'
25
30
import { CippTable , cellBooleanFormatter } from 'src/components/tables'
26
31
import { useSelector } from 'react-redux'
@@ -58,6 +63,37 @@ const RefreshAction = () => {
58
63
</ CButton >
59
64
)
60
65
}
66
+
67
+ const getsubcolumns = ( data ) => {
68
+ const flatObj = data && data . length > 0 ? data : [ { data : 'No Data Found' } ]
69
+ const QueryColumns = [ ]
70
+ if ( flatObj [ 0 ] ) {
71
+ Object . keys ( flatObj [ 0 ] ) . map ( ( key ) => {
72
+ QueryColumns . push ( {
73
+ name : key ,
74
+ selector : ( row ) => row [ key ] , // Accessing the property using the key
75
+ sortable : true ,
76
+ exportSelector : key ,
77
+ cell : cellGenericFormatter ( ) ,
78
+ } )
79
+ } )
80
+ }
81
+ return QueryColumns
82
+ }
83
+ const getNestedValue = ( obj , path ) => {
84
+ if ( ! path ) return undefined
85
+ return path . split ( '.' ) . reduce ( ( acc , part ) => {
86
+ // Check for an array marker
87
+ const match = part . match ( / ( .* ?) \[ ( \d + ) \] / )
88
+ if ( match ) {
89
+ const propName = match [ 1 ]
90
+ const index = parseInt ( match [ 2 ] , 10 )
91
+ return acc [ propName ] ? acc [ propName ] [ index ] : undefined
92
+ }
93
+ // If no array marker, simply return the property value
94
+ return acc ? acc [ part ] : undefined
95
+ } , obj )
96
+ }
61
97
const BestPracticeAnalyser = ( ) => {
62
98
const { data : templates = [ ] , isLoading : templatesfetch } = useGenericGetRequestQuery ( {
63
99
path : 'api/listBPATemplates' ,
@@ -73,6 +109,7 @@ const BestPracticeAnalyser = () => {
73
109
const shippedValues = {
74
110
SearchNow : true ,
75
111
Report : values . reportTemplate ,
112
+ tenantFilter : tenant . customerId ,
76
113
random : ( Math . random ( ) + 1 ) . toString ( 36 ) . substring ( 7 ) ,
77
114
}
78
115
var queryString = Object . keys ( shippedValues )
@@ -99,21 +136,6 @@ const BestPracticeAnalyser = () => {
99
136
if ( graphrequest . data . length === 0 ) {
100
137
graphrequest . data = [ { data : 'No Data Found' } ]
101
138
}
102
-
103
- const getNestedValue = ( obj , path ) => {
104
- if ( ! path ) return undefined
105
- return path . split ( '.' ) . reduce ( ( acc , part ) => {
106
- // Check for an array marker
107
- const match = part . match ( / ( .* ?) \[ ( \d + ) \] / )
108
- if ( match ) {
109
- const propName = match [ 1 ]
110
- const index = parseInt ( match [ 2 ] , 10 )
111
- return acc [ propName ] ? acc [ propName ] [ index ] : undefined
112
- }
113
- // If no array marker, simply return the property value
114
- return acc ? acc [ part ] : undefined
115
- } , obj )
116
- }
117
139
const flatObj = graphrequest . data . Columns ? graphrequest . data . Columns : [ ]
118
140
119
141
flatObj . map ( ( col ) => {
@@ -157,7 +179,7 @@ const BestPracticeAnalyser = () => {
157
179
execGraphRequest ( {
158
180
path : 'api/listBPA' ,
159
181
params : {
160
- tenantFilter : tenant . defaultDomainName ,
182
+ tenantFilter : tenant . customerId ,
161
183
Report : Report ,
162
184
SearchNow : SearchNow ,
163
185
} ,
@@ -226,13 +248,14 @@ const BestPracticeAnalyser = () => {
226
248
< CippPage title = "Report Results" tenantSelector = { false } >
227
249
{ graphrequest . isUninitialized && < span > Choose a BPA Report to get started.</ span > }
228
250
{ graphrequest . isFetching && < CSpinner /> }
229
- { graphrequest . isSuccess && QueryColumns . set && (
251
+ { graphrequest . isSuccess && QueryColumns . set && graphrequest . data . Style == 'Table' && (
230
252
< CCard className = "content-card" >
231
253
< CCardHeader className = "d-flex justify-content-between align-items-center" >
232
254
< CCardTitle > Best Practice Report</ CCardTitle >
233
255
</ CCardHeader >
234
256
< CCardBody >
235
257
< CippTable
258
+ key = { QueryColumns . data }
236
259
reportName = "BestPracticeAnalyser"
237
260
dynamicColumns = { false }
238
261
columns = { QueryColumns . data }
@@ -245,6 +268,83 @@ const BestPracticeAnalyser = () => {
245
268
</ CCardBody >
246
269
</ CCard >
247
270
) }
271
+ { graphrequest . isSuccess && QueryColumns . set && graphrequest . data . Style == 'Tenant' && (
272
+ < >
273
+ < CRow >
274
+ { graphrequest . data . Columns . map ( ( info , idx ) => (
275
+ < CCol sm = { 10 } md = { 4 } className = "mb-3" >
276
+ < CCard className = "h-100" >
277
+ < CCardHeader >
278
+ < CCardTitle > { info . name } </ CCardTitle >
279
+ </ CCardHeader >
280
+ < CCardBody >
281
+ < CCardText >
282
+ { info . formatter === 'bool' && (
283
+ < CBadge
284
+ color = { graphrequest . data . Data [ info . value ] ? 'info' : 'danger' }
285
+ >
286
+ < FontAwesomeIcon
287
+ icon = { graphrequest . data . Data [ info . value ] ? faCheck : faTimes }
288
+ size = "lg"
289
+ className = "me-1"
290
+ />
291
+ { graphrequest . data . Data [ info . value ] ? 'Yes' : 'No' }
292
+ </ CBadge >
293
+ ) }
294
+ { info . formatter === 'reverseBool' && (
295
+ < CBadge
296
+ color = { graphrequest . data . Data [ info . value ] ? 'danger' : 'info' }
297
+ >
298
+ < FontAwesomeIcon
299
+ icon = { graphrequest . data . Data [ info . value ] ? faTimes : faCheck }
300
+ size = "lg"
301
+ className = "me-1"
302
+ />
303
+ { graphrequest . data . Data [ info . value ] ? 'No' : 'Yes' }
304
+ </ CBadge >
305
+ ) }
306
+ { info . formatter === 'warnBool' && (
307
+ < CBadge
308
+ color = { graphrequest . data . Data [ info . value ] ? 'info' : 'warning' }
309
+ >
310
+ < FontAwesomeIcon
311
+ icon = {
312
+ graphrequest . data . Data [ info . value ] ? faCheck : faExclamation
313
+ }
314
+ size = "lg"
315
+ className = "me-1"
316
+ />
317
+ { graphrequest . data . Data [ info . value ] ? 'Yes' : 'No' }
318
+ </ CBadge >
319
+ ) }
320
+
321
+ { info . formatter === 'table' && (
322
+ < CippTable
323
+ key = { QueryColumns . data }
324
+ reportName = "BestPracticeAnalyser"
325
+ dynamicColumns = { false }
326
+ columns = { getsubcolumns ( graphrequest . data . Data [ info . value ] ) }
327
+ data = { graphrequest . data . Data [ info . value ] }
328
+ isFetching = { graphrequest . isFetching }
329
+ />
330
+ ) }
331
+
332
+ { info . formatter === 'number' && (
333
+ < p class = "fs-1 text-center" >
334
+ { getNestedValue ( graphrequest . data . Data , info . value ) }
335
+ </ p >
336
+ ) }
337
+ </ CCardText >
338
+ < CCardText >
339
+ < small className = "text-medium-emphasis" > { info . desc } </ small >
340
+ </ CCardText >
341
+ </ CCardBody >
342
+ </ CCard >
343
+ </ CCol >
344
+ ) ) }
345
+ </ CRow >
346
+ </ >
347
+ ) }
248
348
</ CippPage >
249
349
</ CCol >
250
350
</ CRow >
0 commit comments