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

issuePresentation.tsx

71 lines2.8 KB

1import type { IssueState, IssueTrackerKind } from "@t3tools/contracts";
2import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
3import { CircleCheckIcon, CircleDotIcon, CircleSlashIcon, TicketIcon } from "lucide-react";
4​
5import { cn } from "~/lib/utils";
6import { JiraIcon, LinearIcon, type Icon } from "~/components/Icons";
7import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
8​
9import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10import { PULL_REQUEST_STATE_PRESENTATION } from "../pullRequest/pullRequestIcons";
11​
12export const IssueGlyph = { issue: CircleDotIcon } as const;
13​
14/** Name and mark per standalone tracker kind; one missing here falls back to its kind and a ticket. */
15const STANDALONE_TRACKERS: Partial<Record<string, { providerName: string; Icon: Icon }>> = {
16 linear: { providerName: "Linear", Icon: LinearIcon },
17 jira: { providerName: "Jira", Icon: JiraIcon },
18};
19​
20/** A git host's tracker wears the host's own icon and name; a standalone tracker wears its kind. */
21export function issueTrackerPresentation(tracker: IssueTrackerKind | string) {
22 if (sourceControlClients.find(tracker) !== undefined) {
23 return getSourceControlPresentationForKind(tracker);
24 }
25 return STANDALONE_TRACKERS[tracker] ?? { providerName: tracker, Icon: TicketIcon };
27​
28/**
29 * Open and completed borrow the ink the pull-request states use for open and merged, so green
30 * and violet mean the same thing on both pages; closed any other way than completed wears a
31 * draft's grey, because work that stopped must not look like work that finished. The tracker's own state name is the label,
32 * so a workflow tracker's "In Review" reads as itself.
33 */
34export function issueStatePresentation(state: IssueState) {
35 if (state.category === "open") {
36 return {
37 ...PULL_REQUEST_STATE_PRESENTATION.open,
38 label: state.name,
39 Icon: CircleDotIcon,
40 };
41 }
42 if (state.closeReason !== undefined && state.closeReason !== "completed") {
43 return {
44 ...PULL_REQUEST_STATE_PRESENTATION.draft,
45 label: state.name,
46 Icon: CircleSlashIcon,
47 };
48 }
49 return {
50 ...PULL_REQUEST_STATE_PRESENTATION.merged,
51 label: state.name,
52 Icon: CircleCheckIcon,
53 };
55​
56export function IssueStateGlyph({ state, className }: { state: IssueState; className?: string }) {
57 const presentation = issueStatePresentation(state);
58 return (
59 <Tooltip>
60 {/* The list row is itself a button, so the trigger stays a span. */}
61 <TooltipTrigger render={<span className="inline-flex shrink-0" />}>
62 <presentation.Icon
63 role="img"
64 aria-label={presentation.label}
65 className={cn("size-4 shrink-0", presentation.toneClassName, className)}
66 />
67 </TooltipTrigger>
68 <TooltipPopup>{presentation.label}</TooltipPopup>
69 </Tooltip>
70 );