|
1 | 1 | import { Codesnippet } from "@/components/CodeSnippet"; |
2 | 2 | import { CollapsibleCard } from "@/components/CollapsibleCard"; |
3 | 3 | import { useStepDetail } from "@/data/steps/step-detail-query"; |
4 | | -import { Skeleton } from "@zenml-io/react-component-library"; |
| 4 | +import { Button, Skeleton } from "@zenml-io/react-component-library"; |
5 | 5 | import { ErrorFallback } from "../../Error"; |
| 6 | +import AlertCircle from "@/assets/icons/alert-circle.svg?react"; |
| 7 | +import ArrowLeft from "@/assets/icons/arrow-left.svg?react"; |
6 | 8 |
|
7 | 9 | type Props = { |
8 | 10 | stepId: string; |
9 | 11 | }; |
10 | 12 |
|
| 13 | +function goToError() { |
| 14 | + const errorLineElement = document.querySelector(".error-highlight-line"); |
| 15 | + if (errorLineElement) { |
| 16 | + errorLineElement.scrollIntoView({ behavior: "smooth" }); |
| 17 | + } |
| 18 | +} |
| 19 | + |
11 | 20 | export function StepCodeTab({ stepId }: Props) { |
12 | 21 | const { data, isPending, isError, error } = useStepDetail({ stepId }); |
13 | 22 |
|
14 | 23 | if (isError) return <ErrorFallback err={error} />; |
15 | 24 |
|
16 | 25 | if (isPending) return <Skeleton className="h-[300px] w-full" />; |
17 | 26 |
|
| 27 | + const traceback = data?.metadata?.exception_info?.traceback; |
| 28 | + |
18 | 29 | return ( |
19 | | - <CollapsibleCard initialOpen title="Code"> |
20 | | - <Codesnippet fullWidth highlightCode wrap code={data?.metadata?.source_code || ""} /> |
21 | | - </CollapsibleCard> |
| 30 | + <div className="flex flex-col gap-5"> |
| 31 | + {traceback && ( |
| 32 | + <CollapsibleCard |
| 33 | + initialOpen |
| 34 | + title={ |
| 35 | + <> |
| 36 | + <AlertCircle className="h-5 w-5 fill-theme-text-error" /> Error |
| 37 | + </> |
| 38 | + } |
| 39 | + contentClassName="border-t border-error-200" |
| 40 | + className="border border-error-200" |
| 41 | + headerClassName="flex justify-between" |
| 42 | + headerChildren={ |
| 43 | + <Button |
| 44 | + className="whitespace-nowrap" |
| 45 | + onClick={goToError} |
| 46 | + intent="danger" |
| 47 | + emphasis="subtle" |
| 48 | + > |
| 49 | + Go to error |
| 50 | + <ArrowLeft className="h-5 w-5 -rotate-90 fill-error-700" /> |
| 51 | + </Button> |
| 52 | + } |
| 53 | + > |
| 54 | + <div className="whitespace-pre-wrap font-mono text-text-md">{traceback}</div> |
| 55 | + </CollapsibleCard> |
| 56 | + )} |
| 57 | + <CollapsibleCard initialOpen title="Code"> |
| 58 | + <Codesnippet |
| 59 | + fullWidth |
| 60 | + highlightCode |
| 61 | + wrap |
| 62 | + code={data?.metadata?.source_code || ""} |
| 63 | + exceptionCodeLine={data?.metadata?.exception_info?.step_code_line ?? undefined} |
| 64 | + /> |
| 65 | + </CollapsibleCard> |
| 66 | + </div> |
22 | 67 | ); |
23 | 68 | } |
0 commit comments