import { HeaderLabel, Loader, NameValueTable, SectionBox, SectionHeader, StatusLabel, } from '@kinvolk/headlamp-plugin/lib/CommonComponents'; import React from 'react'; import { AuditData, computeScore, countResults, getRefreshInterval, ResultCounts, setRefreshInterval, usePolarisData, } from '../api/polaris'; const INTERVAL_OPTIONS = [ { label: '1 minute', value: 60 }, { label: '5 minutes', value: 300 }, { label: '10 minutes', value: 600 }, { label: '30 minutes', value: 1800 }, ]; function scoreStatus(score: number): 'success' | 'warning' | 'error' { if (score >= 80) return 'success'; if (score >= 50) return 'warning'; return 'error'; } function RefreshSettings(props: { interval: number; onChange: (seconds: number) => void }) { return ( o.value === props.interval)?.label ?? ''} /> ); } function OverviewSection(props: { data: AuditData; counts: ResultCounts }) { const score = computeScore(props.counts); const status = scoreStatus(score); return ( <> {score}% ), }, ]} /> {props.counts.pass} ), }, { name: 'Warning', value: ( {props.counts.warning} ), }, { name: 'Danger', value: ( {props.counts.danger} ), }, ]} /> ); } export default function PolarisView() { const [interval, setInterval] = React.useState(getRefreshInterval); function handleIntervalChange(seconds: number) { setInterval(seconds); setRefreshInterval(seconds); } const { data, loading, error } = usePolarisData(interval); if (loading) { return ; } const counts = data ? countResults(data) : null; return ( <> , ]} /> {error && ( {error} ), }, ]} /> )} {data && counts && } {!data && !error && ( )} ); }