import { Renderer } from "@k8slens/extensions"; import React from "react"; import './pie-chart.scss' const getStats = (objects: Renderer.K8sApi.KubeObject[]) => { const suspended = objects.filter(k => k.spec.suspend === true).length; const ready = objects.filter(k => !k.spec.suspend && k.status?.conditions?.find((c: any) => c.type === "Ready").status === "True").length; const notReady = objects.filter(k => !k.spec.suspend && k.status?.conditions?.find((c: any) => c.type === "Ready").status === "False").length; const inProgress = objects.length - ready - notReady - suspended; return [ready, notReady, inProgress, suspended]; } export interface PieChartProps { objects: A[]; title: string; crd: Renderer.K8sApi.CustomResourceDefinition; } export function PieChart(props: PieChartProps): React.ReactElement { const { objects, title, crd } = props; const [ready, notReady, inProgress, suspended] = getStats(objects); return <> { e.preventDefault(); Renderer.Navigation.navigate({ pathname: `/crd/${crd.spec.group}/${crd.spec.names.plural}` }) }}>{title}: {objects.length} }