All files / src/app/admin/components/_components ClusterResourceBanner.tsx

16.66% Statements 1/6
0% Branches 0/4
0% Functions 0/2
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831x                                                                                                                                                                    
"use client";
 
import { Activity, Cpu, HardDrive } from "lucide-react";
import { TrendArrow } from "./TrendArrow";
import type { TopologyData } from "./types";
import { useT } from "@/lib/i18n/translate";
 
export function ClusterResourceBanner({
  metrics,
}: {
  metrics: NonNullable<TopologyData["clusterMetrics"]>;
}) {
  const t = useT("admin");
  const fmtMem = (mb: number) =>
    mb > 1024 ? `${(mb / 1024).toFixed(1)} GB` : `${Math.round(mb)} MB`;
  const hasPrev = metrics.prev24h.samples > 0;
 
  return (
    <div className="flex flex-wrap items-center gap-x-6 gap-y-2 border border-(--border) rounded-xl px-4 py-3 mb-6 bg-(--surface)/40">
      <div className="flex items-center gap-2 text-xs text-(--text-secondary)">
        <Activity
          size={14}
          className="text-teal-800 dark:text-teal-300 shrink-0"
        />
        <span className="font-medium text-(--text-primary)">
          {t("Cluster")}
        </span>
      </div>
 
      {/* Current */}
      <div className="flex items-center gap-1.5 text-xs">
        <Cpu size={11} className="text-(--accent)" />
        <span className="text-(--text-primary) tabular-nums">
          {metrics.currentCpu.toFixed(1)}%
        </span>
        <span className="text-(--text-secondary)">{t("now")}</span>
      </div>
      <div className="flex items-center gap-1.5 text-xs">
        <HardDrive size={11} className="text-(--accent)" />
        <span className="text-(--text-primary) tabular-nums">
          {fmtMem(metrics.currentMemMB)}
        </span>
        <span className="text-(--text-secondary)">{t("now")}</span>
      </div>
 
      <span className="text-(--text-secondary)">│</span>
 
      {/* 24h peaks */}
      <div className="flex items-center gap-1 text-xs">
        <TrendArrow
          current={metrics.last24h.peakCpu}
          previous={metrics.prev24h.peakCpu}
          hasPrevData={hasPrev}
        />
        <span className="text-(--accent) tabular-nums font-medium">
          CPU {metrics.last24h.peakCpu.toFixed(1)}%
        </span>
        <span className="text-(--text-secondary)">{t("peak 24h")}</span>
      </div>
      <div className="flex items-center gap-1 text-xs">
        <TrendArrow
          current={metrics.last24h.peakMemMB}
          previous={metrics.prev24h.peakMemMB}
          hasPrevData={hasPrev}
        />
        <span className="text-(--accent) tabular-nums font-medium">
          MEM {fmtMem(metrics.last24h.peakMemMB)}
        </span>
        <span className="text-(--text-secondary)">{t("peak 24h")}</span>
      </div>
 
      {metrics.last24h.samples > 0 && (
        <span
          className="text-[10px] text-(--text-secondary)"
          title={t("Number of data points collected in the last 24h")}
        >
          ({t("{n} samples", { n: metrics.last24h.samples })})
        </span>
      )}
    </div>
  );
}