Skip to content

Commit b327bab

Browse files
BPA Improvements and CIPP Table improvements
1 parent 2b59d07 commit b327bab

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

src/components/tables/CellGenericFormat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ export const cellGenericFormatter =
7676
return CellBoolean({ cell, warning, reverse, colourless, noDataIsFalse })
7777
}
7878
if (typeof cell === 'string') {
79+
if (cell.toLowerCase() === 'failed') {
80+
return <CBadge color="danger">{CellTip('Failed to retrieve from API')}</CBadge>
81+
}
7982
return CellTip(cell)
8083
}
8184
if (typeof cell === 'number') {

src/components/tables/CippTable.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -339,32 +339,35 @@ export default function CippTable({
339339
return null
340340
})
341341

342-
const filtered = data.map((obj) =>
343-
// eslint-disable-next-line no-sequences
344-
/* keys.reduce((acc, curr) => ((acc[curr] = obj[curr]), acc), {}),*/
345-
keys.reduce((acc, curr) => {
346-
const key = curr.split('/')
347-
if (key.length > 1) {
348-
var property = obj
349-
for (var x = 0; x < key.length; x++) {
350-
if (property.hasOwnProperty(key[x]) && property[key[x]] !== null) {
351-
property = property[key[x]]
352-
} else {
353-
property = 'n/a'
354-
break
355-
}
356-
}
357-
acc[curr] = property
358-
} else {
359-
if (typeof exportFormatter[curr] === 'function') {
360-
acc[curr] = exportFormatter[curr]({ cell: obj[curr] })
361-
} else {
362-
acc[curr] = obj[curr]
363-
}
364-
}
365-
return acc
366-
}, {}),
367-
)
342+
const filtered =
343+
Array.isArray(data) && data.length > 0
344+
? data.map((obj) =>
345+
// eslint-disable-next-line no-sequences
346+
/* keys.reduce((acc, curr) => ((acc[curr] = obj[curr]), acc), {}),*/
347+
keys.reduce((acc, curr) => {
348+
const key = curr.split('/')
349+
if (key.length > 1) {
350+
var property = obj
351+
for (var x = 0; x < key.length; x++) {
352+
if (property.hasOwnProperty(key[x]) && property[key[x]] !== null) {
353+
property = property[key[x]]
354+
} else {
355+
property = 'n/a'
356+
break
357+
}
358+
}
359+
acc[curr] = property
360+
} else {
361+
if (typeof exportFormatter[curr] === 'function') {
362+
acc[curr] = exportFormatter[curr]({ cell: obj[curr] })
363+
} else {
364+
acc[curr] = obj[curr]
365+
}
366+
}
367+
return acc
368+
}, {}),
369+
)
370+
: []
368371

369372
if (!disablePDFExport) {
370373
if (dynamicColumns === true) {

src/views/tenant/standards/BestPracticeAnalyser.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { CippPage } from 'src/components/layout/CippPage'
2929
import { useGenericGetRequestQuery, useLazyGenericGetRequestQuery } from 'src/store/api/app'
3030
import { OnChange } from 'react-final-form-listeners'
3131
import { queryString } from 'src/helpers'
32-
import { cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
32+
import { CellTip, cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
3333
import { useExecBestPracticeAnalyserMutation } from 'src/store/api/reports'
3434
import { ModalService } from 'src/components/utilities'
3535
import { cellTableFormatter } from 'src/components/tables/CellTable'
@@ -82,7 +82,18 @@ const BestPracticeAnalyser = () => {
8282
navigate(`?${queryString}`)
8383
}
8484
const [execGraphRequest, graphrequest] = useLazyGenericGetRequestQuery()
85-
const QueryColumns = { set: false, data: [] }
85+
const QueryColumns = {
86+
set: false,
87+
data: [
88+
{
89+
name: 'Tenant',
90+
selector: (row) => row['Tenant'],
91+
sortable: true,
92+
exportSelector: 'Tenant',
93+
cell: (row) => CellTip(row['Tenant']),
94+
},
95+
],
96+
}
8697

8798
if (graphrequest.isSuccess) {
8899
if (graphrequest.data.length === 0) {
@@ -103,7 +114,7 @@ const BestPracticeAnalyser = () => {
103114
return acc ? acc[part] : undefined
104115
}, obj)
105116
}
106-
const flatObj = graphrequest.data.Columns
117+
const flatObj = graphrequest.data.Columns ? graphrequest.data.Columns : []
107118

108119
flatObj.map((col) => {
109120
// Determine the cell selector based on the 'formatter' property
@@ -113,6 +124,9 @@ const BestPracticeAnalyser = () => {
113124
case 'bool':
114125
cellSelector = cellBooleanFormatter()
115126
break
127+
case 'reverseBool':
128+
cellSelector = cellBooleanFormatter({ reverse: true })
129+
break
116130
case 'table':
117131
cellSelector = cellTableFormatter(col.value)
118132
break

0 commit comments

Comments
 (0)