Skip to content
Source
Sign inSign up
Open History to see the last commit

PullRequestDiffUnavailableState.tsx

62 lines2.2 KB

1import type { SourceControlProviderKind } from "@t3tools/contracts";
2import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
3​
4import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
5​
6import { Button } from "../ui/button";
7import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../ui/empty";
8import { RefreshIcon } from "../ui/refresh-icon";
9import { describePullRequestDiffError } from "./pullRequestDiffError";
10​
11export function PullRequestDiffUnavailableState({
12 error,
13 provider,
14 url,
15 onRetry,
16}: {
17 error: string;
18 provider: SourceControlProviderKind;
19 url: string;
20 onRetry: () => void;
21}) {
22 const { providerName, terminology } = getSourceControlPresentationForKind(provider);
23 const { title, description } = describePullRequestDiffError(
24 error,
25 providerName,
26 terminology.singular,
27 );
28​
29 return (
30 <Empty size="compact" className="min-h-full" role="status">
31 <div className="flex size-11 items-center justify-center rounded-full bg-warning-surface text-warning">
32 <TriangleAlertIcon aria-hidden className="size-5" />
33 </div>
34 <EmptyHeader>
35 <EmptyTitle>{title}</EmptyTitle>
36 <EmptyDescription>{description}</EmptyDescription>
37 </EmptyHeader>
38 <div className="flex flex-wrap justify-center gap-2">
39 <Button size="sm" variant="default" onClick={onRetry}>
40 <RefreshIcon />
41 Try again
42 </Button>
43 <Button
44 size="sm"
45 variant="outline"
46 render={<a href={url} target="_blank" rel="noopener noreferrer" />}
47 >
48 <ExternalLinkIcon aria-hidden />
49 Open on {providerName}
50 </Button>
51 </div>
52 <details className="w-full max-w-lg text-xs text-muted-foreground">
53 <summary className="mx-auto w-fit cursor-pointer rounded-sm -outline-offset-2 hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring">
54 Technical details
55 </summary>
56 <pre className="scrollbar-gutter-both mt-3 max-h-40 overflow-auto whitespace-pre-wrap break-words rounded-lg border border-border bg-muted/40 p-3 text-left font-mono text-xs">
57 {error}
58 </pre>
59 </details>
60 </Empty>
61 );