Skip to content

Commit 826ca1d

Browse files
fix(web): long searches no longer reset remembered list filters (#45278)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent 7900119 commit 826ca1d

4 files changed

Lines changed: 52 additions & 13 deletions

File tree

‎apps/web/src/components/issue/issueListPreferences.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
IssueListState,
88
ProjectId,
99
} from "@t3tools/contracts";
10+
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
1011

1112
/**
1213
* What the issues page remembers between visits; the selection in the URL is not part of it.
@@ -34,7 +35,11 @@ const DEFAULT_ISSUE_LIST_PREFERENCES = {
3435

3536
const STORAGE_KEY = "t3.issues.preferences";
3637

37-
const BoundedPreference = Schema.String.check(Schema.isMaxLength(200));
38+
const TEXT_MAX = 200;
39+
const LABELS_MAX = 20;
40+
const BoundedPreference = Schema.String.check(Schema.isMaxLength(TEXT_MAX));
41+
const bounded = (value: string) =>
42+
value.slice(0, splitsSurrogatePair(value, TEXT_MAX) ? TEXT_MAX - 1 : TEXT_MAX);
3843
export const IssueListPreferencesSchema = Schema.Struct({
3944
who: IssueInvolvement,
4045
status: IssueListState,
@@ -45,7 +50,7 @@ export const IssueListPreferencesSchema = Schema.Struct({
4550
),
4651
host: Schema.optional(BoundedPreference),
4752
q: Schema.optional(BoundedPreference),
48-
label: Schema.optional(Schema.Array(BoundedPreference).check(Schema.isMaxLength(20))),
53+
label: Schema.optional(Schema.Array(BoundedPreference).check(Schema.isMaxLength(LABELS_MAX))),
4954
assignee: Schema.optional(BoundedPreference),
5055
order: Schema.optional(Schema.Literal("created")),
5156
});
@@ -74,10 +79,10 @@ export function issueListPreferences(search: {
7479
...(search.hideProjects?.length
7580
? { hideProjects: search.hideProjects.slice(0, ISSUE_LIST_MAX_EXCLUDED_PROJECTS) }
7681
: {}),
77-
...(search.host ? { host: search.host } : {}),
78-
...(search.q ? { q: search.q } : {}),
79-
...(search.label?.length ? { label: search.label } : {}),
80-
...(search.assignee ? { assignee: search.assignee } : {}),
82+
...(search.host ? { host: bounded(search.host) } : {}),
83+
...(search.q ? { q: bounded(search.q) } : {}),
84+
...(search.label?.length ? { label: search.label.slice(0, LABELS_MAX).map(bounded) } : {}),
85+
...(search.assignee ? { assignee: bounded(search.assignee) } : {}),
8186
...(search.order ? { order: search.order } : {}),
8287
};
8388
}

‎apps/web/src/components/issue/issueSavedViews.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,15 @@ describe("saved issue views", () => {
4949
const restored = decodePreferences(stored);
5050
expect(restored._tag === "Some" && restored.value.hideProjects).toEqual(many.slice(0, 1_000));
5151
});
52+
53+
// regression: a pasted search over 200 characters reset every remembered filter
54+
it("keeps every filter when long text is remembered", () => {
55+
const [long, kept] = [`${"a".repeat(199)}${"😀".repeat(30)}`, "a".repeat(199)];
56+
const label = Array.from({ length: 21 }, (_, index) => `label-${index}`);
57+
const text = (value: string) => ({ host: value, q: value, assignee: value });
58+
const stored = issueListPreferences({ ...preferences, ...text(long), label: [long, ...label] });
59+
const restored = decodePreferences(stored);
60+
const expected = { ...preferences, ...text(kept), label: [kept, ...label.slice(0, 19)] };
61+
expect(restored._tag === "Some" && restored.value).toEqual(expected);
62+
});
5263
});

‎apps/web/src/components/pullRequest/pullRequestList.logic.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,24 @@ describe("remembered pull request list controls", () => {
484484
expect(readPullRequestListPreferences(storage)).toEqual({ involvement: "all", state: "open" });
485485
});
486486

487+
// regression: a pasted search over 200 characters reset every remembered control
488+
it("keeps every control when long text is remembered", () => {
489+
const storage = makeStorage();
490+
const [long, kept] = [`${"a".repeat(199)}${"😀".repeat(30)}`, "a".repeat(199)];
491+
const labels = Array.from({ length: 11 }, (_, index) => `label-${index}`);
492+
const text = (value: string) => ({ host: value, q: value, author: value });
493+
const controls = { involvement: "authored", state: "merged" } as const;
494+
writePullRequestListPreferences(
495+
{ ...controls, ...text(long), labels: [long, ...labels] },
496+
storage,
497+
);
498+
expect(readPullRequestListPreferences(storage)).toEqual({
499+
...controls,
500+
...text(kept),
501+
labels: [kept, ...labels.slice(0, 9)],
502+
});
503+
});
504+
487505
it("falls back when browser policy denies storage", () => {
488506
const denied = {
489507
getItem: () => {

‎apps/web/src/components/pullRequest/pullRequestListPreferences.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PullRequestListFilters,
88
PullRequestListState,
99
} from "@t3tools/contracts";
10+
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
1011

1112
export const PullRequestListSort = Schema.Literals([
1213
"ready",
@@ -43,7 +44,11 @@ const DEFAULT_PULL_REQUEST_LIST_PREFERENCES = {
4344
state: "open",
4445
} as const satisfies PullRequestListPreferences;
4546

46-
const BoundedPreference = Schema.String.check(Schema.isMaxLength(200));
47+
const TEXT_MAX = 200;
48+
const LABELS_MAX = 10;
49+
const BoundedPreference = Schema.String.check(Schema.isMaxLength(TEXT_MAX));
50+
const bounded = (value: string) =>
51+
value.slice(0, splitsSurrogatePair(value, TEXT_MAX) ? TEXT_MAX - 1 : TEXT_MAX);
4752
export const PullRequestListPreferencesSchema = Schema.Struct({
4853
involvement: PullRequestInvolvement,
4954
state: PullRequestListState,
@@ -55,7 +60,7 @@ export const PullRequestListPreferencesSchema = Schema.Struct({
5560
review: PullRequestListFilters.fields.review,
5661
checks: PullRequestListFilters.fields.checks,
5762
author: Schema.optional(BoundedPreference),
58-
labels: Schema.optional(Schema.Array(BoundedPreference).check(Schema.isMaxLength(10))),
63+
labels: Schema.optional(Schema.Array(BoundedPreference).check(Schema.isMaxLength(LABELS_MAX))),
5964
sort: Schema.optional(PullRequestListSort),
6065
});
6166

@@ -79,13 +84,13 @@ export function pullRequestListPreferences(
7984
state: search.state,
8085
...(search.environmentId ? { environmentId: search.environmentId } : {}),
8186
...(search.projectId ? { projectId: search.projectId } : {}),
82-
...(search.host ? { host: search.host } : {}),
83-
...(search.q ? { q: search.q } : {}),
87+
...(search.host ? { host: bounded(search.host) } : {}),
88+
...(search.q ? { q: bounded(search.q) } : {}),
8489
...(search.draft ? { draft: search.draft } : {}),
8590
...(search.review ? { review: search.review } : {}),
8691
...(search.checks ? { checks: search.checks } : {}),
87-
...(search.author ? { author: search.author } : {}),
88-
...(search.labels && search.labels.length > 0 ? { labels: search.labels } : {}),
92+
...(search.author ? { author: bounded(search.author) } : {}),
93+
...(search.labels?.length ? { labels: search.labels.slice(0, LABELS_MAX).map(bounded) } : {}),
8994
...(search.sort && search.sort !== "ready" ? { sort: search.sort } : {}),
9095
};
9196
}
@@ -114,7 +119,7 @@ export function writePullRequestListPreferences(
114119
try {
115120
resolvePreferenceStorage(storage)?.setItem(
116121
PULL_REQUEST_LIST_PREFERENCES_STORAGE_KEY,
117-
JSON.stringify(preferences),
122+
JSON.stringify(pullRequestListPreferences(preferences)),
118123
);
119124
} catch {}
120125
}

0 commit comments

Comments
 (0)