Skip to content

Commit

Permalink
BPA Improvements and CIPP Table improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Aug 15, 2023
1 parent 2b59d07 commit b327bab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/components/tables/CellGenericFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export const cellGenericFormatter =
return CellBoolean({ cell, warning, reverse, colourless, noDataIsFalse })
}
if (typeof cell === 'string') {
if (cell.toLowerCase() === 'failed') {
return <CBadge color="danger">{CellTip('Failed to retrieve from API')}</CBadge>
}
return CellTip(cell)
}
if (typeof cell === 'number') {
Expand Down
55 changes: 29 additions & 26 deletions src/components/tables/CippTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,32 +339,35 @@ export default function CippTable({
return null
})

const filtered = data.map((obj) =>
// eslint-disable-next-line no-sequences
/* keys.reduce((acc, curr) => ((acc[curr] = obj[curr]), acc), {}),*/
keys.reduce((acc, curr) => {
const key = curr.split('/')
if (key.length > 1) {
var property = obj
for (var x = 0; x < key.length; x++) {
if (property.hasOwnProperty(key[x]) && property[key[x]] !== null) {
property = property[key[x]]
} else {
property = 'n/a'
break
}
}
acc[curr] = property
} else {
if (typeof exportFormatter[curr] === 'function') {
acc[curr] = exportFormatter[curr]({ cell: obj[curr] })
} else {
acc[curr] = obj[curr]
}
}
return acc
}, {}),
)
const filtered =
Array.isArray(data) && data.length > 0
? data.map((obj) =>
// eslint-disable-next-line no-sequences
/* keys.reduce((acc, curr) => ((acc[curr] = obj[curr]), acc), {}),*/
keys.reduce((acc, curr) => {
const key = curr.split('/')
if (key.length > 1) {
var property = obj
for (var x = 0; x < key.length; x++) {
if (property.hasOwnProperty(key[x]) && property[key[x]] !== null) {
property = property[key[x]]
} else {
property = 'n/a'
break
}
}
acc[curr] = property
} else {
if (typeof exportFormatter[curr] === 'function') {
acc[curr] = exportFormatter[curr]({ cell: obj[curr] })
} else {
acc[curr] = obj[curr]
}
}
return acc
}, {}),
)
: []

if (!disablePDFExport) {
if (dynamicColumns === true) {
Expand Down
20 changes: 17 additions & 3 deletions src/views/tenant/standards/BestPracticeAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CippPage } from 'src/components/layout/CippPage'
import { useGenericGetRequestQuery, useLazyGenericGetRequestQuery } from 'src/store/api/app'
import { OnChange } from 'react-final-form-listeners'
import { queryString } from 'src/helpers'
import { cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
import { CellTip, cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
import { useExecBestPracticeAnalyserMutation } from 'src/store/api/reports'
import { ModalService } from 'src/components/utilities'
import { cellTableFormatter } from 'src/components/tables/CellTable'
Expand Down Expand Up @@ -82,7 +82,18 @@ const BestPracticeAnalyser = () => {
navigate(`?${queryString}`)
}
const [execGraphRequest, graphrequest] = useLazyGenericGetRequestQuery()
const QueryColumns = { set: false, data: [] }
const QueryColumns = {
set: false,
data: [
{
name: 'Tenant',
selector: (row) => row['Tenant'],
sortable: true,
exportSelector: 'Tenant',
cell: (row) => CellTip(row['Tenant']),
},
],
}

if (graphrequest.isSuccess) {
if (graphrequest.data.length === 0) {
Expand All @@ -103,7 +114,7 @@ const BestPracticeAnalyser = () => {
return acc ? acc[part] : undefined
}, obj)
}
const flatObj = graphrequest.data.Columns
const flatObj = graphrequest.data.Columns ? graphrequest.data.Columns : []

flatObj.map((col) => {
// Determine the cell selector based on the 'formatter' property
Expand All @@ -113,6 +124,9 @@ const BestPracticeAnalyser = () => {
case 'bool':
cellSelector = cellBooleanFormatter()
break
case 'reverseBool':
cellSelector = cellBooleanFormatter({ reverse: true })
break
case 'table':
cellSelector = cellTableFormatter(col.value)
break
Expand Down

0 comments on commit b327bab

Please sign in to comment.