-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathTaskShellPanel.tsx
More file actions
53 lines (45 loc) · 1.71 KB
/
Copy pathTaskShellPanel.tsx
File metadata and controls
53 lines (45 loc) · 1.71 KB
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
49
50
51
52
53
import type { Task } from "@posthog/shared/domain-types";
import { Box } from "@radix-ui/themes";
import { useEffect } from "react";
import { usePanelLayoutStore } from "../../panels/panelLayoutStore";
import { useSessionSelector } from "../../sessions/sessionStore";
import { ShellTerminal } from "../../terminal/ShellTerminal";
import { useTerminalStore } from "../../terminal/terminalStore";
import { useShellProcessPoller } from "../../terminal/useShellProcessPoller";
import { useWorkspace } from "../../workspace/useWorkspace";
interface TaskShellPanelProps {
taskId: string;
task: Task;
shellId?: string;
}
export function TaskShellPanel({
taskId,
task: _task,
shellId,
}: TaskShellPanelProps) {
const stateKey = shellId ? `${taskId}-${shellId}` : taskId;
const tabId = shellId || "shell";
// Only the connection status gates rendering here; reading it narrowly keeps
// the terminal panel from re-rendering on every streamed token.
const sessionStatus = useSessionSelector(taskId, (s) => s?.status);
const workspace = useWorkspace(taskId);
const workspacePath = workspace?.worktreePath ?? workspace?.folderPath;
const processName = useTerminalStore(
(state) => state.terminalStates[stateKey]?.processName,
);
const updateTabLabel = usePanelLayoutStore((state) => state.updateTabLabel);
useShellProcessPoller(stateKey);
useEffect(() => {
if (processName) {
updateTabLabel(taskId, tabId, processName);
}
}, [processName, taskId, tabId, updateTabLabel]);
if (!workspacePath || !sessionStatus || sessionStatus === "connecting") {
return null;
}
return (
<Box height="100%">
<ShellTerminal cwd={workspacePath} stateKey={stateKey} taskId={taskId} />
</Box>
);
}