import { Loader, NameValueTable, PercentageBar, PercentageCircle, SectionBox, SectionHeader, SimpleTable, StatusLabel, } from '@kinvolk/headlamp-plugin/lib/CommonComponents'; import { useTheme } from '@mui/material/styles'; import React from 'react'; import { getSeverityStatus } from '../api/checkMapping'; import { AuditData, computeScore, countResults, ResultCounts } from '../api/polaris'; import { usePolarisDataContext } from '../api/PolarisDataContext'; import { getTopIssues, TopIssue } from '../api/topIssues'; const COLORS = { pass: '#4caf50', warning: '#ff9800', danger: '#f44336', skipped: '#9e9e9e', }; function OverviewSection(props: { data: AuditData; counts: ResultCounts }) { const { counts } = props; const score = computeScore(counts); const chartData = [ { name: 'Pass', value: counts.pass, fill: COLORS.pass }, { name: 'Warning', value: counts.warning, fill: COLORS.warning }, { name: 'Danger', value: counts.danger, fill: COLORS.danger }, ]; return ( <> {counts.pass}, }, { name: 'Warning', value: {counts.warning}, }, { name: 'Danger', value: {counts.danger}, }, ]} /> ); } function formatAuditTime(auditTime: string): string { const date = new Date(auditTime); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); if (diffMins < 1) return 'just now'; if (diffMins < 60) return `${diffMins} minute${diffMins > 1 ? 's' : ''} ago`; const diffHours = Math.floor(diffMins / 60); if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`; const diffDays = Math.floor(diffHours / 24); return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`; } export default function DashboardView() { const theme = useTheme(); const { data, loading, error, refresh } = usePolarisDataContext(); if (loading) { return ; } const counts = data ? countResults(data) : null; const topIssues = data ? getTopIssues(data) : []; return ( <>
{data && (
Last updated: {formatAuditTime(data.AuditTime)}
)}
{error && ( {error}, }, ]} /> )} {data && counts && ( <> {topIssues.length > 0 && ( issue.checkName }, { label: 'Category', getter: (issue: TopIssue) => issue.category }, { label: 'Severity', getter: (issue: TopIssue) => ( {issue.severity} ), }, { label: 'Affected Workloads', getter: (issue: TopIssue) => String(issue.count), }, ]} data={topIssues} /> )} )} {!data && !error && ( )} ); }