From cfd4339c411652a2bf294d6815b06220600e36ec Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Mon, 25 Nov 2024 12:11:27 +0100 Subject: [PATCH] feat: render all providers with or without data --- .../provider-overview/provider-overview.tsx | 99 +++++++++++++------ 1 file changed, 69 insertions(+), 30 deletions(-) diff --git a/components/overview/provider-overview/provider-overview.tsx b/components/overview/provider-overview/provider-overview.tsx index 6c5edfb102..cd69f02595 100644 --- a/components/overview/provider-overview/provider-overview.tsx +++ b/components/overview/provider-overview/provider-overview.tsx @@ -40,6 +40,13 @@ export const ProvidersOverview = ({ } }; + const providers = [ + { id: "aws", name: "AWS" }, + { id: "azure", name: "Azure" }, + { id: "gcp", name: "GCP" }, + { id: "kubernetes", name: "Kubernetes" }, + ]; + return ( @@ -63,46 +70,78 @@ export const ProvidersOverview = ({ - {providersOverview.data.length === 0 ? ( -
- - - - - - - - -
- ) : ( - providersOverview.data.map((provider) => { - const { pass, fail, total } = provider.attributes.findings; - const resourcesTotal = provider.attributes.resources.total; + {providers.map((providerTemplate) => { + const providerData = providersOverview.data.find( + (p) => p.id === providerTemplate.id, + ); - return ( -
- - {renderProviderBadge(provider.id)} - - - {calculatePassingPercentage(pass, total)}% - - {fail} - {resourcesTotal} -
- ); - }) - )} + return ( +
+ + {renderProviderBadge(providerTemplate.id)} + + + {providerData + ? calculatePassingPercentage( + providerData.attributes.findings.pass, + providerData.attributes.findings.total, + ) + : "0.00"} + % + + + {providerData ? providerData.attributes.findings.fail : "-"} + + + {providerData ? providerData.attributes.resources.total : "-"} + +
+ ); + })} + + {/* Totals row */} +
+ Total + + {calculatePassingPercentage( + providersOverview.data.reduce( + (sum, provider) => sum + provider.attributes.findings.pass, + 0, + ), + providersOverview.data.reduce( + (sum, provider) => sum + provider.attributes.findings.total, + 0, + ), + )} + % + + + {providersOverview.data.reduce( + (sum, provider) => sum + provider.attributes.findings.fail, + 0, + )} + + + {providersOverview.data.reduce( + (sum, provider) => sum + provider.attributes.resources.total, + 0, + )} + +
} > - Go to Providers + Add Provider