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 | 8x 156x 15x 2x 1x | /**
* Viewer registry — maps a resource type to a specialized React viewer.
*
* The commander explorer resolves the viewer for a leaf node from the source
* descriptor's `viewer` field (or the model system — see `resolveViewer`).
* Specialized viewers (DB tables, pod logs, manifests, messages, documents,
* key-values, files, images, secrets) register here so the generic UI stays
* decoupled from the concrete backends.
*/
import type React from 'react';
/** Props shared by all commander viewers. */
export interface ICommanderViewerProps {
/** The leaf node row data (list fields as returned by the parent). */
node: Record<string, unknown>;
/** Optional fetcher that loads the full node content (e.g. `node.get`). */
fetch?: (params?: Record<string, unknown>) => Promise<unknown>;
/** Fetched content (set by the parent, or loaded via `fetch`). */
data?: unknown;
/** Optional content-type hint (e.g. for files/images). */
contentType?: string;
className?: string;
}
export type CommanderViewer = React.ComponentType<ICommanderViewerProps>;
const viewers = new Map<string, CommanderViewer>();
/** Register a viewer for a resource type. Later registrations win. */
export function registerViewer(type: string, component: CommanderViewer): void {
viewers.set(type, component);
}
/** Resolve the viewer component for a resource type. */
export function getViewer(type?: string): CommanderViewer | undefined {
return type ? viewers.get(type) : undefined;
}
/** Whether a viewer is registered for the given type. */
export function hasViewer(type?: string): boolean {
return !!type && viewers.has(type);
}
/** List all registered viewer type keys (for diagnostics / tests). */
export function listViewers(): string[] {
return [...viewers.keys()];
}
|