Skip to content

Commit 1737c12

Browse files
Address terminal PR review
1 parent 2269358 commit 1737c12

9 files changed

Lines changed: 26 additions & 105 deletions

File tree

src/app/dashboard/[teamSlug]/sandboxes/[sandboxId]/terminal/layout.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/app/dashboard/terminal/layout.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/features/dashboard/sandbox/inspect/filesystem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import LoadingLayout from '@/features/dashboard/loading-layout'
44
import SandboxInspectFilesystemHeader from '@/features/dashboard/sandbox/inspect/filesystem-header'
5+
import { DashboardPanelFrame } from '@/features/dashboard/shared'
56
import { ScrollArea } from '@/ui/primitives/scroll-area'
67
import { useSandboxContext } from '../context'
7-
import SandboxInspectFrame from './frame'
88
import { useDirectoryState } from './hooks/use-directory'
99
import { useRootChildren } from './hooks/use-node'
1010
import SandboxInspectNode from './node'
@@ -28,7 +28,7 @@ export default function SandboxInspectFilesystem({
2828
return (
2929
<div className="h-full flex-1 flex flex-col gap-1 overflow-hidden">
3030
<StoppedBanner rootNodeCount={children.length} />
31-
<SandboxInspectFrame
31+
<DashboardPanelFrame
3232
initial={{
3333
flex: 1,
3434
}}
@@ -49,7 +49,7 @@ export default function SandboxInspectFilesystem({
4949
</ScrollArea>
5050
)}
5151
</div>
52-
</SandboxInspectFrame>
52+
</DashboardPanelFrame>
5353
</div>
5454
)
5555
}

src/features/dashboard/sandbox/inspect/frame.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/features/dashboard/sandbox/inspect/viewer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AnimatePresence } from 'motion/react'
44
import { useEffect, useState } from 'react'
55
import ShikiHighlighter, { type Language } from 'react-shiki'
66
import { useShikiTheme } from '@/configs/shiki'
7+
import { DashboardPanelFrame } from '@/features/dashboard/shared'
78
import { useIsMobile } from '@/lib/hooks/use-mobile'
89
import { cn } from '@/lib/utils'
910
import { Button } from '@/ui/primitives/button'
@@ -16,7 +17,6 @@ import {
1617
type UnreadableFileTypeContentState,
1718
type UnreadableTooLargeContentState,
1819
} from './filesystem/store'
19-
import SandboxInspectFrame from './frame'
2020
import { useContent } from './hooks/use-content'
2121
import { useFile } from './hooks/use-file'
2222
import { useErrorPaths, useSelectedPath } from './hooks/use-node'
@@ -81,7 +81,7 @@ function SandboxInspectViewerContent({
8181
}
8282

8383
return (
84-
<SandboxInspectFrame
84+
<DashboardPanelFrame
8585
classNames={{
8686
frame: 'max-md:max-w-full max-md:border-none max-h-full',
8787
header: 'max-md:bg-transparent max-md:h-9 max-md:border-none',
@@ -125,7 +125,7 @@ function SandboxInspectViewerContent({
125125
) : (
126126
<UnreadableContent state={state} onDownload={download} />
127127
)}
128-
</SandboxInspectFrame>
128+
</DashboardPanelFrame>
129129
)
130130
}
131131

src/features/dashboard/sandbox/layout.tsx

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

3-
import { notFound, usePathname } from 'next/navigation'
3+
import { notFound } from 'next/navigation'
44
import { PROTECTED_URLS } from '@/configs/urls'
55
import { useRouteParams } from '@/lib/hooks/use-route-params'
66
import { DashboardTabsList } from '@/ui/dashboard-tabs'
@@ -26,26 +26,18 @@ export default function SandboxLayout({
2626
}: SandboxLayoutProps) {
2727
const { teamSlug, sandboxId } =
2828
useRouteParams<'/dashboard/[teamSlug]/sandboxes/[sandboxId]'>()
29-
const pathname = usePathname()
3029

3130
const { sandboxInfo, isSandboxInfoLoading, isSandboxNotFound } =
3231
useSandboxContext()
33-
const isTerminalTab =
34-
pathname === PROTECTED_URLS.SANDBOX_TERMINAL(teamSlug, sandboxId)
3532

36-
const isSandboxUnavailable =
37-
isSandboxNotFound || (!sandboxInfo && !isSandboxInfoLoading)
38-
39-
if (isSandboxUnavailable && !isTerminalTab) {
33+
if (isSandboxNotFound) {
4034
throw notFound()
4135
}
4236

43-
if (isSandboxUnavailable) {
44-
return (
45-
<div className="flex h-full min-h-0 flex-1 flex-col max-md:overflow-y-auto">
46-
{children}
47-
</div>
48-
)
37+
if (!sandboxInfo) {
38+
if (!isSandboxInfoLoading) {
39+
throw notFound()
40+
}
4941
}
5042

5143
return (
Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
'use client'
22

3-
import Link from 'next/link'
4-
import { PROTECTED_URLS } from '@/configs/urls'
53
import { useDashboard } from '@/features/dashboard/context'
64
import DashboardTerminal from '@/features/dashboard/terminal/dashboard-terminal'
7-
import { useRouteParams } from '@/lib/hooks/use-route-params'
8-
import { Button } from '@/ui/primitives/button'
9-
import {
10-
Card,
11-
CardContent,
12-
CardDescription,
13-
CardFooter,
14-
CardHeader,
15-
} from '@/ui/primitives/card'
16-
import { ArrowLeftIcon, SandboxIcon } from '@/ui/primitives/icons'
17-
import { useSandboxContext } from '../context'
185

196
interface SandboxTerminalViewProps {
207
sandboxId: string
@@ -24,17 +11,6 @@ export default function SandboxTerminalView({
2411
sandboxId,
2512
}: SandboxTerminalViewProps) {
2613
const { team } = useDashboard()
27-
const { teamSlug } =
28-
useRouteParams<'/dashboard/[teamSlug]/sandboxes/[sandboxId]'>()
29-
const { sandboxInfo, isSandboxInfoLoading, isSandboxNotFound } =
30-
useSandboxContext()
31-
32-
const isSandboxUnavailable =
33-
isSandboxNotFound || (!sandboxInfo && !isSandboxInfoLoading)
34-
35-
if (isSandboxUnavailable) {
36-
return <SandboxTerminalUnavailable teamSlug={teamSlug} />
37-
}
3814

3915
return (
4016
<div className="flex min-h-0 flex-1 overflow-hidden p-3 md:p-6">
@@ -47,39 +23,3 @@ export default function SandboxTerminalView({
4723
</div>
4824
)
4925
}
50-
51-
function SandboxTerminalUnavailable({ teamSlug }: { teamSlug: string }) {
52-
return (
53-
<div className="flex min-h-0 flex-1 items-center justify-center p-3 md:p-6">
54-
<Card className="w-full max-w-md border border-stroke bg-bg-1/40 backdrop-blur-lg">
55-
<CardHeader className="text-center">
56-
<span className="prose-value-big">Sandbox unavailable</span>
57-
<CardDescription>
58-
Sandbox not found or you do not have access to it.
59-
</CardDescription>
60-
</CardHeader>
61-
<CardContent className="text-center text-fg-secondary">
62-
<p>
63-
It may have been killed, removed, or created under another team.
64-
</p>
65-
</CardContent>
66-
<CardFooter className="flex flex-col gap-1">
67-
<Button variant="secondary" asChild className="w-full">
68-
<Link href={PROTECTED_URLS.SANDBOXES_LIST(teamSlug)}>
69-
<SandboxIcon />
70-
Sandboxes
71-
</Link>
72-
</Button>
73-
<Button
74-
variant="secondary"
75-
onClick={() => window.history.back()}
76-
className="w-full"
77-
>
78-
<ArrowLeftIcon />
79-
Go Back
80-
</Button>
81-
</CardFooter>
82-
</Card>
83-
</div>
84-
)
85-
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client'
22

3+
import '@xterm/xterm/css/xterm.css'
34
import { Terminal as XTerm } from '@xterm/xterm'
45
import { type CommandHandle, type Sandbox, TimeoutError } from 'e2b'
56
import { useCallback, useEffect, useRef, useState } from 'react'
@@ -223,9 +224,7 @@ export default function DashboardTerminal({
223224
template: nextTemplate,
224225
})
225226

226-
if (!isCurrentStart()) {
227-
throw new Error('Terminal start was cancelled.')
228-
}
227+
if (!isCurrentStart()) return null
229228

230229
appendOutput(`Sandbox ${sandbox.sandboxId} is running.\r\n`)
231230
appendOutput('Opening PTY...\r\n')
@@ -247,13 +246,17 @@ export default function DashboardTerminal({
247246
const canRetryAttach = Boolean(options.sandboxId)
248247

249248
try {
249+
type AttachResult = NonNullable<
250+
Awaited<ReturnType<typeof openSandboxAndPty>>
251+
>
250252
let attachAttempt = 0
251-
let sandbox: Awaited<ReturnType<typeof openSandboxAndPty>>['sandbox']
252-
let pty: Awaited<ReturnType<typeof openSandboxAndPty>>['pty']
253+
let sandbox: AttachResult['sandbox']
254+
let pty: AttachResult['pty']
253255

254256
while (true) {
255257
try {
256258
const result = await openSandboxAndPty()
259+
if (!result) return
257260
sandbox = result.sandbox
258261
pty = result.pty
259262
break

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ export default function TerminalPanel({
8989
)
9090

9191
return (
92-
<DashboardPanelFrame header={header}>
92+
<DashboardPanelFrame
93+
classNames={{
94+
frame: 'bg-bg-1',
95+
}}
96+
header={header}
97+
>
9398
<div
9499
ref={terminalContainerRef}
95100
role="application"

0 commit comments

Comments
 (0)