Skip to content

Commit 660c772

Browse files
committed
Use nebari code block.
1 parent 7650760 commit 660c772

6 files changed

Lines changed: 395 additions & 137 deletions

File tree

‎frontend/src/components/jobs/Jobs.tsx‎

Lines changed: 31 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import {
2-
Check,
3-
ChevronDown,
4-
ChevronRight,
5-
Copy,
6-
Loader2,
7-
Radio,
8-
} from 'lucide-react';
1+
import { ChevronDown, ChevronRight, Loader2, Radio } from 'lucide-react';
92
import { useMemo, useState } from 'react';
103
import { RemoteUnreachableBanner } from '@/components/remote/RemoteUnreachableBanner';
114
import { Badge } from '@/components/ui/badge';
12-
import { Button } from '@/components/ui/button';
135
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
6+
import { CodeBlock, CodeBlockBody } from '@/components/ui/code-block';
147
import { useJobLogStream } from '@/hooks/useJobLogStream';
158
import { useJobs } from '@/hooks/useJobs';
169
import { useRemoteJobs, useRemoteView } from '@/hooks/useRemote';
@@ -35,37 +28,6 @@ const typeColors: Record<JobType, string> = {
3528
env_uninstall: 'bg-orange-100 text-orange-800 border-orange-300',
3629
};
3730

38-
const CopyButton = ({ text }: { text: string }) => {
39-
const [copied, setCopied] = useState(false);
40-
41-
const handleCopy = async () => {
42-
await navigator.clipboard.writeText(text);
43-
setCopied(true);
44-
setTimeout(() => setCopied(false), 2000);
45-
};
46-
47-
return (
48-
<Button
49-
variant="outline"
50-
size="sm"
51-
onClick={handleCopy}
52-
className="h-7 gap-1"
53-
>
54-
{copied ? (
55-
<>
56-
<Check className="h-3 w-3" />
57-
Copied
58-
</>
59-
) : (
60-
<>
61-
<Copy className="h-3 w-3" />
62-
Copy
63-
</>
64-
)}
65-
</Button>
66-
);
67-
};
68-
6931
const JobCard = ({
7032
job,
7133
isFirst,
@@ -149,33 +111,36 @@ const JobCard = ({
149111

150112
{(isStreaming || displayLogs) && (
151113
<div>
152-
<div className="flex items-center justify-between mb-2">
153-
<div className="flex items-center gap-2">
154-
<h4 className="font-semibold">Logs</h4>
155-
{isStreaming && (
156-
<Badge variant="outline" className="text-xs">
157-
<Radio className="h-2 w-2 mr-1 animate-pulse" />
158-
Live
159-
</Badge>
160-
)}
161-
</div>
162-
{displayLogs && <CopyButton text={displayLogs} />}
114+
<div className="flex items-center gap-2 mb-2">
115+
<h4 className="font-semibold">Logs</h4>
116+
{isStreaming && (
117+
<Badge variant="outline" className="text-xs">
118+
<Radio className="h-2 w-2 mr-1 animate-pulse" />
119+
Live
120+
</Badge>
121+
)}
163122
</div>
164-
<pre className="bg-slate-900 text-slate-100 p-4 rounded-md overflow-x-auto max-h-96 overflow-y-auto font-mono whitespace-pre-wrap text-sm">
165-
{displayLogs || 'Waiting for logs...'}
166-
</pre>
123+
<CodeBlock
124+
dark
125+
code={displayLogs || 'Waiting for logs...'}
126+
className="w-full"
127+
showCopyButton={!!displayLogs}
128+
>
129+
<CodeBlockBody maxLines={16} aria-label="Job logs" />
130+
</CodeBlock>
167131
</div>
168132
)}
169133

170134
{job.error && (
171135
<div>
172-
<div className="flex items-center justify-between mb-2">
173-
<h4 className="font-semibold text-destructive">Error</h4>
174-
<CopyButton text={job.error} />
175-
</div>
176-
<pre className="bg-red-950 text-red-100 p-4 rounded-md overflow-x-auto font-mono whitespace-pre-wrap">
177-
{job.error}
178-
</pre>
136+
<h4 className="font-semibold text-destructive mb-2">Error</h4>
137+
<CodeBlock
138+
dark
139+
code={job.error}
140+
className="w-full border-destructive-foreground/40"
141+
>
142+
<CodeBlockBody aria-label="Job error output" />
143+
</CodeBlock>
179144
</div>
180145
)}
181146

@@ -190,15 +155,12 @@ const JobCard = ({
190155

191156
return (
192157
<div key={key}>
193-
<div className="flex items-center justify-between mb-1">
194-
<div className="text-sm font-medium text-muted-foreground capitalize">
195-
{key.replace(/_/g, ' ')}
196-
</div>
197-
<CopyButton text={content} />
158+
<div className="text-sm font-medium text-muted-foreground capitalize mb-1">
159+
{key.replace(/_/g, ' ')}
198160
</div>
199-
<pre className="bg-slate-900 text-slate-100 p-4 rounded-md overflow-x-auto font-mono whitespace-pre">
200-
{content}
201-
</pre>
161+
<CodeBlock dark code={content} className="w-full">
162+
<CodeBlockBody aria-label={`${key} metadata`} />
163+
</CodeBlock>
202164
</div>
203165
);
204166
})}

0 commit comments

Comments
 (0)