import { ApiProxy } from "@kinvolk/headlamp-plugin/lib"; import { Link, SectionBox, StatusLabel, } from "@kinvolk/headlamp-plugin/lib/CommonComponents"; import React, { useEffect, useState } from "react"; import { ArgoCDApplication, ArgoCDApplicationsList } from "../api/argocd"; import { healthStatusToColor, healthStatusToLabel, syncStatusToColor, } from "./ApplicationsList"; // --- API --- const ARGOCD_API_PATH = "/api/v1/namespaces/argocd/services/argocd-server/proxy/api/v1/applications"; async function fetchApplications(): Promise { const response = (await ApiProxy.request( ARGOCD_API_PATH )) as ArgoCDApplicationsList; return response; } // --- Matching helper --- /** * Returns ArgoCD applications whose spec.destination.namespace matches * the given namespace name. */ export function appsForNamespace( apps: ArgoCDApplication[], namespace: string ): ArgoCDApplication[] { return apps.filter((app) => app.spec?.destination?.namespace === namespace); } // --- Component --- interface NamespaceArgoSectionProps { namespaceName: string; } export default function NamespaceArgoSection({ namespaceName, }: NamespaceArgoSectionProps) { const [apps, setApps] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; fetchApplications() .then((data) => { if (cancelled) return; const matched = appsForNamespace(data.items ?? [], namespaceName); setApps(matched); setLoading(false); }) .catch((err: unknown) => { if (cancelled) return; setError(err instanceof Error ? err.message : String(err)); setLoading(false); }); return () => { cancelled = true; }; }, [namespaceName]); if (loading) { return ( Loading... ); } if (error || !apps) { return ( ArgoCD unreachable ); } if (apps.length === 0) { return null; // Show nothing when no matching application } return ( {apps.length} application(s)
    {apps.map((app) => (
  • {app.metadata.name}   {healthStatusToLabel(app.status?.health?.status ?? "Unknown")}   {app.status?.sync?.status ?? "Unknown"}
  • ))}
); }