Upgrading to 0.5.0-beta.1 left the old docked explorer sidebar showing next to the new explorer pane, with no way to dismiss it. The sidebar rendered off the persisted `desktop.fileExplorerOpen` flag. #3287 rerouted the explorer toggle to the workspace-layout explorer pane, so nothing on a wide layout ever wrote that flag false again, and no migration cleared it. Assistant directory links and review attachments could still set it. On Windows and Linux the sidebar's close button was suppressed because the OS window controls own the top-right corner, so there was no affordance at all. The explorer is now one surface picked from two facts — is the layout compact, and can the platform render split panes: compact -> slide-over overlay (panel store) non-compact + splits -> dedicated right pane (layout store) non-compact, no splits -> ordinary tabs in the focused pane `workspace-tabs/explorer-surface.ts` owns that choice and every entry point routes through it, so the toggle, Ctrl+E, Ctrl+., directory links, review attachments and side file opens can no longer disagree about where the explorer lives. Pane splits stay gated on `isWeb`: they depend on dnd-kit and DOM-backed accessibility helpers. Native tablets are non-compact without splits, so they get explorer tabs rather than a second pane — deliberately trading side-by-side agent and Changes for a surface that only renders what the single-column tab row can actually reach. Ctrl+. is handled by the workspace screen rather than the app shell. The pathname alone cannot identify the active workspace: desktop cold-starts at "/" and restores the remembered workspace from route params, so a key derived from the pathname is null exactly when a workspace is mounted, and the explorer reads as permanently closed. `desktop.fileExplorerOpen` and `explorerWidth` are dropped by a migration to panel-state v15 but stay declared in the persisted schema. That schema is a strict object and the validated storage deletes the whole entry when parsing fails, so removing the keys outright would wipe every upgrading user's sidebar width, expanded paths and diff-collapse state.
122 lines
4.3 KiB
TypeScript
122 lines
4.3 KiB
TypeScript
import { useCallback } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Terminal } from "lucide-react-native";
|
|
import { Text, View } from "react-native";
|
|
import invariant from "tiny-invariant";
|
|
import type { ListTerminalsResponse } from "@getpaseo/protocol/messages";
|
|
import { deriveTerminalActivityStatusBucket } from "@getpaseo/protocol/terminal-activity";
|
|
import { TerminalPane } from "@/components/terminal-pane";
|
|
import { usePaneContext, usePaneFocus } from "@/panels/pane-context";
|
|
import type { PanelDescriptor, PanelRegistration } from "@/panels/panel-registry";
|
|
import { queryClient } from "@/data/query-client";
|
|
import { buildTerminalsQueryKey } from "@/screens/workspace/terminals/state";
|
|
import { usePanelStore } from "@/stores/panel-store";
|
|
import { useSessionStore } from "@/stores/session-store";
|
|
import { useWorkspaceDirectory, useWorkspaceFields } from "@/stores/session-store-hooks";
|
|
|
|
type ListTerminalsPayload = ListTerminalsResponse["payload"];
|
|
|
|
const CENTERED_PADDED_STYLE = {
|
|
flex: 1,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
padding: 16,
|
|
} as const;
|
|
|
|
function trimNonEmpty(value: string | null | undefined): string | null {
|
|
if (typeof value !== "string") {
|
|
return null;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed.length > 0 ? trimmed : null;
|
|
}
|
|
|
|
function useTerminalPanelDescriptor(
|
|
target: { kind: "terminal"; terminalId: string },
|
|
context: { serverId: string; workspaceId: string },
|
|
): PanelDescriptor {
|
|
const { t } = useTranslation();
|
|
const client = useSessionStore((state) => state.sessions[context.serverId]?.client ?? null);
|
|
const workspaceDirectory = useWorkspaceDirectory(context.serverId, context.workspaceId);
|
|
const terminalsQuery = useQuery(
|
|
{
|
|
queryKey: buildTerminalsQueryKey(
|
|
context.serverId,
|
|
workspaceDirectory,
|
|
context.workspaceId || null,
|
|
),
|
|
enabled: Boolean(client && workspaceDirectory),
|
|
queryFn: async (): Promise<ListTerminalsPayload> => {
|
|
if (!client || !workspaceDirectory) {
|
|
throw new Error("Workspace directory not found");
|
|
}
|
|
return client.listTerminals(workspaceDirectory, undefined, {
|
|
workspaceId: context.workspaceId || undefined,
|
|
});
|
|
},
|
|
staleTime: 5_000,
|
|
},
|
|
queryClient,
|
|
);
|
|
const terminal =
|
|
terminalsQuery.data?.terminals.find((entry) => entry.id === target.terminalId) ?? null;
|
|
const label =
|
|
trimNonEmpty(terminal?.title ?? terminal?.name ?? null) ??
|
|
t("workspace.tabs.fallback.terminal");
|
|
|
|
return {
|
|
label,
|
|
subtitle: t("workspace.tabs.fallback.terminal"),
|
|
tooltip: label,
|
|
titleState: "ready",
|
|
icon: Terminal,
|
|
statusBucket: deriveTerminalActivityStatusBucket(terminal?.activity),
|
|
};
|
|
}
|
|
|
|
function TerminalPanel() {
|
|
const { serverId, workspaceId, target, openFileInWorkspace } = usePaneContext();
|
|
const { isWorkspaceFocused, isPaneFocused } = usePaneFocus();
|
|
const workspaceFields = useWorkspaceFields(serverId, workspaceId, (w) => ({
|
|
workspaceDirectory: w.workspaceDirectory,
|
|
isGitCheckout: w.projectKind === "git",
|
|
}));
|
|
const workspaceDirectory = workspaceFields?.workspaceDirectory || null;
|
|
const isGitCheckout = workspaceFields?.isGitCheckout ?? false;
|
|
const openCompactFileExplorer = usePanelStore((state) => state.openCompactFileExplorer);
|
|
const handleOpenFileExplorer = useCallback(() => {
|
|
if (!workspaceDirectory) {
|
|
return;
|
|
}
|
|
openCompactFileExplorer({ serverId, cwd: workspaceDirectory, isGit: isGitCheckout });
|
|
}, [isGitCheckout, openCompactFileExplorer, serverId, workspaceDirectory]);
|
|
invariant(target.kind === "terminal", "TerminalPanel requires terminal target");
|
|
|
|
if (!workspaceDirectory) {
|
|
return (
|
|
<View style={CENTERED_PADDED_STYLE}>
|
|
<Text>Workspace directory not found.</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<TerminalPane
|
|
serverId={serverId}
|
|
cwd={workspaceDirectory}
|
|
terminalId={target.terminalId}
|
|
isWorkspaceFocused={isWorkspaceFocused}
|
|
isPaneFocused={isPaneFocused}
|
|
onOpenFileExplorer={handleOpenFileExplorer}
|
|
onOpenWorkspaceFile={openFileInWorkspace}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export const terminalPanelRegistration: PanelRegistration<"terminal"> = {
|
|
kind: "terminal",
|
|
component: TerminalPanel,
|
|
useDescriptor: useTerminalPanelDescriptor,
|
|
};
|