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