The best way to control Claude Code, Codex and more from any computer or phone
feat(prs): save named filter views across clients (#29387)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jake Leventhal committed
Nov 17, 2026 at 01:35 UTC
2d265dc410c0dcfa6efc985812032ac23db02ea8
20 files changed
+957
-5
apps/mobile/src/features/layout/workspace/workspace-tabs-state.test.ts
+15
@@ -135,6 +135,21 @@ describe("workspace root navigation", () => {
135
expect(state.tabs.threads.query).toBe("diff");
136
});
137
138
+ it("applying an empty-query view resets the position that search cancellation restores", () => {
139
+ let state = initialWorkspaceTabsState();
140
+ state = workspaceTabsReducer(state, { type: "scroll", tab: "pullRequests", offset: 640 });
141
+ state = workspaceTabsReducer(state, { type: "search", tab: "pullRequests" });
142
+ state = workspaceTabsReducer(state, { type: "query", tab: "pullRequests", query: "old query" });
143
+ state = workspaceTabsReducer(state, { type: "scroll", tab: "pullRequests", offset: 80 });
144
+ state = workspaceTabsReducer(state, { type: "cancel", tab: "pullRequests", scrollToTop: true });
145
+ expect(state.tabs.pullRequests).toEqual({
146
+ query: "",
147
+ searchMode: "resting",
148
+ scrollOffset: 0,
149
+ searchEntryOffset: 0,
150
+ });
151
+ });
152
+
153
it("a late native blur cannot reopen a cancelled search", () => {
154
let state = workspaceTabsReducer(initialWorkspaceTabsState(), { type: "search" });
155
state = workspaceTabsReducer(state, { type: "cancel" });
apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts
+3
-2
@@ -65,7 +65,7 @@ export type WorkspaceTabsAction =
65
| { readonly type: "search"; readonly tab?: WorkspaceSearchTab }
66
| { readonly type: "query"; readonly query: string; readonly tab?: WorkspaceSearchTab }
67
| { readonly type: "expand"; readonly tab?: WorkspaceSearchTab }
68
- | { readonly type: "cancel"; readonly tab?: WorkspaceSearchTab }
68
+ | { readonly type: "cancel"; readonly tab?: WorkspaceSearchTab; readonly scrollToTop?: boolean }
69
| { readonly type: "scroll"; readonly tab: WorkspaceSearchTab; readonly offset: number };
70
71
export function workspaceTabsReducer(
@@ -105,7 +105,8 @@ export function workspaceTabsReducer(
105
...current,
106
query: "",
107
searchMode: "resting",
108
- scrollOffset: current.searchEntryOffset,
108
+ scrollOffset: action.scrollToTop ? 0 : current.searchEntryOffset,
109
+ searchEntryOffset: action.scrollToTop ? 0 : current.searchEntryOffset,
110
};
111
break;
112
case "scroll":
apps/mobile/src/features/pull-requests/PullRequestListFilters.tsx
+3
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
2
import { sortProjectsByGroupOrder } from "@t3tools/client-runtime/state/project-grouping";
3
import type { ScopedProjectRef, SidebarProjectGroupingMode } from "@t3tools/contracts";
4
import { Atom } from "effect/reactivity";
5
+import type { ReactNode } from "react";
6
import { Platform, ScrollView } from "react-native";
7
import type { MenuProps } from "../../components/ui/Menu.types";
8
import { ListFilterMenu } from "../layout/workspace/ListFilterMenu";
@@ -361,6 +362,7 @@ export function PullRequestListFilters(props: {
362
/** Android sidebar rows sit further in than full-width rows; the pills follow them. */
363
readonly sidebar?: boolean;
364
readonly filters: ReturnType<typeof usePullRequestListFilters>;
365
+ readonly savedViewsMenu: ReactNode;
366
}) {
367
const { count, more, reset, select, author, selectedLabelCount } = props.filters;
368
return (
@@ -376,6 +378,7 @@ export function PullRequestListFilters(props: {
378
: ROW_STYLE
379
}
380
>
381
+ {props.savedViewsMenu}
382
{Platform.OS === "android" ? null : (
383
<ListFilterMenu
384
label={count ? String(count) : "Filters"}
apps/mobile/src/features/pull-requests/PullRequestSavedViewsMenu.tsx
new
+131
@@ -0,0 +1,131 @@
1
+import { pullRequestViewNameError } from "@t3tools/client-runtime/pull-request-saved-views";
2
+import { useState } from "react";
3
+import { Alert } from "react-native";
4
+
5
+import { prompt as showTextInputDialog } from "../../components/ui/Dialog";
6
+import type { MenuProps } from "../../components/ui/Menu.types";
7
+import { uuidv4 } from "../../lib/uuid";
8
+import type { PullRequestSavedView } from "../../persistence/mobile-preferences";
9
+import { ListFilterMenu } from "../layout/workspace/ListFilterMenu";
10
+import { pullRequestViewMatches, type PullRequestSavedViewScope } from "./pullRequestSavedViews";
11
+import { usePullRequestSavedViews } from "./usePullRequestListControls";
12
+
13
+export function PullRequestSavedViewsMenu({
14
+ scope,
15
+ onApply,
16
+}: {
17
+ scope: PullRequestSavedViewScope;
18
+ onApply: (view: PullRequestSavedView) => Promise<void>;
19
+}) {
20
+ const { views, ready, update } = usePullRequestSavedViews();
21
+ const [selectedId, setSelectedId] = useState<string | null>(null);
22
+ const [busy, setBusy] = useState(false);
23
+ const selectedView =
24
+ views.find((view) => view.id === selectedId) ??
25
+ views.find((view) => pullRequestViewMatches(view, scope));
26
+ if (selectedId === null && selectedView) setSelectedId(selectedView.id);
27
+ const modified = selectedView !== undefined && !pullRequestViewMatches(selectedView, scope);
28
+
29
+ // These avoid `finally`, which the React Compiler cannot lower; every path clears `busy`.
30
+ async function applyView(view: PullRequestSavedView) {
31
+ setBusy(true);
32
+ try {
33
+ await onApply(view);
34
+ setSelectedId(view.id);
35
+ } catch {
36
+ Alert.alert("Could not apply PR view", "The device could not save your filters. Try again.");
37
+ }
38
+ setBusy(false);
39
+ }
40
+
41
+ async function persist(
42
+ transform: (
43
+ current: ReadonlyArray<PullRequestSavedView>,
44
+ ) => ReadonlyArray<PullRequestSavedView>,
45
+ ) {
46
+ setBusy(true);
47
+ let saved = true;
48
+ try {
49
+ await update(transform);
50
+ } catch {
51
+ Alert.alert("Could not save PR views", "The device could not save your views. Try again.");
52
+ saved = false;
53
+ }
54
+ setBusy(false);
55
+ return saved;
56
+ }
57
+
58
+ function editName(view?: PullRequestSavedView) {
59
+ showTextInputDialog({
60
+ title: view ? "Rename PR view" : "Save PR view",
61
+ initialValue:
62
+ view?.name ??
63
+ (scope.controls.involvement === "reviewing" ? "PRs Requesting My Review" : ""),
64
+ confirmText: "Save",
65
+ onConfirm: (value) => {
66
+ const error = pullRequestViewNameError(value, views, view?.id);
67
+ if (error) {
68
+ Alert.alert("Could not save view", error);
69
+ return;
70
+ }
71
+ const id = view?.id ?? uuidv4();
72
+ const name = value.trim();
73
+ void persist((current) =>
74
+ view
75
+ ? current.map((item) => (item.id === view.id ? { ...item, name } : item))
76
+ : [...current, { ...scope, id, name }],
77
+ ).then((saved) => {
78
+ if (saved) setSelectedId(id);
79
+ });
80
+ },
81
+ });
82
+ }
83
+
84
+ const actions: MenuProps["actions"] = [
85
+ ...views.map((view) => ({
86
+ id: `apply:${view.id}`,
87
+ title: view.name,
88
+ state: selectedView?.id === view.id && !modified ? ("on" as const) : ("off" as const),
89
+ })),
90
+ { id: "save", title: "Save current view…" },
91
+ ...(selectedView
92
+ ? [
93
+ ...(modified ? [{ id: "update", title: "Update saved view" }] : []),
94
+ { id: "rename", title: "Rename view…" },
95
+ { id: "delete", title: "Delete view", attributes: { destructive: true } },
96
+ ]
97
+ : []),
98
+ ];
99
+
100
+ return (
101
+ <ListFilterMenu
102
+ label={selectedView ? `${selectedView.name}${modified ? " *" : ""}` : "Views"}
103
+ active={selectedView !== undefined}
104
+ accessibilityLabel="Saved pull request views"
105
+ actions={actions.map((action) => ({
106
+ ...action,
107
+ attributes: { ...action.attributes, disabled: !ready || busy },
108
+ }))}
109
+ onSelect={(id) => {
110
+ if (!ready || busy) return;
111
+ const view = views.find((item) => `apply:${item.id}` === id);
112
+ if (view) {
113
+ void applyView(view);
114
+ return;
115
+ }
116
+ if (id === "save") editName();
117
+ else if (id === "rename" && selectedView) editName(selectedView);
118
+ else if (id === "update" && selectedView)
119
+ void persist((current) =>
120
+ current.map((item) => (item.id === selectedView.id ? { ...item, ...scope } : item)),
121
+ );
122
+ else if (id === "delete" && selectedView)
123
+ void persist((current) => current.filter((item) => item.id !== selectedView.id)).then(
124
+ (saved) => {
125
+ if (saved) setSelectedId(null);
126
+ },
127
+ );
128
+ }}
129
+ />
130
+ );
131
+}
apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+31
-1
@@ -29,6 +29,7 @@ import {
29
usePullRequestListFilters,
30
type PullRequestFilterMenu,
31
} from "./PullRequestListFilters";
32
+import { PullRequestSavedViewsMenu } from "./PullRequestSavedViewsMenu";
33
import { usePullRequestList } from "./usePullRequestList";
34
import { usePullRequestListControls } from "./usePullRequestListControls";
35
import { usePullRequestListActions } from "./usePullRequestListActions";
@@ -319,7 +320,36 @@ export function PullRequestsScreen(
320
ListHeaderComponentStyle={{ zIndex: 1 }}
321
ListHeaderComponent={
322
<>
322
- <PullRequestListFilters sidebar={sidebar} filters={filters} />
323
+ <PullRequestListFilters
324
+ sidebar={sidebar}
325
+ savedViewsMenu={
326
+ <PullRequestSavedViewsMenu
327
+ scope={{
328
+ environmentId,
329
+ controls,
330
+ query: tab.searchMode === "resting" ? "" : tab.query,
331
+ }}
332
+ onApply={async (view) => {
333
+ await listControls.applyView(view);
334
+ workspace.dispatch(
335
+ view.query.trim()
336
+ ? { type: "search", tab: "pullRequests" }
337
+ : { type: "cancel", tab: "pullRequests", scrollToTop: true },
338
+ );
339
+ workspace.dispatch({
340
+ type: "query",
341
+ tab: "pullRequests",
342
+ query: view.query.trim(),
343
+ });
344
+ void listRef.current?.scrollToOffset({
345
+ offset: Platform.OS === "ios" ? -insets.top : 0,
346
+ animated: false,
347
+ });
348
+ }}
349
+ />
350
+ }
351
+ filters={filters}
352
+ />
353
{result.data?.errors.length ? (
354
<View key={JSON.stringify(targets)}>
355
{result.data.errors.map((error) => (
apps/mobile/src/features/pull-requests/pullRequestSavedViews.test.ts
new
+58
@@ -0,0 +1,58 @@
1
+import { expect, it } from "vite-plus/test";
2
+import type { PullRequestSavedView } from "../../persistence/mobile-preferences";
3
+import { pullRequestSavedViewPreferences, pullRequestViewMatches } from "./pullRequestSavedViews";
4
+
5
+const view = {
6
+ id: "review",
7
+ name: "Review queue",
8
+ environmentId: "remote",
9
+ query: "bug",
10
+ controls: {
11
+ state: "open",
12
+ involvement: "reviewing",
13
+ filters: {
14
+ author: "me",
15
+ draft: "hide",
16
+ labels: [["bug", "fix"], ["urgent"]],
17
+ excludedLabels: ["hold", "later"],
18
+ },
19
+ sort: "created",
20
+ projectId: "project",
21
+ projectEnvironmentId: "remote",
22
+ },
23
+} as const satisfies PullRequestSavedView;
24
+
25
+it("recognizes a saved view regardless of filter property or label ordering", () => {
26
+ const controls = {
27
+ ...view.controls,
28
+ filters: {
29
+ excludedLabels: ["later", "hold"],
30
+ labels: [["urgent"], ["fix", "bug"]],
31
+ draft: "hide",
32
+ author: "me",
33
+ },
34
+ } as const;
35
+ expect(pullRequestViewMatches(view, { ...view, query: " bug ", controls })).toBe(true);
36
+ expect(view.controls.filters.labels).toEqual([["bug", "fix"], ["urgent"]]);
37
+ expect(
38
+ pullRequestViewMatches(view, {
39
+ ...view,
40
+ controls: { ...view.controls, projectEnvironmentId: "other" },
41
+ }),
42
+ ).toBe(false);
43
+});
44
+
45
+it("applies a view's environment and controls while keeping other environments' controls", () => {
46
+ const local = { state: "merged", involvement: "authored", filters: {}, sort: "oldest" } as const;
47
+ expect(
48
+ pullRequestSavedViewPreferences(
49
+ { pullRequestListFilters: { environmentId: "local", controls: { local } } },
50
+ view,
51
+ ),
52
+ ).toEqual({
53
+ pullRequestListFilters: {
54
+ environmentId: "remote",
55
+ controls: { local, remote: view.controls },
56
+ },
57
+ });
58
+});
apps/mobile/src/features/pull-requests/pullRequestSavedViews.ts
new
+44
@@ -0,0 +1,44 @@
1
+import type { Preferences, PullRequestSavedView } from "../../persistence/mobile-preferences";
2
+
3
+export type PullRequestSavedViewScope = Pick<
4
+ PullRequestSavedView,
5
+ "environmentId" | "controls" | "query"
6
+>;
7
+
8
+export function pullRequestViewMatches(
9
+ view: PullRequestSavedView,
10
+ scope: PullRequestSavedViewScope,
11
+) {
12
+ const key = ({ environmentId, controls, query }: PullRequestSavedViewScope) =>
13
+ JSON.stringify([
14
+ environmentId,
15
+ query.trim(),
16
+ controls.state,
17
+ controls.involvement,
18
+ controls.sort,
19
+ controls.projectId,
20
+ controls.projectEnvironmentId,
21
+ controls.filters.draft,
22
+ controls.filters.review,
23
+ controls.filters.checks,
24
+ controls.filters.author,
25
+ controls.filters.labels
26
+ ?.map((group) => [...group].sort())
27
+ .sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b))),
28
+ controls.filters.excludedLabels ? [...controls.filters.excludedLabels].sort() : undefined,
29
+ ]);
30
+ return key(view) === key(scope);
31
+}
32
+
33
+/** Apply environment and controls in one preference write, retaining other environments' controls. */
34
+export function pullRequestSavedViewPreferences(current: Preferences, view: PullRequestSavedView) {
35
+ return {
36
+ pullRequestListFilters: {
37
+ environmentId: view.environmentId,
38
+ controls: {
39
+ ...current.pullRequestListFilters?.controls,
40
+ [view.environmentId ?? ""]: view.controls,
41
+ },
42
+ },
43
+ };
44
+}
apps/mobile/src/features/pull-requests/usePullRequestListControls.ts
+30
-1
@@ -3,10 +3,13 @@ import { AsyncResult } from "effect/reactivity";
3
4
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
5
import { DEFAULT_PR_LIST_CONTROLS, type PullRequestListControls } from "./pullRequestList";
6
+import type { PullRequestSavedView } from "../../persistence/mobile-preferences";
7
+import { pullRequestSavedViewPreferences } from "./pullRequestSavedViews";
8
9
export function usePullRequestListControls() {
10
const preferences = useAtomValue(mobilePreferencesAtom);
11
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
12
+ const applyPreferences = useAtomSet(updateMobilePreferencesAtom, { mode: "promise" });
13
const saved = AsyncResult.isSuccess(preferences)
14
? preferences.value.pullRequestListFilters
15
: undefined;
@@ -35,7 +38,33 @@ export function usePullRequestListControls() {
38
},
39
}),
40
});
38
- return { environmentId, controlsFor, setEnvironmentId, setControls } as const;
41
+ const applyView = (view: PullRequestSavedView) =>
42
+ applyPreferences({
43
+ transform: (current) => pullRequestSavedViewPreferences(current, view),
44
+ });
45
+ return { environmentId, controlsFor, setEnvironmentId, setControls, applyView } as const;
46
+}
47
+
48
+const EMPTY_SAVED_VIEWS: ReadonlyArray<PullRequestSavedView> = [];
49
+
50
+export function usePullRequestSavedViews() {
51
+ const preferences = useAtomValue(mobilePreferencesAtom);
52
+ const savePreferences = useAtomSet(updateMobilePreferencesAtom, { mode: "promise" });
53
+ const ready = AsyncResult.isSuccess(preferences) && !preferences.waiting;
54
+ const views = AsyncResult.isSuccess(preferences)
55
+ ? (preferences.value.pullRequestSavedViews ?? EMPTY_SAVED_VIEWS)
56
+ : EMPTY_SAVED_VIEWS;
57
+ const update = (
58
+ transform: (
59
+ current: ReadonlyArray<PullRequestSavedView>,
60
+ ) => ReadonlyArray<PullRequestSavedView>,
61
+ ) =>
62
+ savePreferences({
63
+ transform: (current) => ({
64
+ pullRequestSavedViews: transform(current.pullRequestSavedViews ?? EMPTY_SAVED_VIEWS),
65
+ }),
66
+ });
67
+ return { views, ready, update } as const;
68
}
69
70
function withEnvironmentControls(
apps/mobile/src/lib/storage.test.ts
+29
@@ -152,6 +152,35 @@ describe("mobile connection storage", () => {
152
expect(fallback.updatedAt).toEqual(expect.any(Number));
153
});
154
155
+ it("discards malformed saved PR views without discarding other preferences", async () => {
156
+ const validView = {
157
+ id: "reviewing",
158
+ name: "Review queue",
159
+ environmentId: null,
160
+ query: "bug",
161
+ controls: { state: "open", involvement: "reviewing", filters: {}, sort: "updated" },
162
+ } as const;
163
+ mocks.setPreferencesJson(
164
+ JSON.stringify({
165
+ baseFontSize: 17,
166
+ pullRequestSavedViews: [
167
+ validView,
168
+ {
169
+ ...validView,
170
+ id: "invalid",
171
+ name: "Broken",
172
+ controls: { ...validView.controls, sort: "unknown" },
173
+ },
174
+ ],
175
+ }),
176
+ 10,
177
+ );
178
+ expect(await loadPreferences()).toEqual({
179
+ baseFontSize: 17,
180
+ pullRequestSavedViews: [validView],
181
+ });
182
+ });
183
+
184
it("reconciles fallback preferences after SQLite recovers", async () => {
185
mocks.setPreferencesJson(JSON.stringify({ baseFontSize: 15 }), 10);
186
await mocks.setItemAsync(
apps/mobile/src/persistence/mobile-preferences.ts
+15
@@ -5,6 +5,7 @@ import * as Option from "effect/Option";
5
import * as Ref from "effect/Ref";
6
import * as Schema from "effect/Schema";
7
import * as Semaphore from "effect/Semaphore";
8
+import { PullRequestSavedViewIdentity } from "@t3tools/client-runtime/pull-request-saved-views";
9
import {
10
EnvironmentId,
11
PullRequestInvolvement,
@@ -38,6 +39,15 @@ export const PullRequestListControls = Schema.Struct({
39
});
40
export type PullRequestListControls = typeof PullRequestListControls.Type;
41
42
+export const PullRequestSavedView = Schema.Struct({
43
+ ...PullRequestSavedViewIdentity.fields,
44
+ environmentId: Schema.NullOr(Schema.String),
45
+ controls: PullRequestListControls,
46
+ query: Schema.String,
47
+});
48
+export type PullRequestSavedView = typeof PullRequestSavedView.Type;
49
+const isPullRequestSavedView = Schema.is(PullRequestSavedView);
50
+
51
const ThreadListFilters = Schema.Struct({
52
environmentId: Schema.NullOr(EnvironmentId),
53
projectKey: Schema.NullOr(Schema.String),
@@ -154,6 +164,7 @@ export interface Preferences {
164
readonly threadListFilters?: ThreadListFilters;
165
readonly pullRequestListFilters?: PullRequestListPreferences;
166
readonly workspaceSelections?: WorkspaceSelections;
167
+ readonly pullRequestSavedViews?: ReadonlyArray<PullRequestSavedView>;
168
}
169
170
export class MobilePreferencesLoadError extends Schema.TaggedError<MobilePreferencesLoadError>()(
@@ -239,6 +250,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
250
threadListFilters?: ThreadListFilters;
251
pullRequestListFilters?: PullRequestListPreferences;
252
workspaceSelections?: WorkspaceSelections;
253
+ pullRequestSavedViews?: ReadonlyArray<PullRequestSavedView>;
254
} = {};
255
256
if (Array.isArray(parsed.hiddenNavigationTabs)) {
@@ -398,6 +410,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
410
if (isWorkspaceSelections(parsed.workspaceSelections)) {
411
preferences.workspaceSelections = parsed.workspaceSelections;
412
}
413
+ if (Array.isArray(parsed.pullRequestSavedViews)) {
414
+ preferences.pullRequestSavedViews = parsed.pullRequestSavedViews.filter(isPullRequestSavedView);
415
+ }
416
return preferences;
417
}
418
apps/web/src/components/pullRequest/PullRequestSavedViewsMenu.browser.test.tsx
new
+146
@@ -0,0 +1,146 @@
1
+import { describe, expect, it, vi } from "vite-plus/test";
2
+
3
+import { act, render, type Screen } from "../../../test/render";
4
+import { PullRequestSavedViewsMenu } from "./PullRequestSavedViewsMenu";
5
+import type { PullRequestListPreferences } from "./pullRequestListPreferences";
6
+import { PULL_REQUEST_SAVED_VIEWS_KEY, type PullRequestSavedView } from "./pullRequestSavedViews";
7
+
8
+const { toastAdd } = vi.hoisted(() => ({ toastAdd: vi.fn() }));
9
+vi.mock("../ui/toast", () => ({ toastManager: { add: toastAdd } }));
10
+
11
+const reviewing = {
12
+ involvement: "reviewing",
13
+ state: "open",
14
+ q: "bug",
15
+ draft: "hide",
16
+ sort: "updated",
17
+} as const satisfies PullRequestListPreferences;
18
+
19
+function setup() {
20
+ localStorage.clear();
21
+ const onApply = vi.fn();
22
+ toastAdd.mockClear();
23
+ return {
24
+ onApply,
25
+ menu: (preferences: PullRequestListPreferences = reviewing) => (
26
+ <PullRequestSavedViewsMenu preferences={preferences} onApply={onApply} />
27
+ ),
28
+ [Symbol.dispose]() {
29
+ localStorage.clear();
30
+ vi.restoreAllMocks();
31
+ },
32
+ };
33
+}
34
+
35
+async function openMenu(screen: Screen) {
36
+ await act(() =>
37
+ screen.container
38
+ .querySelector<HTMLButtonElement>('[aria-label="Saved pull request views"]')!
39
+ .click(),
40
+ );
41
+}
42
+
43
+async function choose(label: string) {
44
+ const item = [...document.querySelectorAll<HTMLElement>('[role="menuitem"]')].find(
45
+ (element) => element.textContent === label,
46
+ );
47
+ expect(item, label).toBeDefined();
48
+ await act(() => item!.click());
49
+}
50
+
51
+async function nameView(name: string) {
52
+ const input = document.querySelector<HTMLInputElement>("input")!;
53
+ await act(() => {
54
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(input, name);
55
+ input.dispatchEvent(new Event("input", { bubbles: true }));
56
+ });
57
+}
58
+
59
+async function submit() {
60
+ await act(() =>
61
+ document
62
+ .querySelector("form")!
63
+ .dispatchEvent(new Event("submit", { bubbles: true, cancelable: true })),
64
+ );
65
+}
66
+
67
+function storedViews(): ReadonlyArray<PullRequestSavedView> {
68
+ return JSON.parse(localStorage.getItem(PULL_REQUEST_SAVED_VIEWS_KEY) ?? "[]");
69
+}
70
+
71
+describe("PullRequestSavedViewsMenu", () => {
72
+ it("saves a named filter setup and restores it after remounting", async () => {
73
+ using fixture = setup();
74
+ const { menu } = fixture;
75
+ await using first = await render(menu());
76
+ await openMenu(first);
77
+ await choose("Save current view…");
78
+ expect(document.querySelector("input")?.value).toBe("PRs Requesting My Review");
79
+ await submit();
80
+ expect(storedViews()).toEqual([
81
+ { id: expect.any(String), name: "PRs Requesting My Review", preferences: reviewing },
82
+ ]);
83
+
84
+ await first.unmount();
85
+ const merged = { involvement: "all", state: "merged", checks: "failing" } as const;
86
+ await using screen = await render(menu(merged));
87
+ await openMenu(screen);
88
+ await choose("PRs Requesting My Review");
89
+ expect(fixture.onApply).toHaveBeenCalledExactlyOnceWith(reviewing);
90
+ });
91
+
92
+ it("updates, renames, and deletes a view without affecting another saved view", async () => {
93
+ using fixture = setup();
94
+ const { menu } = fixture;
95
+ localStorage.setItem(
96
+ PULL_REQUEST_SAVED_VIEWS_KEY,
97
+ JSON.stringify([
98
+ { id: "reviewing", name: "Review queue", preferences: reviewing },
99
+ { id: "authored", name: "My PRs", preferences: { involvement: "authored", state: "open" } },
100
+ ]),
101
+ );
102
+ await using screen = await render(menu());
103
+ await openMenu(screen);
104
+ await choose("Review queue");
105
+ await screen.rerender(menu({ ...reviewing, checks: "passing" }));
106
+ await openMenu(screen);
107
+ await choose("Update saved view");
108
+ expect(storedViews()[0]?.preferences.checks).toBe("passing");
109
+ await openMenu(screen);
110
+ await choose("Rename view…");
111
+ await nameView("My PRs");
112
+ expect(document.body.textContent).toContain("A view with this name already exists.");
113
+ await nameView(" Ready to review ");
114
+ await submit();
115
+ expect(storedViews()[0]?.name).toBe("Ready to review");
116
+ await openMenu(screen);
117
+ await choose("Delete view");
118
+ expect(storedViews().map((view) => view.id)).toEqual(["authored"]);
119
+ });
120
+
121
+ it("keeps an inferred view as the update target when edits match another view", async () => {
122
+ using fixture = setup();
123
+ const { menu } = fixture;
124
+ const other = {
125
+ id: "other",
126
+ name: "Other queue",
127
+ preferences: { ...reviewing, checks: "passing" },
128
+ } as const;
129
+ localStorage.setItem(
130
+ PULL_REQUEST_SAVED_VIEWS_KEY,
131
+ JSON.stringify([{ id: "reviewing", name: "Review queue", preferences: reviewing }, other]),
132
+ );
133
+ await using screen = await render(menu());
134
+ await screen.rerender(menu(other.preferences));
135
+ expect(screen.container.textContent).toContain("Review queue*");
136
+ await openMenu(screen);
137
+ await choose("Update saved view");
138
+ expect(storedViews()).toEqual([
139
+ { id: "reviewing", name: "Review queue", preferences: other.preferences },
140
+ other,
141
+ ]);
142
+ await openMenu(screen);
143
+ await choose("Other queue");
144
+ expect(screen.container.textContent).toContain("Other queue");
145
+ });
146
+});
apps/web/src/components/pullRequest/PullRequestSavedViewsMenu.tsx
new
+261
@@ -0,0 +1,261 @@
1
+import { BookmarkIcon, CheckIcon, ChevronDownIcon, PlusIcon } from "lucide-react";
2
+import { useId, useState } from "react";
3
+import {
4
+ PULL_REQUEST_VIEW_NAME_MAX_LENGTH,
5
+ pullRequestViewNameError,
6
+} from "@t3tools/client-runtime/pull-request-saved-views";
7
+
8
+import { getLocalStorageItem, useLocalStorage } from "../../hooks/useLocalStorage";
9
+import { randomUUID } from "../../lib/utils";
10
+import { Button } from "../ui/button";
11
+import {
12
+ Dialog,
13
+ DialogDescription,
14
+ DialogFooter,
15
+ DialogHeader,
16
+ DialogPanel,
17
+ DialogPopup,
18
+ DialogTitle,
19
+} from "../ui/dialog";
20
+import { Input } from "../ui/input";
21
+import { Label } from "../ui/label";
22
+import { Menu, MenuItem, MenuItemLabel, MenuPopup, MenuSeparator, MenuTrigger } from "../ui/menu";
23
+import { toastManager } from "../ui/toast";
24
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
25
+import {
26
+ pullRequestListPreferences,
27
+ type PullRequestListPreferences,
28
+} from "./pullRequestListPreferences";
29
+import {
30
+ EMPTY_PULL_REQUEST_SAVED_VIEWS,
31
+ PULL_REQUEST_SAVED_VIEWS_KEY,
32
+ PullRequestSavedViews,
33
+ pullRequestViewMatches,
34
+ type PullRequestSavedView,
35
+} from "./pullRequestSavedViews";
36
+
37
+export function PullRequestSavedViewsMenu({
38
+ preferences,
39
+ onApply,
40
+}: {
41
+ preferences: PullRequestListPreferences;
42
+ onApply: (preferences: PullRequestListPreferences) => void;
43
+}) {
44
+ const [views, setViews] = useLocalStorage(
45
+ PULL_REQUEST_SAVED_VIEWS_KEY,
46
+ EMPTY_PULL_REQUEST_SAVED_VIEWS,
47
+ PullRequestSavedViews,
48
+ );
49
+ const [selectedId, setSelectedId] = useState<string | null>(null);
50
+ const [editor, setEditor] = useState<{ id?: string; name: string } | null>(null);
51
+ const inputId = useId();
52
+ const errorId = useId();
53
+ const selectedView =
54
+ views.find((view) => view.id === selectedId) ??
55
+ views.find((view) => pullRequestViewMatches(view, preferences));
56
+ if (selectedView && selectedId !== selectedView.id) setSelectedId(selectedView.id);
57
+ const modified = selectedView !== undefined && !pullRequestViewMatches(selectedView, preferences);
58
+ const nameError = editor ? pullRequestViewNameError(editor.name, views, editor.id) : null;
59
+
60
+ function persist(
61
+ update: (current: ReadonlyArray<PullRequestSavedView>) => ReadonlyArray<PullRequestSavedView>,
62
+ ) {
63
+ let written: ReadonlyArray<PullRequestSavedView> | undefined;
64
+ setViews((current) => {
65
+ written = update(current);
66
+ return written;
67
+ });
68
+ // The shared hook logs storage failures. Keep the editor open and explain when saving failed.
69
+ try {
70
+ if (
71
+ written &&
72
+ JSON.stringify(getLocalStorageItem(PULL_REQUEST_SAVED_VIEWS_KEY, PullRequestSavedViews)) ===
73
+ JSON.stringify(written)
74
+ ) {
75
+ return true;
76
+ }
77
+ } catch {
78
+ // A browser policy can deny reads as well as writes.
79
+ }
80
+ toastManager.add({
81
+ type: "error",
82
+ title: "Could not save PR views",
83
+ description:
84
+ "Local storage is unavailable or full. Try again after freeing space or allowing storage.",
85
+ });
86
+ return false;
87
+ }
88
+
89
+ function saveName() {
90
+ if (!editor || nameError) return;
91
+ const id = editor.id ?? randomUUID();
92
+ const name = editor.name.trim();
93
+ const editingId = editor.id;
94
+ let missing = false;
95
+ const saved = persist((current) => {
96
+ if (editingId && !current.some((view) => view.id === editingId)) {
97
+ missing = true;
98
+ return current;
99
+ }
100
+ return editingId
101
+ ? current.map((view) => (view.id === editingId ? { ...view, name } : view))
102
+ : [...current, { id, name, preferences: pullRequestListPreferences(preferences) }];
103
+ });
104
+ if (missing) {
105
+ setEditor((current) => (current ? { name: current.name } : null));
106
+ toastManager.add({
107
+ type: "error",
108
+ title: "This saved view was removed",
109
+ description: "Your name has been kept. Save it as a new view or cancel.",
110
+ });
111
+ return;
112
+ }
113
+ if (!saved) return;
114
+ setSelectedId(id);
115
+ setEditor(null);
116
+ }
117
+
118
+ return (
119
+ <>
120
+ <Menu>
121
+ <Tooltip>
122
+ <TooltipTrigger
123
+ render={
124
+ <MenuTrigger
125
+ render={<Button variant="outline" />}
126
+ aria-label="Saved pull request views"
127
+ />
128
+ }
129
+ >
130
+ <BookmarkIcon aria-hidden className="size-4" />
131
+ <span className="max-w-40 truncate">{selectedView?.name ?? "Views"}</span>
132
+ {modified ? <span aria-label="Modified view">*</span> : null}
133
+ <ChevronDownIcon aria-hidden className="size-3 shrink-0" />
134
+ </TooltipTrigger>
135
+ <TooltipPopup>{selectedView?.name ?? "Saved pull request views"}</TooltipPopup>
136
+ </Tooltip>
137
+ <MenuPopup align="start">
138
+ {views.map((view) => (
139
+ <Tooltip key={view.id}>
140
+ <TooltipTrigger
141
+ render={
142
+ <MenuItem
143
+ onClick={() => {
144
+ setSelectedId(view.id);
145
+ onApply(pullRequestListPreferences(view.preferences));
146
+ }}
147
+ />
148
+ }
149
+ >
150
+ {selectedView?.id === view.id && !modified ? (
151
+ <CheckIcon aria-hidden />
152
+ ) : (
153
+ <BookmarkIcon aria-hidden />
154
+ )}
155
+ <MenuItemLabel>{view.name}</MenuItemLabel>
156
+ </TooltipTrigger>
157
+ <TooltipPopup side="right">{view.name}</TooltipPopup>
158
+ </Tooltip>
159
+ ))}
160
+ {views.length > 0 ? <MenuSeparator /> : null}
161
+ <MenuItem
162
+ onClick={() =>
163
+ setEditor({
164
+ name: preferences.involvement === "reviewing" ? "PRs Requesting My Review" : "",
165
+ })
166
+ }
167
+ >
168
+ <PlusIcon aria-hidden />
169
+ Save current view…
170
+ </MenuItem>
171
+ {selectedView ? (
172
+ <>
173
+ {modified ? (
174
+ <MenuItem
175
+ onClick={() =>
176
+ persist((current) =>
177
+ current.map((view) =>
178
+ view.id === selectedView.id
179
+ ? { ...view, preferences: pullRequestListPreferences(preferences) }
180
+ : view,
181
+ ),
182
+ )
183
+ }
184
+ >
185
+ Update saved view
186
+ </MenuItem>
187
+ ) : null}
188
+ <MenuItem onClick={() => setEditor({ id: selectedView.id, name: selectedView.name })}>
189
+ Rename view…
190
+ </MenuItem>
191
+ <MenuItem
192
+ variant="destructive"
193
+ onClick={() => {
194
+ if (persist((current) => current.filter((view) => view.id !== selectedView.id)))
195
+ setSelectedId(null);
196
+ }}
197
+ >
198
+ Delete view
199
+ </MenuItem>
200
+ </>
201
+ ) : null}
202
+ </MenuPopup>
203
+ </Menu>
204
+ <Dialog
205
+ open={editor !== null}
206
+ onOpenChange={(open) => {
207
+ if (!open) setEditor(null);
208
+ }}
209
+ >
210
+ <DialogPopup>
211
+ <form
212
+ className="flex min-h-0 flex-col"
213
+ onSubmit={(event) => {
214
+ event.preventDefault();
215
+ saveName();
216
+ }}
217
+ >
218
+ <DialogHeader>
219
+ <DialogTitle>{editor?.id ? "Rename PR view" : "Save PR view"}</DialogTitle>
220
+ <DialogDescription>
221
+ Save your search, filters, and sort order on this device.
222
+ </DialogDescription>
223
+ </DialogHeader>
224
+ <DialogPanel>
225
+ <div className="flex flex-col gap-2">
226
+ <Label htmlFor={inputId}>View name</Label>
227
+ <Input
228
+ id={inputId}
229
+ autoFocus
230
+ value={editor?.name ?? ""}
231
+ maxLength={PULL_REQUEST_VIEW_NAME_MAX_LENGTH}
232
+ placeholder="PRs Requesting My Review"
233
+ aria-invalid={Boolean(editor?.name && nameError)}
234
+ aria-describedby={nameError && editor?.name ? errorId : undefined}
235
+ onChange={(event) =>
236
+ setEditor((current) =>
237
+ current ? { ...current, name: event.target.value } : null,
238
+ )
239
+ }
240
+ />
241
+ {nameError && editor?.name ? (
242
+ <p id={errorId} className="text-sm text-destructive-foreground">
243
+ {nameError}
244
+ </p>
245
+ ) : null}
246
+ </div>
247
+ </DialogPanel>
248
+ <DialogFooter>
249
+ <Button variant="outline" onClick={() => setEditor(null)}>
250
+ Cancel
251
+ </Button>
252
+ <Button type="submit" disabled={nameError !== null}>
253
+ Save
254
+ </Button>
255
+ </DialogFooter>
256
+ </form>
257
+ </DialogPopup>
258
+ </Dialog>
259
+ </>
260
+ );
261
+}
apps/web/src/components/pullRequest/PullRequestsColumn.tsx
+3
@@ -82,6 +82,7 @@ export function PullRequestsColumn({
82
searchInput,
83
sortMenu,
84
filtersMenu,
85
+ savedViewsMenu,
86
rightPanelControl,
87
titlebarControls,
88
rightPanelOpen,
@@ -102,6 +103,7 @@ export function PullRequestsColumn({
103
searchInput: ReactNode;
104
sortMenu: ReactNode;
105
filtersMenu: ReactNode;
106
+ savedViewsMenu: ReactNode;
107
rightPanelControl: ReactNode;
108
titlebarControls: ReactNode;
109
rightPanelOpen: boolean;
@@ -240,6 +242,7 @@ export function PullRequestsColumn({
242
</div>
243
{sortMenu}
244
{filtersMenu}
245
+ {savedViewsMenu}
246
<PullRequestCompactFilterMenu
247
label="Filter by provider"
248
outlined
apps/web/src/components/pullRequest/PullRequestsPage.tsx
+8
@@ -54,6 +54,8 @@ import {
54
type PullRequestListPreferencePatch,
55
writePullRequestListPreferences,
56
} from "./pullRequestListPreferences";
57
+import { PullRequestSavedViewsMenu } from "./PullRequestSavedViewsMenu";
58
+import { pullRequestSavedViewPatch } from "./pullRequestSavedViews";
59
import { environmentMachineIcon } from "../EnvironmentMachineIcon";
60
import { PullRequestDetailPanel } from "./PullRequestDetailPanel";
61
import {
@@ -1421,6 +1423,12 @@ export function PullRequestsPage() {
1423
searchInput,
1424
sortMenu,
1425
filtersMenu,
1426
+ savedViewsMenu: (
1427
+ <PullRequestSavedViewsMenu
1428
+ preferences={search}
1429
+ onApply={(preferences) => updateListScope(pullRequestSavedViewPatch(preferences))}
1430
+ />
1431
+ ),
1432
rightPanelControl: !pullRequestsSupported ? null : (
1433
<span
1434
aria-hidden
apps/web/src/components/pullRequest/pullRequestListPreferences.ts
+1
-1
@@ -44,7 +44,7 @@ const DEFAULT_PULL_REQUEST_LIST_PREFERENCES = {
44
} as const satisfies PullRequestListPreferences;
45
46
const BoundedPreference = Schema.String.check(Schema.isMaxLength(200));
47
-const PullRequestListPreferencesSchema = Schema.Struct({
47
+export const PullRequestListPreferencesSchema = Schema.Struct({
48
involvement: PullRequestInvolvement,
49
state: PullRequestListState,
50
environmentId: Schema.optional(EnvironmentId),
apps/web/src/components/pullRequest/pullRequestSavedViews.test.ts
new
+87
@@ -0,0 +1,87 @@
1
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2
+import { pullRequestViewNameError } from "@t3tools/client-runtime/pull-request-saved-views";
3
+import { describe, expect, it } from "vite-plus/test";
4
+
5
+import {
6
+ pullRequestListPreferences,
7
+ type PullRequestListPreferences,
8
+} from "./pullRequestListPreferences";
9
+import { pullRequestSavedViewPatch, pullRequestViewMatches } from "./pullRequestSavedViews";
10
+
11
+const preferences = {
12
+ involvement: "reviewing",
13
+ state: "open",
14
+ environmentId: EnvironmentId.make("remote"),
15
+ projectId: ProjectId.make("project"),
16
+ host: "github.example.com",
17
+ q: "label:bug authentication",
18
+ draft: "hide",
19
+ review: "review-required",
20
+ checks: "passing",
21
+ author: "me",
22
+ labels: ["bug", "priority"],
23
+ sort: "updated",
24
+} as const satisfies PullRequestListPreferences;
25
+const view = { id: "review", name: "PRs Requesting My Review", preferences };
26
+
27
+describe("saved PR views", () => {
28
+ it("replaces all filters while preserving the selected PR", () => {
29
+ const current = {
30
+ ...preferences,
31
+ repository: "org/repo",
32
+ number: 42,
33
+ selectedHost: "github.com",
34
+ selectedEnvironmentId: EnvironmentId.make("other"),
35
+ selectedProjectId: ProjectId.make("other"),
36
+ };
37
+ const restored = {
38
+ ...current,
39
+ ...pullRequestSavedViewPatch({ involvement: "all", state: "merged" }),
40
+ };
41
+ expect(pullRequestListPreferences(restored)).toEqual({ involvement: "all", state: "merged" });
42
+ expect(restored).toMatchObject({
43
+ repository: "org/repo",
44
+ number: 42,
45
+ selectedHost: "github.com",
46
+ selectedEnvironmentId: "other",
47
+ selectedProjectId: "other",
48
+ });
49
+ });
50
+
51
+ it("restores scoped filters without conflating a project on two environments", () => {
52
+ const previous = { involvement: "all", state: "closed" } as const;
53
+ expect(
54
+ pullRequestListPreferences({
55
+ ...previous,
56
+ ...pullRequestSavedViewPatch(preferences),
57
+ }),
58
+ ).toEqual(preferences);
59
+ expect(
60
+ pullRequestViewMatches(view, {
61
+ ...preferences,
62
+ environmentId: EnvironmentId.make("another"),
63
+ }),
64
+ ).toBe(false);
65
+ });
66
+
67
+ it("matches default sorting and label sets regardless of selection or label order", () => {
68
+ const defaultView = { ...view, preferences: { ...preferences, sort: undefined } };
69
+ expect(
70
+ pullRequestViewMatches(defaultView, {
71
+ ...preferences,
72
+ labels: ["priority", "bug"],
73
+ sort: "ready",
74
+ }),
75
+ ).toBe(true);
76
+ expect(pullRequestViewMatches(view, { ...preferences, q: "different" })).toBe(false);
77
+ expect(pullRequestViewMatches(view, { ...preferences, labels: ["bug"] })).toBe(false);
78
+ });
79
+
80
+ it("rejects blank and duplicate names while allowing a view to keep its own name", () => {
81
+ expect(pullRequestViewNameError(" ", [view])).toBeTruthy();
82
+ expect(pullRequestViewNameError("x".repeat(81), [view])).toBeTruthy();
83
+ expect(pullRequestViewNameError(" PRS REQUESTING MY REVIEW ", [view])).toBeTruthy();
84
+ expect(pullRequestViewNameError(view.name, [view], view.id)).toBeNull();
85
+ expect(pullRequestViewNameError(" My PRs ", [view])).toBeNull();
86
+ });
87
+});
apps/web/src/components/pullRequest/pullRequestSavedViews.ts
new
+54
@@ -0,0 +1,54 @@
1
+import * as Schema from "effect/Schema";
2
+import { PullRequestSavedViewIdentity } from "@t3tools/client-runtime/pull-request-saved-views";
3
+
4
+import {
5
+ pullRequestListPreferences,
6
+ PullRequestListPreferencesSchema,
7
+ type PullRequestListPreferencePatch,
8
+ type PullRequestListPreferences,
9
+} from "./pullRequestListPreferences";
10
+
11
+export const PULL_REQUEST_SAVED_VIEWS_KEY = "t3.pullRequests.savedViews";
12
+
13
+export const PullRequestSavedViews = Schema.Array(
14
+ Schema.Struct({
15
+ ...PullRequestSavedViewIdentity.fields,
16
+ preferences: PullRequestListPreferencesSchema,
17
+ }),
18
+);
19
+export type PullRequestSavedView = (typeof PullRequestSavedViews.Type)[number];
20
+export const EMPTY_PULL_REQUEST_SAVED_VIEWS: typeof PullRequestSavedViews.Type = [];
21
+
22
+export function pullRequestViewMatches(
23
+ view: PullRequestSavedView,
24
+ preferences: PullRequestListPreferences,
25
+): boolean {
26
+ const key = (value: PullRequestListPreferences) => {
27
+ const normalized = pullRequestListPreferences(value);
28
+ return JSON.stringify({
29
+ ...normalized,
30
+ labels: normalized.labels?.toSorted(),
31
+ });
32
+ };
33
+ return key(pullRequestListPreferences(view.preferences)) === key(preferences);
34
+}
35
+
36
+/** Explicit clears replace the old list scope without touching the independently selected PR. */
37
+export function pullRequestSavedViewPatch(
38
+ preferences: PullRequestListPreferences,
39
+): PullRequestListPreferencePatch & Pick<PullRequestListPreferences, "involvement" | "state"> {
40
+ return {
41
+ involvement: preferences.involvement,
42
+ state: preferences.state,
43
+ environmentId: preferences.environmentId,
44
+ projectId: preferences.projectId,
45
+ host: preferences.host,
46
+ q: preferences.q,
47
+ draft: preferences.draft,
48
+ review: preferences.review,
49
+ checks: preferences.checks,
50
+ author: preferences.author,
51
+ labels: preferences.labels,
52
+ sort: preferences.sort,
53
+ };
54
+}
docs/user/source-control.md
+6
@@ -198,6 +198,12 @@ Where you can edit a description, you can also tick its checkboxes from the Summ
198
(the Overview tab on mobile).
199
GitLab calls these merge requests.
200
201
+Save a filter setup with **Views → Save current view** on the Pull Requests page. For example, choose
202
+**Reviewing** (**Your review** on mobile) and save it as "PRs Requesting My Review". Choose a saved view to restore its search,
203
+filters, sort order, and server/project scope. After changing filters, use **Update saved view** to
204
+keep the changes, or save another view. You can also rename or delete views from the same menu.
205
+Saved views stay in the browser or app where you created them and do not sync across devices.
206
+
207
A link to part of a pull request opens that part: a comment or review is marked in the activity, a
208
changed-line link opens the file at those lines, a checks link opens the checks, and a commit link
209
opens that commit's changes. On web and desktop, hovering a comment or commit link previews it.
packages/client-runtime/package.json
+4
@@ -23,6 +23,10 @@
23
"types": "./src/workspaceBasenameLookup.ts",
24
"default": "./src/workspaceBasenameLookup.ts"
25
},
26
+ "./pull-request-saved-views": {
27
+ "types": "./src/pullRequestSavedViews.ts",
28
+ "default": "./src/pullRequestSavedViews.ts"
29
+ },
30
"./composerThreadItems": {
31
"types": "./src/composerThreadItems.ts",
32
"default": "./src/composerThreadItems.ts"
packages/client-runtime/src/pullRequestSavedViews.ts
new
+28
@@ -0,0 +1,28 @@
1
+import * as Schema from "effect/Schema";
2
+
3
+export const PULL_REQUEST_VIEW_NAME_MAX_LENGTH = 80;
4
+
5
+export const PullRequestSavedViewIdentity = Schema.Struct({
6
+ id: Schema.String.check(Schema.isMinLength(1)),
7
+ name: Schema.String.check(
8
+ Schema.isMinLength(1),
9
+ Schema.isMaxLength(PULL_REQUEST_VIEW_NAME_MAX_LENGTH),
10
+ ),
11
+});
12
+
13
+export function pullRequestViewNameError(
14
+ name: string,
15
+ views: ReadonlyArray<typeof PullRequestSavedViewIdentity.Type>,
16
+ editingId?: string,
17
+): string | null {
18
+ const trimmed = name.trim();
19
+ if (!trimmed) return "Enter a name for this view.";
20
+ if (trimmed.length > PULL_REQUEST_VIEW_NAME_MAX_LENGTH) {
21
+ return `Use ${PULL_REQUEST_VIEW_NAME_MAX_LENGTH} characters or fewer.`;
22
+ }
23
+ return views.some(
24
+ (view) => view.id !== editingId && view.name.toLowerCase() === trimmed.toLowerCase(),
25
+ )
26
+ ? "A view with this name already exists."
27
+ : null;
28
+}