From 6beed13bb326c7aee6d14389cc5a647b757c4638 Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Tue, 29 Mar 2022 17:00:50 +0200 Subject: [PATCH] Update frontend --- assets/js/components/ChecksResults.jsx | 83 ++++++----------- assets/js/components/ChecksSelection.jsx | 110 ++++++++++++----------- assets/js/components/ClustersList.jsx | 24 +++-- 3 files changed, 103 insertions(+), 114 deletions(-) diff --git a/assets/js/components/ChecksResults.jsx b/assets/js/components/ChecksResults.jsx index ea1841f9d0..b54ba21d58 100644 --- a/assets/js/components/ChecksResults.jsx +++ b/assets/js/components/ChecksResults.jsx @@ -19,30 +19,6 @@ const getChecksResults = (cluster) => { return {}; }; -const getDescriptionFromCatalog = - (catalog = []) => - (check_id) => { - return catalog.reduce((acc, check) => { - if (check.id === check_id) { - return check.description; - } - - return acc; - }, ''); - }; - -const getGroupFromCatalog = - (catalog = []) => - (checkId) => { - return catalog.reduce((acc, check) => { - if (check.id === checkId) { - return check.group; - } - - return acc; - }, ''); - }; - const getHostname = (hosts = []) => (hostId) => { @@ -55,6 +31,12 @@ const getHostname = }, ''); }; +const getCatalogByProvider = (catalogProvider) => (state) => { + return state.catalog.catalog.find( + ({ provider }) => provider === catalogProvider + ); +}; + const sortChecksResults = (checksResults = [], group) => { return checksResults.sort((a, b) => { if (a.check_id === b.check_id) { @@ -83,16 +65,18 @@ const ChecksResults = () => { state.clustersList.clusters.find((cluster) => cluster.id === clusterID) ); - const hostname = getHostname(useSelector((state) => state.hostsList.hosts)); + const checksResults = getChecksResults(cluster); - const catalog = useSelector((state) => state.catalog.catalog).flatMap( - ({ checks }) => checks - ); + const hostname = getHostname(useSelector((state) => state.hostsList.hosts)); - const checksResults = getChecksResults(cluster); + // FIXME: Check the provider by cluster + const catalog = useSelector(getCatalogByProvider('azure')); - const description = getDescriptionFromCatalog(catalog); - const group = getGroupFromCatalog(catalog); + const description = (checkId) => { + return catalog?.groups + ?.flatMap(({ checks }) => checks) + .find(({ id }) => id === checkId).description; + }; return (
@@ -109,12 +93,6 @@ const ChecksResults = () => { - - {sortChecksResults(checksResults[c], group).map( - (checkResult) => ( - - - - - - - ) - )} + {sortChecksResults(checksResults[c]).map((checkResult) => ( + + + + + + ))}
- Group - {
- {group(checkResult.check_id)} - - {checkResult.check_id} - - {description(checkResult.check_id)} - - {getResultIcon(checkResult.result)} -
+ {checkResult.check_id} + + {description(checkResult.check_id)} + + {getResultIcon(checkResult.result)} +
diff --git a/assets/js/components/ChecksSelection.jsx b/assets/js/components/ChecksSelection.jsx index 44e3f97b50..5d02002db9 100644 --- a/assets/js/components/ChecksSelection.jsx +++ b/assets/js/components/ChecksSelection.jsx @@ -37,65 +37,69 @@ const ChecksSelection = () => { return (
- {catalog.map(({ group, checks }) => ( -
-
-

- {group} -

-
- -
- ))} + + + ))} + +
+ ))}