refactor: extract panel registry and pane context from workspace screen
Replace hardcoded renderContent() switch and per-kind descriptor logic with a registry-based panel interface. Each panel type (agent, draft, terminal, file) now self-registers with its component, useDescriptor hook, and optional confirmClose. Panels access workspace context via usePaneContext() instead of prop drilling. This prepares the workspace screen for split pane support.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { WorkspaceTabTarget } from "@/stores/workspace-tabs-store";
|
||||
import type { SidebarStateBucket } from "@/utils/sidebar-agent-state";
|
||||
|
||||
export interface PanelIconProps {
|
||||
size: number;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface PanelDescriptor {
|
||||
label: string;
|
||||
subtitle: string;
|
||||
titleState: "ready" | "loading";
|
||||
icon: ComponentType<PanelIconProps>;
|
||||
statusBucket: SidebarStateBucket | null;
|
||||
}
|
||||
|
||||
export interface PanelDescriptorContext {
|
||||
serverId: string;
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
export interface PanelRegistration<
|
||||
K extends WorkspaceTabTarget["kind"] = WorkspaceTabTarget["kind"],
|
||||
> {
|
||||
kind: K;
|
||||
component: ComponentType;
|
||||
useDescriptor(
|
||||
target: Extract<WorkspaceTabTarget, { kind: K }>,
|
||||
context: PanelDescriptorContext
|
||||
): PanelDescriptor;
|
||||
confirmClose?(
|
||||
target: Extract<WorkspaceTabTarget, { kind: K }>,
|
||||
context: PanelDescriptorContext
|
||||
): Promise<boolean>;
|
||||
}
|
||||
|
||||
const panelRegistry = new Map<WorkspaceTabTarget["kind"], PanelRegistration>();
|
||||
|
||||
export function registerPanel<K extends WorkspaceTabTarget["kind"]>(
|
||||
registration: PanelRegistration<K>
|
||||
): void {
|
||||
panelRegistry.set(registration.kind, registration as unknown as PanelRegistration);
|
||||
}
|
||||
|
||||
export function getPanelRegistration(
|
||||
kind: WorkspaceTabTarget["kind"]
|
||||
): PanelRegistration | undefined {
|
||||
return panelRegistry.get(kind);
|
||||
}
|
||||
Reference in New Issue
Block a user