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

PullRequestDiffUnavailableState.tsx

76 lines2.7 KB

1import type { ScopedThreadRef, SourceControlProviderKind } from "@t3tools/contracts";
2import { T, useMessages, Var } from "gt-react";
3import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";
4​
5import { useOpenLink } from "~/browser/useOpenLink";
6import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
7​
8import { Button } from "../ui/button";
9import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../ui/empty";
10import { RefreshIcon } from "../ui/refresh-icon";
11import { changeRequestTermKind } from "./changeRequestTerm";
12import { describePullRequestDiffError } from "./pullRequestDiffError";
13​
14export function PullRequestDiffUnavailableState({
15 error,
16 provider,
17 url,
18 threadRef,
19 onRetry,
20}: {
21 error: string;
22 provider: SourceControlProviderKind;
23 url: string;
24 threadRef: ScopedThreadRef | null;
25 onRetry: () => void;
26}) {
27 const m = useMessages();
28 const openLink = useOpenLink(threadRef);
29 const { providerName, terminology } = getSourceControlPresentationForKind(provider);
30 const { title, description } = describePullRequestDiffError(
31 error,
32 providerName,
33 changeRequestTermKind(terminology),
34 m,
35 );
36​
37 return (
38 <Empty size="compact" className="min-h-full" role="status">
39 <div className="flex size-11 items-center justify-center rounded-full bg-warning-surface text-warning">
40 <TriangleAlertIcon aria-hidden className="size-5" />
41 </div>
42 <EmptyHeader>
43 <EmptyTitle>{title}</EmptyTitle>
44 <EmptyDescription>{description}</EmptyDescription>
45 </EmptyHeader>
46 <div className="flex flex-wrap justify-center gap-2">
47 <Button size="sm" variant="default" onClick={onRetry}>
48 <RefreshIcon />
49 <T>Try again</T>
50 </Button>
51 <Button
52 size="sm"
53 variant="outline"
54 render={<a href={url} target="_blank" rel="noopener noreferrer" />}
55 onClick={(event) => {
56 event.preventDefault();
57 void openLink(url, { event }).catch(console.error);
58 }}
59 >
60 <ExternalLinkIcon aria-hidden />
61 <T>
62 Open on <Var>{providerName}</Var>
63 </T>
64 </Button>
65 </div>
66 <details className="w-full max-w-lg text-xs text-muted-foreground">
67 <summary className="mx-auto w-fit cursor-pointer rounded-sm -outline-offset-2 hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring">
68 <T>Technical details</T>
69 </summary>
70 <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">
71 {error}
72 </pre>
73 </details>
74 </Empty>
75 );