Open History to see the last commit
1import { pullRequestFilterProjects } from "@t3tools/client-runtime/pull-request-project-filter";
2import type { EnvironmentProject } from "@t3tools/client-runtime/state/models";
3import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
4
5import type { IssuesSearch } from "./IssuesPage";
6
7// The router reads a bare `key=42` as a number.
8const bounded = (value: unknown): string | undefined => {
9 const text = typeof value === "number" ? String(value) : value;
10 return typeof text === "string" && text.trim() ? text.trim().slice(0, 200) : undefined;
11};
12
13const labels = (raw: unknown): ReadonlyArray<string> | undefined => {
14 const names = (Array.isArray(raw) ? raw : [raw]).flatMap((name) => bounded(name) ?? []);
15 return names.length === 0 ? undefined : names.slice(0, 20);
16};
17
18// Every optional key is an own key, even when undefined: the router lays these over the parent
19// route's unvalidated search, where a key left out would keep its raw value.
20export const issuesSearchFromUrl = (raw: Record<string, unknown>): IssuesSearch => ({
21 who:
22 raw.who === "assigned" || raw.who === "authored" || raw.who === "mentioned" ? raw.who : "all",
23 status: raw.status === "closed" || raw.status === "all" ? raw.status : "open",
24 issueServer: bounded(raw.issueServer) as EnvironmentId | undefined,
25 issueProject: bounded(raw.issueProject) as ProjectId | undefined,
26 host: bounded(raw.host),
27 q: bounded(raw.q),
28 label: labels(raw.label),
29 assignee: bounded(raw.assignee),
30 order: raw.order === "created" ? "created" : undefined,
31 selectedEnvironmentId: bounded(raw.selectedEnvironmentId) as EnvironmentId | undefined,
32 selectedProjectId: bounded(raw.selectedProjectId) as ProjectId | undefined,
33 selectedHost: bounded(raw.selectedHost),
34 tracker: bounded(raw.tracker),
35 scope: bounded(raw.scope),
36 key: bounded(raw.key),
37});
38
39/** One choice per project: projects on one repository can read different Linear teams. */
40export const issueFilterProjects = (
41 projects: ReadonlyArray<EnvironmentProject>,
42 environmentLabels: ReadonlyMap<EnvironmentId, string>,
43) =>
44 pullRequestFilterProjects(
45 projects
46 .filter((project) => !project.isScratch)
47 .map((project) => ({ ...project, repositoryIdentity: null })),
48 environmentLabels,
49 );