Skip to content

Commit 2269358

Browse files
Address terminal review comments
1 parent 6e5ff18 commit 2269358

5 files changed

Lines changed: 54 additions & 46 deletions

File tree

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1 @@
1-
'use client'
2-
3-
import { motion } from 'motion/react'
4-
import type React from 'react'
5-
import { cn } from '@/lib/utils'
6-
7-
type SandboxInspectFrameProps = React.ComponentProps<typeof motion.div> & {
8-
header: React.ReactNode
9-
classNames?: {
10-
frame?: string
11-
header?: string
12-
}
13-
}
14-
15-
export default function SandboxInspectFrame({
16-
className,
17-
classNames,
18-
children,
19-
header,
20-
...props
21-
}: SandboxInspectFrameProps) {
22-
return (
23-
<motion.div
24-
transition={{ duration: 0.25, ease: 'easeInOut' }}
25-
className={cn(
26-
'bg-bg flex h-full min-h-0 flex-1 flex-col overflow-hidden border',
27-
classNames?.frame,
28-
className
29-
)}
30-
{...props}
31-
>
32-
<div className={cn('h-10 w-full border-b', classNames?.header)}>
33-
{header}
34-
</div>
35-
{children as React.ReactNode}
36-
</motion.div>
37-
)
38-
}
1+
export { DashboardPanelFrame as default } from '@/features/dashboard/shared'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { IdBadge } from './id-badge'
2+
export { DashboardPanelFrame } from './panel-frame'
23
export { UserAvatar } from './user-avatar'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use client'
2+
3+
import { motion } from 'motion/react'
4+
import type React from 'react'
5+
import { cn } from '@/lib/utils'
6+
7+
type DashboardPanelFrameProps = React.ComponentProps<typeof motion.div> & {
8+
header: React.ReactNode
9+
classNames?: {
10+
frame?: string
11+
header?: string
12+
}
13+
}
14+
15+
export function DashboardPanelFrame({
16+
className,
17+
classNames,
18+
children,
19+
header,
20+
...props
21+
}: DashboardPanelFrameProps) {
22+
return (
23+
<motion.div
24+
transition={{ duration: 0.25, ease: 'easeInOut' }}
25+
className={cn(
26+
'bg-bg flex h-full min-h-0 flex-1 flex-col overflow-hidden border',
27+
classNames?.frame,
28+
className
29+
)}
30+
{...props}
31+
>
32+
<div className={cn('h-10 w-full border-b', classNames?.header)}>
33+
{header}
34+
</div>
35+
{children as React.ReactNode}
36+
</motion.div>
37+
)
38+
}

src/features/dashboard/terminal/dashboard-terminal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

33
import { Terminal as XTerm } from '@xterm/xterm'
4-
import Sandbox, { type CommandHandle, TimeoutError } from 'e2b'
4+
import { type CommandHandle, type Sandbox, TimeoutError } from 'e2b'
55
import { useCallback, useEffect, useRef, useState } from 'react'
66
import {
77
DEFAULT_COLS,
@@ -217,7 +217,7 @@ export default function DashboardTerminal({
217217
requestTimeoutMs: options.sandboxId
218218
? TERMINAL_ATTACH_ATTEMPT_TIMEOUT_MS
219219
: undefined,
220-
shouldStoreSession: isCurrentStart,
220+
shouldStoreSession: () => !sandboxScoped && isCurrentStart(),
221221
sandboxId: options.sandboxId,
222222
teamId,
223223
template: nextTemplate,
@@ -336,6 +336,7 @@ export default function DashboardTerminal({
336336
disconnectTerminal,
337337
resizeTerminal,
338338
runCommand,
339+
sandboxScoped,
339340
teamId,
340341
template,
341342
updateTerminalUrl,
@@ -541,6 +542,7 @@ export default function DashboardTerminal({
541542
<>
542543
<TerminalPanel
543544
sandboxId={activeSandboxId}
545+
reconnectSandboxId={sandboxScoped ? initialSandboxId : activeSandboxId}
544546
status={status}
545547
template={template}
546548
restartAction={sandboxScoped ? 'reconnect' : 'new'}

src/features/dashboard/terminal/terminal-panel.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { RefObject } from 'react'
2-
import SandboxInspectFrame from '@/features/dashboard/sandbox/inspect/frame'
2+
import { DashboardPanelFrame } from '@/features/dashboard/shared'
33
import { IconButton } from '@/ui/primitives/icon-button'
44
import {
55
CopyIcon,
@@ -13,6 +13,7 @@ interface TerminalPanelProps {
1313
status: TerminalStatus
1414
template: string
1515
restartAction?: 'new' | 'reconnect'
16+
reconnectSandboxId?: string
1617
terminalContainerRef: RefObject<HTMLDivElement | null>
1718
onFocusTerminal: () => void
1819
onCopyTerminalText: () => void
@@ -24,6 +25,7 @@ export default function TerminalPanel({
2425
status,
2526
template,
2627
restartAction = 'new',
28+
reconnectSandboxId,
2729
terminalContainerRef,
2830
onFocusTerminal,
2931
onCopyTerminalText,
@@ -33,6 +35,8 @@ export default function TerminalPanel({
3335
const restartLabel = isReconnectAction
3436
? 'Reconnect terminal'
3537
: 'Start new terminal sandbox'
38+
const isRestartDisabled =
39+
status === 'starting' || (isReconnectAction && !reconnectSandboxId)
3640

3741
const header = (
3842
<div className="flex h-full items-center justify-between px-3">
@@ -69,11 +73,11 @@ export default function TerminalPanel({
6973
className="size-7"
7074
aria-label={restartLabel}
7175
title={restartLabel}
72-
disabled={status === 'starting'}
76+
disabled={isRestartDisabled}
7377
onClick={() =>
7478
onStartTerminal(
75-
isReconnectAction && sandboxId
76-
? { sandboxId }
79+
isReconnectAction
80+
? { sandboxId: reconnectSandboxId }
7781
: { forceNewSandbox: true }
7882
)
7983
}
@@ -85,14 +89,14 @@ export default function TerminalPanel({
8589
)
8690

8791
return (
88-
<SandboxInspectFrame header={header}>
92+
<DashboardPanelFrame header={header}>
8993
<div
9094
ref={terminalContainerRef}
9195
role="application"
9296
aria-label="Terminal"
9397
className="min-h-0 flex-1 cursor-text overflow-hidden bg-black p-3"
9498
onMouseDown={onFocusTerminal}
9599
/>
96-
</SandboxInspectFrame>
100+
</DashboardPanelFrame>
97101
)
98102
}

0 commit comments

Comments
 (0)