Skip to content

Commit eaaed26

Browse files
prep for release
1 parent d01b2d1 commit eaaed26

File tree

1 file changed

+113
-17
lines changed

1 file changed

+113
-17
lines changed

src/views/tenant/standards/BestPracticeAnalyser.js

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { useEffect, useState } from 'react'
22
import {
3+
CBadge,
34
CButton,
45
CCard,
56
CCardBody,
67
CCardHeader,
8+
CCardText,
79
CCardTitle,
810
CCol,
911
CCollapse,
@@ -21,6 +23,8 @@ import {
2123
faSearch,
2224
faExclamationTriangle,
2325
faCheck,
26+
faCross,
27+
faTimes,
2428
} from '@fortawesome/free-solid-svg-icons'
2529
import { CippTable, cellBooleanFormatter } from 'src/components/tables'
2630
import { useSelector } from 'react-redux'
@@ -58,6 +62,37 @@ const RefreshAction = () => {
5862
</CButton>
5963
)
6064
}
65+
66+
const getsubcolumns = (data) => {
67+
const flatObj = data && data.length > 0 ? data : [{ data: 'No Data Found' }]
68+
const QueryColumns = []
69+
if (flatObj[0]) {
70+
Object.keys(flatObj[0]).map((key) => {
71+
QueryColumns.push({
72+
name: key,
73+
selector: (row) => row[key], // Accessing the property using the key
74+
sortable: true,
75+
exportSelector: key,
76+
cell: cellGenericFormatter(),
77+
})
78+
})
79+
}
80+
return QueryColumns
81+
}
82+
const getNestedValue = (obj, path) => {
83+
if (!path) return undefined
84+
return path.split('.').reduce((acc, part) => {
85+
// Check for an array marker
86+
const match = part.match(/(.*?)\[(\d+)\]/)
87+
if (match) {
88+
const propName = match[1]
89+
const index = parseInt(match[2], 10)
90+
return acc[propName] ? acc[propName][index] : undefined
91+
}
92+
// If no array marker, simply return the property value
93+
return acc ? acc[part] : undefined
94+
}, obj)
95+
}
6196
const BestPracticeAnalyser = () => {
6297
const { data: templates = [], isLoading: templatesfetch } = useGenericGetRequestQuery({
6398
path: 'api/listBPATemplates',
@@ -73,6 +108,7 @@ const BestPracticeAnalyser = () => {
73108
const shippedValues = {
74109
SearchNow: true,
75110
Report: values.reportTemplate,
111+
tenantFilter: tenant.customerId,
76112
random: (Math.random() + 1).toString(36).substring(7),
77113
}
78114
var queryString = Object.keys(shippedValues)
@@ -99,21 +135,6 @@ const BestPracticeAnalyser = () => {
99135
if (graphrequest.data.length === 0) {
100136
graphrequest.data = [{ data: 'No Data Found' }]
101137
}
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-
}
117138
const flatObj = graphrequest.data.Columns ? graphrequest.data.Columns : []
118139

119140
flatObj.map((col) => {
@@ -157,7 +178,7 @@ const BestPracticeAnalyser = () => {
157178
execGraphRequest({
158179
path: 'api/listBPA',
159180
params: {
160-
tenantFilter: tenant.defaultDomainName,
181+
tenantFilter: tenant.customerId,
161182
Report: Report,
162183
SearchNow: SearchNow,
163184
},
@@ -226,7 +247,7 @@ const BestPracticeAnalyser = () => {
226247
<CippPage title="Report Results" tenantSelector={false}>
227248
{graphrequest.isUninitialized && <span>Choose a BPA Report to get started.</span>}
228249
{graphrequest.isFetching && <CSpinner />}
229-
{graphrequest.isSuccess && QueryColumns.set && (
250+
{graphrequest.isSuccess && QueryColumns.set && graphrequest.data.Style == 'Table' && (
230251
<CCard className="content-card">
231252
<CCardHeader className="d-flex justify-content-between align-items-center">
232253
<CCardTitle>Best Practice Report</CCardTitle>
@@ -246,6 +267,81 @@ const BestPracticeAnalyser = () => {
246267
</CCardBody>
247268
</CCard>
248269
)}
270+
{graphrequest.isSuccess && QueryColumns.set && graphrequest.data.Style == 'Tenant' && (
271+
<>
272+
<CRow>
273+
{graphrequest.data.Columns.map((info, idx) => (
274+
<CCol sm={10} md={4} className="mb-3">
275+
<CCard className="h-100">
276+
<CCardHeader>
277+
<CCardTitle>{info.name}</CCardTitle>
278+
</CCardHeader>
279+
<CCardBody>
280+
<CCardText>
281+
{info.formatter === 'bool' && (
282+
<CBadge
283+
color={graphrequest.data.Data[info.value] ? 'info' : 'danger'}
284+
>
285+
<FontAwesomeIcon
286+
icon={graphrequest.data.Data[info.value] ? faCheck : faTimes}
287+
size="lg"
288+
className="me-1"
289+
/>
290+
{graphrequest.data.Data[info.value] ? 'Yes' : 'No'}
291+
</CBadge>
292+
)}
293+
{info.formatter === 'reverseBool' && (
294+
<CBadge
295+
color={graphrequest.data.Data[info.value] ? 'danger' : 'info'}
296+
>
297+
<FontAwesomeIcon
298+
icon={graphrequest.data.Data[info.value] ? faTimes : faCheck}
299+
size="lg"
300+
className="me-1"
301+
/>
302+
{graphrequest.data.Data[info.value] ? 'No' : 'Yes'}
303+
</CBadge>
304+
)}
305+
{info.formatter === 'warnBool' && (
306+
<CBadge
307+
color={graphrequest.data.Data[info.value] ? 'info' : 'warning'}
308+
>
309+
<FontAwesomeIcon
310+
icon={graphrequest.data.Data[info.value] ? faCheck : faTimes}
311+
size="lg"
312+
className="me-1"
313+
/>
314+
{graphrequest.data.Data[info.value] ? 'Yes' : 'No'}
315+
</CBadge>
316+
)}
317+
318+
{info.formatter === 'table' && (
319+
<CippTable
320+
key={QueryColumns.data}
321+
reportName="BestPracticeAnalyser"
322+
dynamicColumns={false}
323+
columns={getsubcolumns(graphrequest.data.Data[info.value])}
324+
data={graphrequest.data.Data[info.value]}
325+
isFetching={graphrequest.isFetching}
326+
/>
327+
)}
328+
329+
{info.formatter === 'number' && (
330+
<p class="fs-1 text-center">
331+
{getNestedValue(graphrequest.data.Data, info.value)}
332+
</p>
333+
)}
334+
</CCardText>
335+
<CCardText>
336+
<small className="text-medium-emphasis">{info.desc}</small>
337+
</CCardText>
338+
</CCardBody>
339+
</CCard>
340+
</CCol>
341+
))}
342+
</CRow>
343+
</>
344+
)}
249345
</CippPage>
250346
</CCol>
251347
</CRow>

0 commit comments

Comments
 (0)