Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ export const useNodes = (): Node[] => {
);
};

// useNode is the reactive single-node lookup for per-node pages. It subscribes
// via useNodes so the live fleet is fetched and the page re-renders when it
// arrives — a bare getNode() reads the module store synchronously and, on a
// direct load or refresh in live mode, finds an empty store and never recovers.
export const useNode = (name: string | undefined): Node | undefined => {
const all = useNodes();
return name ? all.find((n) => n.name === name) : undefined;
};

// The trust chain from the root down to this node, following parentCn. Guards a
// missing parent link and a cycle so a broken fixture can't loop forever.
export const chainToRoot = (node: Node): Node[] => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { Link, Navigate, useParams } from "react-router-dom";

import { ConfigForm } from "@/components/config-form";
import { Button } from "@/components/ui/button";
import { getNode } from "@/lib/nodes";
import { useNode } from "@/lib/nodes";

export const NodeConfigPage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);

if (!node || node.identityState === "REVOKED") {
return <Navigate replace to={`/nodes/${name}`} />;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CertInventory } from "@/components/cert-inventory";
import { NodeDetailPanel } from "@/components/node-detail-panel";
import { Button } from "@/components/ui/button";
import { type IdentityState, roleLabels } from "@/lib/mock";
import { chainToRoot, getNode } from "@/lib/nodes";
import { chainToRoot, useNode } from "@/lib/nodes";
import { cn } from "@/lib/utils";

const stateTone: Record<IdentityState, string> = {
Expand All @@ -33,7 +33,7 @@ const stateTone: Record<IdentityState, string> = {

export const NodeDetailPage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);

if (!node) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node-issue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { Link, Navigate, useParams } from "react-router-dom";
import { IssueForm } from "@/components/issue-form";
import { Button } from "@/components/ui/button";
import { canIssue, type Cert } from "@/lib/certs";
import { getNode } from "@/lib/nodes";
import { useNode } from "@/lib/nodes";

export const NodeIssuePage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);
const [issued, setIssued] = useState<Cert | null>(null);
// Remount key: bumping it drops the form's issued/export state so "Issue
// another" starts from a clean form (and a fresh, unexportable key).
Expand Down
2 changes: 1 addition & 1 deletion src/pages/node-profiles.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ vi.mock("@/lib/config", () => ({
getNodeConfig: (...args: unknown[]) => getNodeConfig(...args),
}));
vi.mock("@/lib/nodes", () => ({
getNode: (name: string) => ({ identityState: "ESTABLISHED", name }),
useNode: (name: string) => ({ identityState: "ESTABLISHED", name }),
}));
vi.mock("@/lib/profiles", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/lib/profiles")>();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node-profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Button } from "@/components/ui/button";
import { useAuth } from "@/context/auth";
import { getNodeConfig } from "@/lib/config";
import { fleetMode } from "@/lib/fleet/mode";
import { getNode } from "@/lib/nodes";
import { useNode } from "@/lib/nodes";
import { computeDrift, type DriftRow, type DriftStatus } from "@/lib/profile-drift";
import { applyProfileToNode, fromProtoProfile, useProfiles } from "@/lib/profiles";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -151,7 +151,7 @@ const DriftView = ({ nodeName }: { nodeName: string }) => {

export const NodeProfilesPage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);

if (!node) {
return <Navigate replace to={`/nodes/${name}`} />;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/node-rekey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { Link, Navigate, useParams } from "react-router-dom";

import { RekeyWizard } from "@/components/rekey-wizard";
import { Button } from "@/components/ui/button";
import { getNode } from "@/lib/nodes";
import { useNode } from "@/lib/nodes";

export const NodeRekeyPage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);

if (!node || node.identityState === "REVOKED") {
return <Navigate replace to={`/nodes/${name}`} />;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/root-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Link, Navigate, useParams } from "react-router-dom";
import { ConfigForm } from "@/components/config-form";
import { RekeyWizard } from "@/components/rekey-wizard";
import { Button } from "@/components/ui/button";
import { getNode } from "@/lib/nodes";
import { useNode } from "@/lib/nodes";

const Panel = ({ children, label }: { children: React.ReactNode; label: string }) => (
<div className="w-full rounded-xl border bg-card">
Expand All @@ -43,7 +43,7 @@ const Field = ({ children, label }: { children: React.ReactNode; label: string }

export const RootDetailPage = () => {
const { name } = useParams<{ name: string }>();
const node = name ? getNode(name) : undefined;
const node = useNode(name);

if (!node || node.role !== "root") {
return <Navigate replace to="/root" />;
Expand Down
Loading