@devries-cameron20 / t3code-1 / commits / bb29ee3e71
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(issues): save named filter views on web and mobile (#37963)

Julius Marminge committed Nov 16, 2026 at 23:10 UTC bb29ee3e71b3241309b4fad0c76efdf16461b6ec
21 files changed +369 -174
apps/mobile/src/features/issues/IssuesScreen.tsx
+32
@@ -48,6 +48,8 @@ import { issueParamsKey } from "./issueParams";
48 import { IssueListRow } from "./IssueListRow";
49 import type { PullRequestFilterMenu } from "../pull-requests/PullRequestListFilters";
50 import { issueListFiltersAtom } from "./issueListFilters";
51 +import { issueViewMatches } from "./issueSavedViews";
52 +import { SavedViewsMenu } from "../layout/workspace/SavedViewsMenu";
53 import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
54
55 const DEFAULT_ISSUE_LIST_INPUT = { state: "open", involvement: "all", limit: 50 } as const;
@@ -327,6 +329,36 @@ export function IssuesScreen(
329 : FILTER_ROW_STYLE
330 }
331 >
332 + <SavedViewsMenu
333 + read={(preferences) => preferences.issueSavedViews}
334 + write={(issueSavedViews) => ({ issueSavedViews })}
335 + noun="issue"
336 + shortNoun="issue"
337 + suggestedName={involvement === "assigned" ? "Issues Assigned to Me" : ""}
338 + matches={issueViewMatches}
339 + scope={{
340 + query: tab.searchMode === "resting" ? "" : tab.query,
341 + state,
342 + involvement,
343 + sort,
344 + labels,
345 + assignee,
346 + }}
347 + onApply={(view) => {
348 + setState(view.state);
349 + setInvolvement(view.involvement);
350 + setSort(view.sort);
351 + setFilters({ labels: view.labels, assignee: view.assignee });
352 + const viewQuery = view.query.trim();
353 + workspace.dispatch(
354 + viewQuery
355 + ? { type: "search", tab: "issues" }
356 + : { type: "cancel", tab: "issues", scrollToTop: true },
357 + );
358 + workspace.dispatch({ type: "query", tab: "issues", query: viewQuery });
359 + scrollToTop();
360 + }}
361 + />
362 <ListFilterMenu
363 label={STATES[state]}
364 active={state !== "open"}
apps/mobile/src/features/issues/issueSavedViews.ts new
+16
@@ -0,0 +1,16 @@
1 +import type { IssueSavedView } from "../../persistence/mobile-preferences";
2 +
3 +export type IssueSavedViewScope = Omit<IssueSavedView, "id" | "name">;
4 +
5 +export function issueViewMatches(view: IssueSavedViewScope, scope: IssueSavedViewScope) {
6 + const key = (value: IssueSavedViewScope) =>
7 + JSON.stringify([
8 + value.query.trim(),
9 + value.state,
10 + value.involvement,
11 + value.sort,
12 + [...value.labels].sort(),
13 + value.assignee?.login ?? null,
14 + ]);
15 + return key(view) === key(scope);
16 +}
apps/mobile/src/features/layout/workspace/SavedViewsMenu.tsx renamed
+58 -31
@@ -1,69 +1,96 @@
1 -import { pullRequestViewNameError } from "@t3tools/client-runtime/pull-request-saved-views";
1 +import { useAtomSet, useAtomValue } from "@effect/atom-react";
2 +import {
3 + type SavedViewIdentity as SavedViewIdentitySchema,
4 + savedViewNameError,
5 +} from "@t3tools/client-runtime/saved-views";
6 +import { AsyncResult } from "effect/reactivity";
7 import { useState } from "react";
8 import { Alert } from "react-native";
9
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";
10 +import { prompt as showTextInputDialog } from "../../../components/ui/Dialog";
11 +import type { MenuProps } from "../../../components/ui/Menu.types";
12 +import { uuidv4 } from "../../../lib/uuid";
13 +import type { Preferences } from "../../../persistence/mobile-preferences";
14 +import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../../state/preferences";
15 +import { ListFilterMenu } from "./ListFilterMenu";
16
13 -export function PullRequestSavedViewsMenu({
17 +type SavedViewIdentity = typeof SavedViewIdentitySchema.Type;
18 +const EMPTY_SAVED_VIEWS: ReadonlyArray<never> = [];
19 +
20 +export function SavedViewsMenu<Scope extends object>({
21 + read,
22 + write,
23 + noun,
24 + shortNoun,
25 + suggestedName,
26 scope,
27 + matches,
28 onApply,
29 }: {
17 - scope: PullRequestSavedViewScope;
18 - onApply: (view: PullRequestSavedView) => Promise<void>;
30 + read: (preferences: Preferences) => ReadonlyArray<Scope & SavedViewIdentity> | undefined;
31 + write: (views: ReadonlyArray<Scope & SavedViewIdentity>) => Partial<Preferences>;
32 + /** "pull request" in the menu's label, "PR" in its dialogs. */
33 + noun: string;
34 + shortNoun: string;
35 + suggestedName: string;
36 + scope: Scope;
37 + matches: (view: Scope, scope: Scope) => boolean;
38 + onApply: (view: Scope & SavedViewIdentity) => Promise<void> | void;
39 }) {
20 - const { views, ready, update } = usePullRequestSavedViews();
40 + type View = Scope & SavedViewIdentity;
41 + const preferences = useAtomValue(mobilePreferencesAtom);
42 + const savePreferences = useAtomSet(updateMobilePreferencesAtom, { mode: "promise" });
43 + const ready = AsyncResult.isSuccess(preferences) && !preferences.waiting;
44 + const views: ReadonlyArray<View> = AsyncResult.isSuccess(preferences)
45 + ? (read(preferences.value) ?? EMPTY_SAVED_VIEWS)
46 + : EMPTY_SAVED_VIEWS;
47 const [selectedId, setSelectedId] = useState<string | null>(null);
48 const [busy, setBusy] = useState(false);
49 const selectedView =
24 - views.find((view) => view.id === selectedId) ??
25 - views.find((view) => pullRequestViewMatches(view, scope));
50 + views.find((view) => view.id === selectedId) ?? views.find((view) => matches(view, scope));
51 if (selectedId === null && selectedView) setSelectedId(selectedView.id);
27 - const modified = selectedView !== undefined && !pullRequestViewMatches(selectedView, scope);
52 + const modified = selectedView !== undefined && !matches(selectedView, scope);
53
54 // These avoid `finally`, which the React Compiler cannot lower; every path clears `busy`.
30 - async function applyView(view: PullRequestSavedView) {
55 + async function applyView(view: View) {
56 setBusy(true);
57 try {
58 await onApply(view);
59 setSelectedId(view.id);
60 } catch {
36 - Alert.alert("Could not apply PR view", "The device could not save your filters. Try again.");
61 + Alert.alert(
62 + `Could not apply ${shortNoun} view`,
63 + "The device could not save your filters. Try again.",
64 + );
65 }
66 setBusy(false);
67 }
68
41 - async function persist(
42 - transform: (
43 - current: ReadonlyArray<PullRequestSavedView>,
44 - ) => ReadonlyArray<PullRequestSavedView>,
45 - ) {
69 + async function persist(transform: (current: ReadonlyArray<View>) => ReadonlyArray<View>) {
70 setBusy(true);
71 let saved = true;
72 try {
49 - await update(transform);
73 + await savePreferences({
74 + transform: (current) => write(transform(read(current) ?? EMPTY_SAVED_VIEWS)),
75 + });
76 } catch {
51 - Alert.alert("Could not save PR views", "The device could not save your views. Try again.");
77 + Alert.alert(
78 + `Could not save ${shortNoun} views`,
79 + "The device could not save your views. Try again.",
80 + );
81 saved = false;
82 }
83 setBusy(false);
84 return saved;
85 }
86
58 - function editName(view?: PullRequestSavedView) {
87 + function editName(view?: View) {
88 showTextInputDialog({
60 - title: view ? "Rename PR view" : "Save PR view",
61 - initialValue:
62 - view?.name ??
63 - (scope.controls.involvement === "reviewing" ? "PRs Requesting My Review" : ""),
89 + title: view ? `Rename ${shortNoun} view` : `Save ${shortNoun} view`,
90 + initialValue: view?.name ?? suggestedName,
91 confirmText: "Save",
92 onConfirm: (value) => {
66 - const error = pullRequestViewNameError(value, views, view?.id);
93 + const error = savedViewNameError(value, views, view?.id);
94 if (error) {
95 Alert.alert("Could not save view", error);
96 return;
@@ -101,7 +128,7 @@ export function PullRequestSavedViewsMenu({
128 <ListFilterMenu
129 label={selectedView ? `${selectedView.name}${modified ? " *" : ""}` : "Views"}
130 active={selectedView !== undefined}
104 - accessibilityLabel="Saved pull request views"
131 + accessibilityLabel={`Saved ${noun} views`}
132 actions={actions.map((action) => ({
133 ...action,
134 attributes: { ...action.attributes, disabled: !ready || busy },
apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+11 -2
@@ -29,7 +29,8 @@ import {
29 usePullRequestListFilters,
30 type PullRequestFilterMenu,
31 } from "./PullRequestListFilters";
32 -import { PullRequestSavedViewsMenu } from "./PullRequestSavedViewsMenu";
32 +import { SavedViewsMenu } from "../layout/workspace/SavedViewsMenu";
33 +import { pullRequestViewMatches } from "./pullRequestSavedViews";
34 import { usePullRequestList } from "./usePullRequestList";
35 import { usePullRequestListControls } from "./usePullRequestListControls";
36 import { usePullRequestListActions } from "./usePullRequestListActions";
@@ -323,7 +324,15 @@ export function PullRequestsScreen(
324 <PullRequestListFilters
325 sidebar={sidebar}
326 savedViewsMenu={
326 - <PullRequestSavedViewsMenu
327 + <SavedViewsMenu
328 + read={(preferences) => preferences.pullRequestSavedViews}
329 + write={(pullRequestSavedViews) => ({ pullRequestSavedViews })}
330 + noun="pull request"
331 + shortNoun="PR"
332 + suggestedName={
333 + controls.involvement === "reviewing" ? "PRs Requesting My Review" : ""
334 + }
335 + matches={pullRequestViewMatches}
336 scope={{
337 environmentId,
338 controls,
apps/mobile/src/features/pull-requests/pullRequestSavedViews.ts
+1 -1
@@ -6,7 +6,7 @@ export type PullRequestSavedViewScope = Pick<
6 >;
7
8 export function pullRequestViewMatches(
9 - view: PullRequestSavedView,
9 + view: PullRequestSavedViewScope,
10 scope: PullRequestSavedViewScope,
11 ) {
12 const key = ({ environmentId, controls, query }: PullRequestSavedViewScope) =>
apps/mobile/src/features/pull-requests/usePullRequestListControls.ts
-22
@@ -45,28 +45,6 @@ export function usePullRequestListControls() {
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 -
48 function withEnvironmentControls(
49 saved: Readonly<Record<string, PullRequestListControls>> | undefined,
50 environment: string,
apps/mobile/src/lib/storage.test.ts
+13 -1
@@ -152,7 +152,7 @@ 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 () => {
155 + it("discards malformed saved PR and issue views without discarding other preferences", async () => {
156 const validView = {
157 id: "reviewing",
158 name: "Review queue",
@@ -160,6 +160,16 @@ describe("mobile connection storage", () => {
160 query: "bug",
161 controls: { state: "open", involvement: "reviewing", filters: {}, sort: "updated" },
162 } as const;
163 + const validIssueView = {
164 + id: "assigned",
165 + name: "Assigned",
166 + query: "",
167 + state: "open",
168 + involvement: "assigned",
169 + sort: "updated",
170 + labels: ["bug"],
171 + assignee: { login: "octocat", name: null },
172 + } as const;
173 mocks.setPreferencesJson(
174 JSON.stringify({
175 baseFontSize: 17,
@@ -172,12 +182,14 @@ describe("mobile connection storage", () => {
182 controls: { ...validView.controls, sort: "unknown" },
183 },
184 ],
185 + issueSavedViews: [validIssueView, { ...validIssueView, id: "invalid", involvement: "x" }],
186 }),
187 10,
188 );
189 expect(await loadPreferences()).toEqual({
190 baseFontSize: 17,
191 pullRequestSavedViews: [validView],
192 + issueSavedViews: [validIssueView],
193 });
194 });
195
apps/mobile/src/persistence/mobile-preferences.ts
+24 -2
@@ -5,9 +5,12 @@ 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";
8 +import { SavedViewIdentity } from "@t3tools/client-runtime/saved-views";
9 import {
10 EnvironmentId,
11 + IssueInvolvement,
12 + IssueListSort,
13 + IssueListState,
14 PullRequestInvolvement,
15 PullRequestListFilters,
16 PullRequestListState,
@@ -40,7 +43,7 @@ export const PullRequestListControls = Schema.Struct({
43 export type PullRequestListControls = typeof PullRequestListControls.Type;
44
45 export const PullRequestSavedView = Schema.Struct({
43 - ...PullRequestSavedViewIdentity.fields,
46 + ...SavedViewIdentity.fields,
47 environmentId: Schema.NullOr(Schema.String),
48 controls: PullRequestListControls,
49 query: Schema.String,
@@ -48,6 +51,20 @@ export const PullRequestSavedView = Schema.Struct({
51 export type PullRequestSavedView = typeof PullRequestSavedView.Type;
52 const isPullRequestSavedView = Schema.is(PullRequestSavedView);
53
54 +export const IssueSavedView = Schema.Struct({
55 + ...SavedViewIdentity.fields,
56 + query: Schema.String,
57 + state: IssueListState,
58 + involvement: IssueInvolvement,
59 + sort: IssueListSort,
60 + labels: Schema.Array(Schema.String),
61 + assignee: Schema.NullOr(
62 + Schema.Struct({ login: Schema.String, name: Schema.NullOr(Schema.String) }),
63 + ),
64 +});
65 +export type IssueSavedView = typeof IssueSavedView.Type;
66 +const isIssueSavedView = Schema.is(IssueSavedView);
67 +
68 const ThreadListFilters = Schema.Struct({
69 environmentId: Schema.NullOr(EnvironmentId),
70 projectKey: Schema.NullOr(Schema.String),
@@ -165,6 +182,7 @@ export interface Preferences {
182 readonly pullRequestListFilters?: PullRequestListPreferences;
183 readonly workspaceSelections?: WorkspaceSelections;
184 readonly pullRequestSavedViews?: ReadonlyArray<PullRequestSavedView>;
185 + readonly issueSavedViews?: ReadonlyArray<IssueSavedView>;
186 }
187
188 export class MobilePreferencesLoadError extends Schema.TaggedError<MobilePreferencesLoadError>()(
@@ -251,6 +269,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
269 pullRequestListFilters?: PullRequestListPreferences;
270 workspaceSelections?: WorkspaceSelections;
271 pullRequestSavedViews?: ReadonlyArray<PullRequestSavedView>;
272 + issueSavedViews?: ReadonlyArray<IssueSavedView>;
273 } = {};
274
275 if (Array.isArray(parsed.hiddenNavigationTabs)) {
@@ -413,6 +432,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
432 if (Array.isArray(parsed.pullRequestSavedViews)) {
433 preferences.pullRequestSavedViews = parsed.pullRequestSavedViews.filter(isPullRequestSavedView);
434 }
435 + if (Array.isArray(parsed.issueSavedViews)) {
436 + preferences.issueSavedViews = parsed.issueSavedViews.filter(isIssueSavedView);
437 + }
438 return preferences;
439 }
440
apps/web/src/components/SavedViewsMenu.browser.test.tsx renamed
+10 -8
@@ -1,12 +1,14 @@
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";
3 +import { act, render, type Screen } from "../../test/render";
4 +import type { PullRequestListPreferences } from "./pullRequest/pullRequestListPreferences";
5 +import { PULL_REQUEST_SAVED_VIEWS } from "./pullRequest/pullRequestSavedViews";
6 +import { SavedViewsMenu, type SavedView } from "./SavedViewsMenu";
7 +
8 +const PULL_REQUEST_SAVED_VIEWS_KEY = PULL_REQUEST_SAVED_VIEWS.storageKey;
9
10 const { toastAdd } = vi.hoisted(() => ({ toastAdd: vi.fn() }));
9 -vi.mock("../ui/toast", () => ({ toastManager: { add: toastAdd } }));
11 +vi.mock("./ui/toast", () => ({ toastManager: { add: toastAdd } }));
12
13 const reviewing = {
14 involvement: "reviewing",
@@ -23,7 +25,7 @@ function setup() {
25 return {
26 onApply,
27 menu: (preferences: PullRequestListPreferences = reviewing) => (
26 - <PullRequestSavedViewsMenu preferences={preferences} onApply={onApply} />
28 + <SavedViewsMenu kind={PULL_REQUEST_SAVED_VIEWS} preferences={preferences} onApply={onApply} />
29 ),
30 [Symbol.dispose]() {
31 localStorage.clear();
@@ -64,11 +66,11 @@ async function submit() {
66 );
67 }
68
67 -function storedViews(): ReadonlyArray<PullRequestSavedView> {
69 +function storedViews(): ReadonlyArray<SavedView<PullRequestListPreferences>> {
70 return JSON.parse(localStorage.getItem(PULL_REQUEST_SAVED_VIEWS_KEY) ?? "[]");
71 }
72
71 -describe("PullRequestSavedViewsMenu", () => {
73 +describe("SavedViewsMenu", () => {
74 it("saves a named filter setup and restores it after remounting", async () => {
75 using fixture = setup();
76 const { menu } = fixture;
apps/web/src/components/SavedViewsMenu.tsx renamed
+61 -53
@@ -1,13 +1,14 @@
1 import { BookmarkIcon, CheckIcon, ChevronDownIcon, PlusIcon } from "lucide-react";
2 import { useId, useState } from "react";
3 +import type * as Schema from "effect/Schema";
4 import {
4 - PULL_REQUEST_VIEW_NAME_MAX_LENGTH,
5 - pullRequestViewNameError,
6 -} from "@t3tools/client-runtime/pull-request-saved-views";
5 + SAVED_VIEW_NAME_MAX_LENGTH,
6 + savedViewNameError,
7 +} from "@t3tools/client-runtime/saved-views";
8
8 -import { getLocalStorageItem, useLocalStorage } from "../../hooks/useLocalStorage";
9 -import { randomUUID } from "../../lib/utils";
10 -import { Button } from "../ui/button";
9 +import { getLocalStorageItem, useLocalStorage } from "../hooks/useLocalStorage";
10 +import { randomUUID } from "../lib/utils";
11 +import { Button } from "./ui/button";
12 import {
13 Dialog,
14 DialogDescription,
@@ -16,51 +17,62 @@ import {
17 DialogPanel,
18 DialogPopup,
19 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";
20 +} from "./ui/dialog";
21 +import { Input } from "./ui/input";
22 +import { Label } from "./ui/label";
23 +import { Menu, MenuItem, MenuItemLabel, MenuPopup, MenuSeparator, MenuTrigger } from "./ui/menu";
24 +import { toastManager } from "./ui/toast";
25 +import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
26
37 -export function PullRequestSavedViewsMenu({
27 +export interface SavedView<Preferences> {
28 + readonly id: string;
29 + readonly name: string;
30 + readonly preferences: Preferences;
31 +}
32 +
33 +/**
34 + * What one list (pull requests, issues) stores and how it compares its list controls. `Stored`
35 + * is the schema's decoded shape, which may spell absent fields as `undefined`.
36 + */
37 +export interface SavedViewsKind<Preferences extends Stored, Stored, Encoded> {
38 + readonly storageKey: string;
39 + readonly schema: Schema.Codec<ReadonlyArray<SavedView<Stored>>, Encoded>;
40 + readonly empty: ReadonlyArray<SavedView<Stored>>;
41 + /** "pull request" in the menu's label, "PR" in the dialog and errors. */
42 + readonly noun: string;
43 + readonly shortNoun: string;
44 + readonly placeholder: string;
45 + readonly suggestedName: (preferences: Preferences) => string;
46 + /** Drops the parts of the list state that a view does not keep. */
47 + readonly normalize: (preferences: Stored) => Preferences;
48 + readonly matches: (view: SavedView<Stored>, preferences: Preferences) => boolean;
49 +}
50 +
51 +export function SavedViewsMenu<Preferences extends Stored, Stored, Encoded>({
52 + kind,
53 preferences,
54 onApply,
55 }: {
41 - preferences: PullRequestListPreferences;
42 - onApply: (preferences: PullRequestListPreferences) => void;
56 + kind: SavedViewsKind<Preferences, Stored, Encoded>;
57 + preferences: Preferences;
58 + onApply: (preferences: Preferences) => void;
59 }) {
44 - const [views, setViews] = useLocalStorage(
45 - PULL_REQUEST_SAVED_VIEWS_KEY,
46 - EMPTY_PULL_REQUEST_SAVED_VIEWS,
47 - PullRequestSavedViews,
48 - );
60 + const [views, setViews] = useLocalStorage(kind.storageKey, kind.empty, kind.schema);
61 const [selectedId, setSelectedId] = useState<string | null>(null);
62 const [editor, setEditor] = useState<{ id?: string; name: string } | null>(null);
63 const inputId = useId();
64 const errorId = useId();
65 const selectedView =
66 views.find((view) => view.id === selectedId) ??
55 - views.find((view) => pullRequestViewMatches(view, preferences));
67 + views.find((view) => kind.matches(view, preferences));
68 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;
69 + const modified = selectedView !== undefined && !kind.matches(selectedView, preferences);
70 + const nameError = editor ? savedViewNameError(editor.name, views, editor.id) : null;
71
72 function persist(
61 - update: (current: ReadonlyArray<PullRequestSavedView>) => ReadonlyArray<PullRequestSavedView>,
73 + update: (current: ReadonlyArray<SavedView<Stored>>) => ReadonlyArray<SavedView<Stored>>,
74 ) {
63 - let written: ReadonlyArray<PullRequestSavedView> | undefined;
75 + let written: ReadonlyArray<SavedView<Stored>> | undefined;
76 setViews((current) => {
77 written = update(current);
78 return written;
@@ -69,7 +81,7 @@ export function PullRequestSavedViewsMenu({
81 try {
82 if (
83 written &&
72 - JSON.stringify(getLocalStorageItem(PULL_REQUEST_SAVED_VIEWS_KEY, PullRequestSavedViews)) ===
84 + JSON.stringify(getLocalStorageItem(kind.storageKey, kind.schema)) ===
85 JSON.stringify(written)
86 ) {
87 return true;
@@ -79,7 +91,7 @@ export function PullRequestSavedViewsMenu({
91 }
92 toastManager.add({
93 type: "error",
82 - title: "Could not save PR views",
94 + title: `Could not save ${kind.shortNoun} views`,
95 description:
96 "Local storage is unavailable or full. Try again after freeing space or allowing storage.",
97 });
@@ -99,7 +111,7 @@ export function PullRequestSavedViewsMenu({
111 }
112 return editingId
113 ? current.map((view) => (view.id === editingId ? { ...view, name } : view))
102 - : [...current, { id, name, preferences: pullRequestListPreferences(preferences) }];
114 + : [...current, { id, name, preferences: kind.normalize(preferences) }];
115 });
116 if (missing) {
117 setEditor((current) => (current ? { name: current.name } : null));
@@ -123,7 +135,7 @@ export function PullRequestSavedViewsMenu({
135 render={
136 <MenuTrigger
137 render={<Button variant="outline" />}
126 - aria-label="Saved pull request views"
138 + aria-label={`Saved ${kind.noun} views`}
139 />
140 }
141 >
@@ -132,7 +144,7 @@ export function PullRequestSavedViewsMenu({
144 {modified ? <span aria-label="Modified view">*</span> : null}
145 <ChevronDownIcon aria-hidden className="size-3 shrink-0" />
146 </TooltipTrigger>
135 - <TooltipPopup>{selectedView?.name ?? "Saved pull request views"}</TooltipPopup>
147 + <TooltipPopup>{selectedView?.name ?? `Saved ${kind.noun} views`}</TooltipPopup>
148 </Tooltip>
149 <MenuPopup align="start">
150 {views.map((view) => (
@@ -142,7 +154,7 @@ export function PullRequestSavedViewsMenu({
154 <MenuItem
155 onClick={() => {
156 setSelectedId(view.id);
145 - onApply(pullRequestListPreferences(view.preferences));
157 + onApply(kind.normalize(view.preferences));
158 }}
159 />
160 }
@@ -158,13 +170,7 @@ export function PullRequestSavedViewsMenu({
170 </Tooltip>
171 ))}
172 {views.length > 0 ? <MenuSeparator /> : null}
161 - <MenuItem
162 - onClick={() =>
163 - setEditor({
164 - name: preferences.involvement === "reviewing" ? "PRs Requesting My Review" : "",
165 - })
166 - }
167 - >
173 + <MenuItem onClick={() => setEditor({ name: kind.suggestedName(preferences) })}>
174 <PlusIcon aria-hidden />
175 Save current view…
176 </MenuItem>
@@ -176,7 +182,7 @@ export function PullRequestSavedViewsMenu({
182 persist((current) =>
183 current.map((view) =>
184 view.id === selectedView.id
179 - ? { ...view, preferences: pullRequestListPreferences(preferences) }
185 + ? { ...view, preferences: kind.normalize(preferences) }
186 : view,
187 ),
188 )
@@ -216,7 +222,9 @@ export function PullRequestSavedViewsMenu({
222 }}
223 >
224 <DialogHeader>
219 - <DialogTitle>{editor?.id ? "Rename PR view" : "Save PR view"}</DialogTitle>
225 + <DialogTitle>
226 + {editor?.id ? `Rename ${kind.shortNoun} view` : `Save ${kind.shortNoun} view`}
227 + </DialogTitle>
228 <DialogDescription>
229 Save your search, filters, and sort order on this device.
230 </DialogDescription>
@@ -228,8 +236,8 @@ export function PullRequestSavedViewsMenu({
236 id={inputId}
237 autoFocus
238 value={editor?.name ?? ""}
231 - maxLength={PULL_REQUEST_VIEW_NAME_MAX_LENGTH}
232 - placeholder="PRs Requesting My Review"
239 + maxLength={SAVED_VIEW_NAME_MAX_LENGTH}
240 + placeholder={kind.placeholder}
241 aria-invalid={Boolean(editor?.name && nameError)}
242 aria-describedby={nameError && editor?.name ? errorId : undefined}
243 onChange={(event) =>
apps/web/src/components/issue/IssuesPage.tsx
+18
@@ -51,6 +51,8 @@ import {
51 type PullRequestFilterOption,
52 } from "~/components/pullRequest/PullRequestListFilters";
53 import { IssueFiltersMenu } from "./IssueListFilterPickers";
54 +import { ISSUE_SAVED_VIEWS } from "./issueSavedViews";
55 +import { SavedViewsMenu } from "~/components/SavedViewsMenu";
56 import { PullRequestCompactFilterMenu } from "../pullRequest/PullRequestCompactFilterMenu";
57 import { PullRequestsUnavailableState } from "~/components/pullRequest/PullRequestsUnavailableState";
58 import { RightPanelTabs } from "~/components/RightPanelTabs";
@@ -578,6 +580,22 @@ export function IssuesPage() {
580 assignee={search.assignee}
581 onAssignee={(assignee) => updateSearch({ assignee })}
582 />
583 + <SavedViewsMenu
584 + kind={ISSUE_SAVED_VIEWS}
585 + preferences={search}
586 + onApply={(view) =>
587 + // Explicit clears replace the old list scope; the selected issue stays open.
588 + updateSearch({
589 + who: view.who,
590 + status: view.status,
591 + host: view.host,
592 + q: view.q,
593 + label: view.label,
594 + assignee: view.assignee,
595 + order: view.order,
596 + })
597 + }
598 + />
599 {hostOptions.length > 1 ? (
600 <FilterMenu
601 label="Filter by tracker"
apps/web/src/components/issue/issueListPreferences.ts
+1 -1
@@ -27,7 +27,7 @@ const DEFAULT_ISSUE_LIST_PREFERENCES = {
27 const STORAGE_KEY = "t3.issues.preferences";
28
29 const BoundedPreference = Schema.String.check(Schema.isMaxLength(200));
30 -const IssueListPreferencesSchema = Schema.Struct({
30 +export const IssueListPreferencesSchema = Schema.Struct({
31 who: IssueInvolvement,
32 status: IssueListState,
33 host: Schema.optional(BoundedPreference),
apps/web/src/components/issue/issueSavedViews.test.ts new
+24
@@ -0,0 +1,24 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { issueViewMatches } from "./issueSavedViews";
4 +
5 +const preferences = {
6 + who: "assigned",
7 + status: "open",
8 + host: "github.com",
9 + q: "crash",
10 + label: ["bug", "priority"],
11 + assignee: "octocat",
12 + order: "created",
13 +} as const;
14 +const view = { id: "mine", name: "Issues Assigned to Me", preferences };
15 +
16 +describe("saved issue views", () => {
17 + it("matches regardless of label order", () => {
18 + expect(issueViewMatches(view, { ...preferences, label: ["priority", "bug"], q: "crash" })).toBe(
19 + true,
20 + );
21 + expect(issueViewMatches(view, { ...preferences, assignee: undefined })).toBe(false);
22 + expect(issueViewMatches(view, { ...preferences, label: ["bug"] })).toBe(false);
23 + });
24 +});
apps/web/src/components/issue/issueSavedViews.ts new
+38
@@ -0,0 +1,38 @@
1 +import * as Schema from "effect/Schema";
2 +import { SavedViewIdentity } from "@t3tools/client-runtime/saved-views";
3 +
4 +import type { SavedView, SavedViewsKind } from "../SavedViewsMenu";
5 +import {
6 + issueListPreferences,
7 + IssueListPreferencesSchema,
8 + type IssueListPreferences,
9 +} from "./issueListPreferences";
10 +
11 +export function issueViewMatches(
12 + view: SavedView<typeof IssueListPreferencesSchema.Type>,
13 + preferences: IssueListPreferences,
14 +): boolean {
15 + const key = (value: IssueListPreferences) => {
16 + const normalized = issueListPreferences(value);
17 + return JSON.stringify({ ...normalized, label: normalized.label?.toSorted() });
18 + };
19 + return key(issueListPreferences(view.preferences)) === key(preferences);
20 +}
21 +
22 +export const ISSUE_SAVED_VIEWS = {
23 + storageKey: "t3.issues.savedViews",
24 + schema: Schema.Array(
25 + Schema.Struct({ ...SavedViewIdentity.fields, preferences: IssueListPreferencesSchema }),
26 + ),
27 + empty: [],
28 + noun: "issue",
29 + shortNoun: "issue",
30 + placeholder: "Issues Assigned to Me",
31 + suggestedName: (preferences) => (preferences.who === "assigned" ? "Issues Assigned to Me" : ""),
32 + normalize: issueListPreferences,
33 + matches: issueViewMatches,
34 +} as const satisfies SavedViewsKind<
35 + IssueListPreferences,
36 + typeof IssueListPreferencesSchema.Type,
37 + unknown
38 +>;
apps/web/src/components/pullRequest/PullRequestsPage.tsx
+4 -3
@@ -54,8 +54,8 @@ import {
54 type PullRequestListPreferencePatch,
55 writePullRequestListPreferences,
56 } from "./pullRequestListPreferences";
57 -import { PullRequestSavedViewsMenu } from "./PullRequestSavedViewsMenu";
58 -import { pullRequestSavedViewPatch } from "./pullRequestSavedViews";
57 +import { SavedViewsMenu } from "../SavedViewsMenu";
58 +import { PULL_REQUEST_SAVED_VIEWS, pullRequestSavedViewPatch } from "./pullRequestSavedViews";
59 import { environmentMachineIcon } from "../EnvironmentMachineIcon";
60 import { PullRequestDetailPanel } from "./PullRequestDetailPanel";
61 import {
@@ -1424,7 +1424,8 @@ export function PullRequestsPage() {
1424 sortMenu,
1425 filtersMenu,
1426 savedViewsMenu: (
1427 - <PullRequestSavedViewsMenu
1427 + <SavedViewsMenu
1428 + kind={PULL_REQUEST_SAVED_VIEWS}
1429 preferences={search}
1430 onApply={(preferences) => updateListScope(pullRequestSavedViewPatch(preferences))}
1431 />
apps/web/src/components/pullRequest/pullRequestSavedViews.test.ts
+6 -6
@@ -1,5 +1,5 @@
1 import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2 -import { pullRequestViewNameError } from "@t3tools/client-runtime/pull-request-saved-views";
2 +import { savedViewNameError } from "@t3tools/client-runtime/saved-views";
3 import { describe, expect, it } from "vite-plus/test";
4
5 import {
@@ -78,10 +78,10 @@ describe("saved PR views", () => {
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();
81 + expect(savedViewNameError(" ", [view])).toBeTruthy();
82 + expect(savedViewNameError("x".repeat(81), [view])).toBeTruthy();
83 + expect(savedViewNameError(" PRS REQUESTING MY REVIEW ", [view])).toBeTruthy();
84 + expect(savedViewNameError(view.name, [view], view.id)).toBeNull();
85 + expect(savedViewNameError(" My PRs ", [view])).toBeNull();
86 });
87 });
apps/web/src/components/pullRequest/pullRequestSavedViews.ts
+22 -13
@@ -1,6 +1,7 @@
1 import * as Schema from "effect/Schema";
2 -import { PullRequestSavedViewIdentity } from "@t3tools/client-runtime/pull-request-saved-views";
2 +import { SavedViewIdentity } from "@t3tools/client-runtime/saved-views";
3
4 +import type { SavedView, SavedViewsKind } from "../SavedViewsMenu";
5 import {
6 pullRequestListPreferences,
7 PullRequestListPreferencesSchema,
@@ -8,19 +9,8 @@ import {
9 type PullRequestListPreferences,
10 } from "./pullRequestListPreferences";
11
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 -
12 export function pullRequestViewMatches(
23 - view: PullRequestSavedView,
13 + view: SavedView<typeof PullRequestListPreferencesSchema.Type>,
14 preferences: PullRequestListPreferences,
15 ): boolean {
16 const key = (value: PullRequestListPreferences) => {
@@ -33,6 +23,25 @@ export function pullRequestViewMatches(
23 return key(pullRequestListPreferences(view.preferences)) === key(preferences);
24 }
25
26 +export const PULL_REQUEST_SAVED_VIEWS = {
27 + storageKey: "t3.pullRequests.savedViews",
28 + schema: Schema.Array(
29 + Schema.Struct({ ...SavedViewIdentity.fields, preferences: PullRequestListPreferencesSchema }),
30 + ),
31 + empty: [],
32 + noun: "pull request",
33 + shortNoun: "PR",
34 + placeholder: "PRs Requesting My Review",
35 + suggestedName: (preferences) =>
36 + preferences.involvement === "reviewing" ? "PRs Requesting My Review" : "",
37 + normalize: pullRequestListPreferences,
38 + matches: pullRequestViewMatches,
39 +} as const satisfies SavedViewsKind<
40 + PullRequestListPreferences,
41 + typeof PullRequestListPreferencesSchema.Type,
42 + unknown
43 +>;
44 +
45 /** Explicit clears replace the old list scope without touching the independently selected PR. */
46 export function pullRequestSavedViewPatch(
47 preferences: PullRequestListPreferences,
docs/user/source-control.md
+2
@@ -363,6 +363,8 @@ DevOps or Forgejo, grouped per tracker account. Open it from the sidebar's utili
363 **Open issues** in the command palette. Filter by open or closed, by your involvement
364 (assigned, opened by you, mentioning you), and by tracker; the search box asks the tracker
365 itself where it can search. Press **Load more** at the end of a group to read further back.
366 +The **Views** menu saves and restores a search, filter, and sort setup, as it does for pull
367 +requests.
368
369 To list a Linear team's issues beside a project's, connect Linear with an API key under
370 Settings → Source control & issues, then choose the team for that project there.
packages/client-runtime/package.json
+3 -3
@@ -23,9 +23,9 @@
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"
26 + "./saved-views": {
27 + "types": "./src/savedViews.ts",
28 + "default": "./src/savedViews.ts"
29 },
30 "./composerThreadItems": {
31 "types": "./src/composerThreadItems.ts",
packages/client-runtime/src/pullRequestSavedViews.ts deleted
-28
@@ -1,28 +0,0 @@
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 -}
packages/client-runtime/src/savedViews.ts new
+25
@@ -0,0 +1,25 @@
1 +import * as Schema from "effect/Schema";
2 +
3 +export const SAVED_VIEW_NAME_MAX_LENGTH = 80;
4 +
5 +export const SavedViewIdentity = Schema.Struct({
6 + id: Schema.String.check(Schema.isMinLength(1)),
7 + name: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(SAVED_VIEW_NAME_MAX_LENGTH)),
8 +});
9 +
10 +export function savedViewNameError(
11 + name: string,
12 + views: ReadonlyArray<typeof SavedViewIdentity.Type>,
13 + editingId?: string,
14 +): string | null {
15 + const trimmed = name.trim();
16 + if (!trimmed) return "Enter a name for this view.";
17 + if (trimmed.length > SAVED_VIEW_NAME_MAX_LENGTH) {
18 + return `Use ${SAVED_VIEW_NAME_MAX_LENGTH} characters or fewer.`;
19 + }
20 + return views.some(
21 + (view) => view.id !== editingId && view.name.toLowerCase() === trimmed.toLowerCase(),
22 + )
23 + ? "A view with this name already exists."
24 + : null;
25 +}