Open History to see the last commit
1import { threadIssueKeyOf, type ScopedThreadRef, type ThreadIssueLink } from "@t3tools/contracts";
2import { useGT } from "gt-react";
3import { MessageSquareIcon } from "lucide-react";
4import type { MouseEvent } from "react";
5
6import { cn } from "~/lib/utils";
7import { useRightPanelStore } from "~/rightPanelStore";
8import { useServerConfigs } from "~/state/entities";
9import { useLinkedIssueDetail } from "~/state/issues";
10
11import {
12 IssueGlyph,
13 issueStatePresentation,
14 issueTrackerPresentation,
15} from "../issue/issuePresentation";
16import {
17 PULL_REQUEST_ROW_CLASS,
18 PULL_REQUEST_ROW_NUMBER_CLASS,
19 PullRequestRowLines,
20} from "../pullRequest/PullRequestListRow";
21import { PullRequestActorLabel } from "../pullRequest/pullRequestPresentation";
22import { ThreadDetailsControl } from "./ThreadDetailsControl";
23import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
24
25function LinkedIssueRow({
26 link,
27 threadRef,
28 compact,
29 mountScope,
30 onOpen,
31}: {
32 link: ThreadIssueLink;
33 threadRef: ScopedThreadRef;
34 compact: boolean;
35 mountScope: "thread-details" | "linked-items" | "sidebar-tooltip";
36 onOpen: (() => void) | undefined;
37}) {
38 const gt = useGT();
39 const configs = useServerConfigs();
40 const detail = useLinkedIssueDetail(threadRef.environmentId, link, mountScope);
41 const trackerPresentation = issueTrackerPresentation(link.tracker);
42 const state = detail === null ? null : issueStatePresentation(detail.state);
43 const Icon = state?.Icon ?? IssueGlyph.issue;
44 const title = detail?.title ?? link.title;
45 const anchorProps = {
46 href: link.url,
47 target: "_blank",
48 rel: "noopener noreferrer",
49 "aria-label": gt("Issue {key}: {title}", { key: link.displayKey, title }),
50 onClick: (event: MouseEvent<HTMLElement>) => {
51 event.stopPropagation();
52 if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
53 if (configs.get(threadRef.environmentId)?.environment.capabilities.issues !== true) return;
54 event.preventDefault();
55 useRightPanelStore.getState().openIssue(threadRef, link);
56 onOpen?.();
57 },
58 };
59 const glyph = (
60 <Icon
61 aria-hidden={state === null ? true : undefined}
62 role={state === null ? undefined : "img"}
63 aria-label={state?.label}
64 className={cn("size-4 shrink-0", state?.toneClassName ?? "text-muted-foreground")}
65 />
66 );
67 const comments =
68 detail !== null && detail.commentCount > 0 ? (
69 <span
70 role="img"
71 aria-label={gt("{count, plural, one {{count} comment} other {{count} comments}}", {
72 count: detail.commentCount,
73 })}
74 className="inline-flex shrink-0 items-center gap-0.5 tabular-nums"
75 >
76 <MessageSquareIcon aria-hidden className="size-3" />
77 <span aria-hidden>{detail.commentCount}</span>
78 </span>
79 ) : null;
80 const trackerIcon = (
81 <trackerPresentation.Icon
82 role="img"
83 aria-label={trackerPresentation.providerName}
84 className="size-3 shrink-0"
85 />
86 );
87 const lines = (
88 <>
89 {glyph}
90 <PullRequestRowLines
91 number={<span className={PULL_REQUEST_ROW_NUMBER_CLASS}>{link.displayKey}</span>}
92 title={title}
93 status={comments}
94 meta={
95 <>
96 {detail?.author ? (
97 <PullRequestActorLabel actor={detail.author} tooltip={false} />
98 ) : null}
99 {trackerIcon}
100 <span className="truncate">{link.scope}</span>
101 </>
102 }
103 updatedAt={detail?.updatedAt ?? link.linkedAt}
104 />
105 </>
106 );
107 return compact ? (
108 <div className="pb-1.5">
109 <Tooltip>
110 <TooltipTrigger
111 render={<ThreadDetailsControl part="title" render={<a {...anchorProps} />} />}
112 >
113 {glyph}
114 <span className="min-w-0 flex-1 line-clamp-2 whitespace-normal leading-4.5">{title}</span>
115 </TooltipTrigger>
116 <TooltipPopup
117 side="top"
118 align="start"
119 variant="glass"
120 className="w-80 max-w-[calc(100vw-2rem)]"
121 >
122 <div className="flex min-w-0 items-center gap-2">{lines}</div>
123 </TooltipPopup>
124 </Tooltip>
125 <div className="flex h-5 min-w-0 items-center gap-1.5 ps-9 pe-2.5 text-xs text-muted-foreground">
126 <span aria-hidden className="shrink-0 tabular-nums">
127 {link.displayKey}
128 </span>
129 {trackerIcon}
130 {comments}
131 </div>
132 </div>
133 ) : (
134 <a
135 {...anchorProps}
136 className={cn(
137 PULL_REQUEST_ROW_CLASS,
138 "px-2 hover:bg-accent/60 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
139 )}
140 >
141 {lines}
142 </a>
143 );
144}
145
146export function ThreadDetailsIssueRows({
147 links,
148 threadRef,
149 compact = true,
150 mountScope = "thread-details",
151 onOpen,
152}: {
153 links: ReadonlyArray<ThreadIssueLink>;
154 threadRef: ScopedThreadRef;
155 compact?: boolean;
156 mountScope?: "thread-details" | "linked-items" | "sidebar-tooltip";
157 onOpen?: () => void;
158}) {
159 return links.map((link) => (
160 <LinkedIssueRow
161 key={threadIssueKeyOf(link)}
162 link={link}
163 threadRef={threadRef}
164 compact={compact}
165 mountScope={mountScope}
166 onOpen={onOpen}
167 />
168 ));
169}