import { Router } from '@kinvolk/headlamp-plugin/lib';
import {
Loader,
NameValueTable,
SectionBox,
SectionHeader,
SimpleTable,
StatusLabel,
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import React from 'react';
import { Link } from 'react-router-dom';
import {
computeScore,
countResultsForItems,
filterResultsByNamespace,
getNamespaces,
} from '../api/polaris';
import { usePolarisDataContext } from '../api/PolarisDataContext';
function scoreStatus(score: number): 'success' | 'warning' | 'error' {
if (score >= 80) return 'success';
if (score >= 50) return 'warning';
return 'error';
}
interface NamespaceRow {
namespace: string;
score: number;
pass: number;
warning: number;
danger: number;
skipped: number;
}
export default function NamespacesListView() {
const { data, loading, error } = usePolarisDataContext();
if (loading) {
return ;
}
if (error) {
return (
<>
{error},
},
]}
/>
>
);
}
if (!data) {
return (
<>
>
);
}
const namespaces = getNamespaces(data);
const rows: NamespaceRow[] = namespaces.map(ns => {
const results = filterResultsByNamespace(data, ns);
const counts = countResultsForItems(results);
const score = computeScore(counts);
return {
namespace: ns,
score,
pass: counts.pass,
warning: counts.warning,
danger: counts.danger,
skipped: counts.skipped,
};
});
return (
<>
(
{row.namespace}
),
},
{
label: 'Score',
getter: (row: NamespaceRow) => (
{row.score}%
),
},
{
label: 'Pass',
getter: (row: NamespaceRow) => {row.pass},
},
{
label: 'Warning',
getter: (row: NamespaceRow) => (
{row.warning}
),
},
{
label: 'Danger',
getter: (row: NamespaceRow) => {row.danger},
},
{
label: 'Skipped',
getter: (row: NamespaceRow) => String(row.skipped),
},
]}
data={rows}
emptyMessage="No namespaces found in Polaris audit data."
/>
>
);
}