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

100% Statements 7/7
76.92% Branches 10/13
100% Functions 3/3
100% Lines 7/7

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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 1111x                                       94x 94x         94x   94x           2x                                                                                                                               46x                        
"use client";
 
import { useState } from "react";
import { ChevronDown, ChevronRight } from "lucide-react";
import { ResourceSummary } from "./ResourceSummary";
import { SeverityDot } from "./SeverityDot";
import { TopoComponentCard } from "./TopoComponentCard";
import { ROLE_COLORS, SEVERITY_STYLES } from "./constants";
import type { PeakEntry, TopoParticipant } from "./types";
import { useT } from "@/lib/i18n/translate";
 
export function ParticipantTopologySection({
  participant,
  peaks,
  metricsShared = false,
}: {
  participant: TopoParticipant;
  peaks: Map<string, PeakEntry>;
  metricsShared?: boolean;
}) {
  const t = useT("admin");
  const [expanded, setExpanded] = useState(
    participant.health === "critical" || participant.health === "warning",
  );
  const sev = SEVERITY_STYLES[participant.health];
  const roleClass =
    ROLE_COLORS[participant.role] || "bg-gray-500/20 text-(--text-secondary)";
 
  return (
    <div
      className={`border rounded-xl ${sev.border} ${sev.bg} overflow-hidden transition-all`}
    >
      {/* Header bar — click to expand/collapse */}
      <button
        onClick={() => setExpanded(!expanded)}
        className="w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-(--surface-2)/40 transition-colors"
      >
        {expanded ? (
          <ChevronDown size={14} className="text-(--text-secondary) shrink-0" />
        ) : (
          <ChevronRight
            size={14}
            className="text-(--text-secondary) shrink-0"
          />
        )}
        <SeverityDot severity={participant.health} />
        <div className="flex-1 min-w-0">
          <div className="flex items-center gap-2 flex-wrap">
            <span className="font-semibold text-sm text-(--text-primary)">
              {participant.displayName}
            </span>
            <span className="text-xs text-(--text-secondary)">
              {participant.organization}
            </span>
          </div>
          <ResourceSummary
            components={participant.components}
            peaks={peaks}
            metricsShared={metricsShared}
          />
        </div>
        <span
          className={`text-[10px] font-medium px-2 py-0.5 rounded-full shrink-0 ${roleClass}`}
        >
          {participant.role}
        </span>
        <span className="text-[10px] text-(--text-secondary) shrink-0">
          {t("{n} services", { n: participant.components.length })}
        </span>
      </button>
 
      {/* Expanded: DID + component grid */}
      {expanded && (
        <div className="px-4 pb-4 pt-1 border-t border-(--border)/60">
          <div className="flex items-center gap-4 text-[11px] text-(--text-secondary) mb-3">
            <span>
              {t("DID:")}{" "}
              <span className="font-mono text-(--text-secondary)">
                {participant.did.length > 40
                  ? participant.did.slice(0, 40) + "…"
                  : participant.did}
              </span>
            </span>
            <span>
              {t("State:")}{" "}
              <span
                className={
                  participant.state === "CREATED"
                    ? "text-(--success-text)"
                    : "text-(--warning-text)"
                }
              >
                {participant.state}
              </span>
            </span>
          </div>
          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2">
            {participant.components.map((c) => (
              <TopoComponentCard
                key={c.container}
                comp={c}
                metricsShared={metricsShared}
              />
            ))}
          </div>
        </div>
      )}
    </div>
  );
}