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

PullRequestListGroups.tsx

118 lines4.1 KB

1import type { EnvironmentId, PullRequestAction } from "@t3tools/contracts";
2import { EyeIcon, LayersIcon, PenLineIcon, UsersIcon, type LucideIcon } from "lucide-react";
3import type { RefCallback } from "react";
4​
5import { cn } from "~/lib/utils";
6import { Separator } from "../ui/separator";
7import {
8 pullRequestEntryKey,
9 scorePullRequestMatch,
10 type EnvironmentPullRequestEntry,
11 type PullRequestGroup,
12} from "./pullRequestList.logic";
13import { PullRequestRow, type PullRequestRowTarget } from "./PullRequestRow";
14import {
15 PullRequestSpeedModeProvider,
16 type PullRequestSpeedActionResult,
17} from "./PullRequestSpeedActions";
18​
19const GROUP_ICONS: Record<string, LucideIcon> = {
20 authored: PenLineIcon,
21 reviewRequested: EyeIcon,
22 others: UsersIcon,
23};
24​
25const MATCHED_ELSEWHERE_SCORE = 10;
26​
27function PullRequestGroupHeader({
28 group,
29}: {
30 group: { key: string; label: string; entries: ReadonlyArray<unknown> };
31}) {
32 const Icon = GROUP_ICONS[group.key] ?? LayersIcon;
33 return (
34 <div className="flex items-center gap-2 px-3 pb-1 text-xs font-medium text-muted-foreground/70">
35 <Icon aria-hidden className="size-3.5 shrink-0" />
36 <h2 className="shrink-0">{group.label}</h2>
37 <span className="shrink-0 tabular-nums text-muted-foreground/50">{group.entries.length}</span>
38 <Separator className="min-w-2 flex-1" />
39 </div>
40 );
42​
43export function PullRequestListGroups({
44 groups,
45 environmentLabels,
46 query,
47 selected,
48 showProvider,
49 statsRef,
50 onSelect,
51 hostActionsOf,
52 onActed,
53 closingKeys,
54 sweepingKeys,
55 onCloseSweepStart,
56}: {
57 groups: ReadonlyArray<PullRequestGroup<EnvironmentPullRequestEntry>>;
58 /** Only when rows come from more than one server, so each says which. */
59 environmentLabels: ReadonlyMap<EnvironmentId, string> | null;
60 query: string;
61 selected: {
62 readonly environmentId: string | undefined;
63 readonly repository: string;
64 readonly host: string | undefined;
65 readonly number: number;
66 } | null;
67 showProvider: boolean;
68 statsRef: RefCallback<HTMLDivElement>;
69 onSelect: (entry: PullRequestRowTarget) => void;
70 hostActionsOf: (entry: EnvironmentPullRequestEntry) => ReadonlySet<PullRequestAction>;
71 onActed: (result: PullRequestSpeedActionResult) => void;
72 closingKeys: ReadonlySet<string>;
73 sweepingKeys: ReadonlySet<string>;
74 onCloseSweepStart: (entry: EnvironmentPullRequestEntry, event: PointerEvent) => void;
75}) {
76 return (
77 <PullRequestSpeedModeProvider>
78 <div className={cn("space-y-3", sweepingKeys.size > 0 && "**:pointer-events-none")}>
79 {groups.map((group) => (
80 <div key={group.key} className="space-y-0.5">
81 {group.label ? <PullRequestGroupHeader group={group} /> : null}
82 {group.entries.map((entry) => {
83 const entryKey = pullRequestEntryKey(entry);
84 const environmentLabel = environmentLabels?.get(entry.environmentId);
85 return (
86 <PullRequestRow
87 key={entryKey}
88 statsKey={entryKey}
89 statsRef={statsRef}
90 entry={entry}
91 showProjectTitle
92 showProvider={showProvider}
93 {...(environmentLabel !== undefined ? { environmentLabel } : {})}
94 matchedElsewhere={
95 query.length > 0 &&
96 scorePullRequestMatch(entry, query) <= MATCHED_ELSEWHERE_SCORE
97 }
98 selected={
99 selected?.environmentId === entry.environmentId &&
100 selected.repository === entry.repository &&
101 selected.host?.toLowerCase() === entry.host.toLowerCase() &&
102 selected.number === entry.number
103 }
104 onSelect={onSelect}
105 hostActions={hostActionsOf(entry)}
106 onActed={onActed}
107 closing={closingKeys.has(entryKey)}
108 sweeping={sweepingKeys.has(entryKey)}
109 onCloseSweepStart={onCloseSweepStart}
110 />
111 );
112 })}
113 </div>
114 ))}
115 </div>
116 </PullRequestSpeedModeProvider>
117 );