Files
headlamp-argocd-plugin/src/index.tsx
T
Test User bcbed693b1 feat(page-injections): inject ArgoCD info into Namespace and Deployment detail views
- Register detail view sections for Namespace and Deployment resource kinds
- NamespaceArgoSection: shows ArgoCD apps whose spec.destination.namespace matches
- DeploymentArgoBadge: shows ArgoCD app managing the deployment (via status.resources)
- 9 unit tests for matching logic (appsForNamespace, appsForDeployment)
- All checks pass: pnpm tsc, pnpm test (40/40), pnpm lint (0 errors)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-21 20:53:51 +00:00

84 lines
1.8 KiB
TypeScript

import {
registerRoute,
registerSidebarEntry,
} from "@kinvolk/headlamp-plugin/lib";
import {
SectionBox,
StatusLabel,
} from "@kinvolk/headlamp-plugin/lib/CommonComponents";
import React from "react";
import ApplicationDetail from "./components/ApplicationDetail";
import ApplicationsList from "./components/ApplicationsList";
import "./components/PageInjections"; // side-effect: registers detail view sections
// --- Error boundary for plugin components ---
interface ErrorBoundaryState {
error: string | null;
}
class ArgoCDErrorBoundary extends React.Component<
{ children: React.ReactNode },
ErrorBoundaryState
> {
state: ErrorBoundaryState = { error: null };
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
return { error: error.message };
}
render() {
if (this.state.error) {
return (
<SectionBox title="ArgoCD Plugin Error">
<StatusLabel status="error">{this.state.error}</StatusLabel>
</SectionBox>
);
}
return this.props.children;
}
}
// --- Sidebar entry ---
registerSidebarEntry({
parent: null,
name: "argocd",
label: "ArgoCD",
url: "/argocd",
icon: "mdi:git",
});
registerSidebarEntry({
parent: "argocd",
name: "argocd-overview",
label: "Applications",
url: "/argocd",
icon: "mdi:view-list",
});
// --- Routes ---
registerRoute({
path: "/argocd",
sidebar: "argocd-overview",
name: "argocd",
exact: true,
component: () => (
<ArgoCDErrorBoundary>
<ApplicationsList />
</ArgoCDErrorBoundary>
),
});
registerRoute({
path: "/argocd/applications/:name",
sidebar: "argocd-overview",
name: "argocd-application-detail",
component: () => (
<ArgoCDErrorBoundary>
<ApplicationDetail />
</ArgoCDErrorBoundary>
),
});