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

pullRequestListOptions.ts

71 lines2.5 KB

1import type { PullRequestInvolvement, PullRequestListState } from "@t3tools/contracts";
2import {
3 CalendarArrowDownIcon,
4 CalendarArrowUpIcon,
5 ClockIcon,
6 EyeIcon,
7 LayersIcon,
8 ListChecksIcon,
9 Maximize2Icon,
10 Minimize2Icon,
11 PenLineIcon,
12 UserLockIcon,
13} from "lucide-react";
14import { msg } from "gt-react";
15​
16import type { MessageResolver } from "~/i18n/messages";
17​
18import type { PullRequestFilterOption } from "./PullRequestListFilters";
19import type { PullRequestListSort } from "./pullRequestListPreferences";
20import { PullRequestGlyph } from "./pullRequestIcons";
21​
22export const INVOLVEMENT_TABS = [
23 { value: "all", label: msg("All", { $context: "pull request filter" }), Icon: LayersIcon },
24 {
25 value: "reviewing",
26 label: msg("Reviewing", { $context: "pull request filter" }),
27 Icon: EyeIcon,
28 },
29 {
30 value: "authored",
31 label: msg("Authored", { $context: "pull request filter" }),
32 Icon: PenLineIcon,
33 },
34] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestInvolvement>>;
35​
36export const STATE_TABS = [
37 { value: "all", label: msg("All", { $context: "pull request filter" }), Icon: LayersIcon },
38 {
39 value: "open",
40 label: msg("Open", { $context: "pull request state" }),
41 Icon: PullRequestGlyph.pullRequest,
42 },
43 {
44 value: "closed",
45 label: msg("Closed", { $context: "pull request state" }),
46 Icon: PullRequestGlyph.closed,
47 },
48 {
49 value: "merged",
50 label: msg("Merged", { $context: "pull request state" }),
51 Icon: PullRequestGlyph.merged,
52 },
53] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
54​
55export const SORT_OPTIONS = [
56 { value: "ready", label: msg("Merge readiness"), Icon: ListChecksIcon },
57 { value: "blocked", label: msg("Blocked on me"), Icon: UserLockIcon },
58 { value: "updated", label: msg("Recently updated"), Icon: ClockIcon },
59 { value: "newest", label: msg("Newest shown"), Icon: CalendarArrowDownIcon },
60 { value: "oldest", label: msg("Oldest shown"), Icon: CalendarArrowUpIcon },
61 { value: "largest", label: msg("Largest shown"), Icon: Maximize2Icon },
62 { value: "smallest", label: msg("Smallest shown"), Icon: Minimize2Icon },
63] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListSort>>;
64​
65/** Static option tables hold `msg()` labels; components resolve them with `useMessages()`. */
66export function resolveFilterOptions<Option extends { readonly label: string }>(
67 options: ReadonlyArray<Option>,
68 resolve: MessageResolver,
69): Option[] {
70 return options.map((option) => ({ ...option, label: resolve(option.label) }));