From b327bab3aee16b8e4dcd1bb477e0bde9c788b793 Mon Sep 17 00:00:00 2001 From: KelvinTegelaar <49186168+KelvinTegelaar@users.noreply.github.com> Date: Tue, 15 Aug 2023 11:49:21 +0200 Subject: [PATCH] BPA Improvements and CIPP Table improvements --- src/components/tables/CellGenericFormat.js | 3 + src/components/tables/CippTable.js | 55 ++++++++++--------- .../tenant/standards/BestPracticeAnalyser.js | 20 ++++++- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/src/components/tables/CellGenericFormat.js b/src/components/tables/CellGenericFormat.js index 04b506efc1e4..e442378a5633 100644 --- a/src/components/tables/CellGenericFormat.js +++ b/src/components/tables/CellGenericFormat.js @@ -76,6 +76,9 @@ export const cellGenericFormatter = return CellBoolean({ cell, warning, reverse, colourless, noDataIsFalse }) } if (typeof cell === 'string') { + if (cell.toLowerCase() === 'failed') { + return {CellTip('Failed to retrieve from API')} + } return CellTip(cell) } if (typeof cell === 'number') { diff --git a/src/components/tables/CippTable.js b/src/components/tables/CippTable.js index 8fcee1e887e5..75e3380d2a79 100644 --- a/src/components/tables/CippTable.js +++ b/src/components/tables/CippTable.js @@ -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) { diff --git a/src/views/tenant/standards/BestPracticeAnalyser.js b/src/views/tenant/standards/BestPracticeAnalyser.js index 83d5c52866ce..3a8cf80ea7e7 100644 --- a/src/views/tenant/standards/BestPracticeAnalyser.js +++ b/src/views/tenant/standards/BestPracticeAnalyser.js @@ -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' @@ -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) { @@ -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 @@ -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