Skip to content

Commit 789c30b

Browse files
fix(pull-requests): filter searches say when they fail and keep room for the host
- A failed host search said nothing matched; web and mobile pickers now say the search failed. - While the search waited out its debounce, the host's answers to the previous text stayed listed under the new text; they are held back until the search catches up. - Loaded matches could fill the capped list and push out every host answer; the host's answers now follow the first half of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cda5a7c commit 789c30b

7 files changed

Lines changed: 67 additions & 14 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestFilterSearchScreen.tsx‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const optionsFamily = Atom.family((key: string) => {
4242
return {
4343
values: results.flatMap((result) => Option.toArray(AsyncResult.value(result))),
4444
waiting: results.some((result) => result.waiting),
45+
failed: results.some(AsyncResult.isFailure),
4546
};
4647
});
4748
});
@@ -54,7 +55,10 @@ export function PullRequestFilterSearchScreen({
5455
const listControls = usePullRequestListControls();
5556
const controls = listControls.controlsFor(environmentId);
5657
const [query, setQuery] = useState("");
57-
const sent = useDebouncedValue(query.trim().slice(0, 100), 250);
58+
const typed = query.trim().slice(0, 100);
59+
const sent = useDebouncedValue(typed, 250);
60+
// Until the search catches up with the typing, the host's answers are for older text.
61+
const settled = sent === typed;
5862
const key = JSON.stringify(
5963
environmentIds.map((id) => ({
6064
environmentId: EnvironmentId.make(id),
@@ -72,7 +76,7 @@ export function PullRequestFilterSearchScreen({
7276
const rows = pullRequestFilterChoices({
7377
selected,
7478
suggestions,
75-
hosted: hosted.values.flatMap((options) =>
79+
hosted: (settled ? hosted.values : []).flatMap((options) =>
7680
kind === "labels"
7781
? options.labels.map((label) => label.name)
7882
: options.authors.map((candidate) => candidate.login),
@@ -167,16 +171,24 @@ export function PullRequestFilterSearchScreen({
167171
</Pressable>
168172
)}
169173
ListEmptyComponent={
170-
hosted.waiting ? (
174+
hosted.waiting || !settled ? (
171175
<AppActivityIndicator className="my-8" />
172176
) : (
173177
<View className="px-4 py-6">
174178
<EmptyState
175-
title={kind === "labels" ? "No matching labels" : "No matching authors"}
179+
title={
180+
hosted.failed
181+
? "Couldn't search the host"
182+
: kind === "labels"
183+
? "No matching labels"
184+
: "No matching authors"
185+
}
176186
detail={
177-
kind === "labels"
178-
? "Search the labels of the repositories this list covers."
179-
: "Search people by name or handle on the repositories' hosts."
187+
hosted.failed
188+
? "The host didn't answer. Try again in a moment."
189+
: kind === "labels"
190+
? "Search the labels of the repositories this list covers."
191+
: "Search people by name or handle on the repositories' hosts."
180192
}
181193
variant="plain"
182194
/>

‎apps/mobile/src/features/pull-requests/pullRequestList.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,16 @@ describe("pullRequestFilterChoices", () => {
359359
}),
360360
).toEqual(["size:XL", "bug", "backend"]);
361361
});
362+
363+
it("leaves room for the host's answers when loaded matches alone would fill the list", () => {
364+
const loaded = Array.from({ length: 120 }, (_, index) => `label-${index}`);
365+
const rows = pullRequestFilterChoices({
366+
selected: [],
367+
suggestions: loaded,
368+
hosted: ["label-from-host"],
369+
query: "label",
370+
});
371+
expect(rows).toHaveLength(100);
372+
expect(rows[50]).toBe("label-from-host");
373+
});
362374
});

‎apps/mobile/src/features/pull-requests/pullRequestList.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ export function appendPullRequestListPage(
189189
* then the host's answers, each once. The host matched its own way (an author's display name, say),
190190
* so its answers are not narrowed again here.
191191
*/
192+
const FILTER_CHOICE_LIMIT = 100;
193+
192194
export function pullRequestFilterChoices(input: {
193195
readonly selected: readonly string[];
194196
readonly suggestions: readonly string[];
@@ -204,10 +206,13 @@ export function pullRequestFilterChoices(input: {
204206
seen.add(key);
205207
rows.push(value);
206208
};
209+
const loaded = input.suggestions.filter((value) => value.toLowerCase().includes(needle));
207210
for (const value of input.selected) add(value);
208-
for (const value of input.suggestions) if (value.toLowerCase().includes(needle)) add(value);
211+
// Loaded matches alone could fill the list, so the host's answers get room after the first half.
212+
for (const value of loaded.slice(0, FILTER_CHOICE_LIMIT / 2)) add(value);
209213
for (const value of input.hosted) add(value);
210-
return rows.slice(0, 100);
214+
for (const value of loaded.slice(FILTER_CHOICE_LIMIT / 2)) add(value);
215+
return rows.slice(0, FILTER_CHOICE_LIMIT);
211216
}
212217

213218
export function pullRequestListFacets(entries: readonly PullRequestListEntry[]) {

‎apps/web/src/components/pullRequest/PullRequestListFilters.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,16 @@ function useHostedFilterOptions(
250250
kind: PullRequestFilterOptionsInput["kind"],
251251
query: string,
252252
) {
253-
const sent = useDebouncedValue(query.trim().slice(0, 100), OPTION_SEARCH_DEBOUNCE_MS);
254-
return usePullRequestFilterOptions(
253+
const typed = query.trim().slice(0, 100);
254+
const sent = useDebouncedValue(typed, OPTION_SEARCH_DEBOUNCE_MS);
255+
const hosted = usePullRequestFilterOptions(
255256
scope.map(({ environmentId, input }) => ({
256257
environmentId,
257258
input: { ...input, kind, ...(sent ? { query: sent } : {}) },
258259
})),
259260
);
261+
// Until the search catches up with the typing, the host's answers are for older text.
262+
return sent === typed ? hosted : { labels: [], authors: [], error: null, isPending: true };
260263
}
261264

262265
function PullRequestOptionSearch({
@@ -343,7 +346,9 @@ function PullRequestAuthorChoices({
343346
</MenuRadioItem>
344347
))}
345348
{visible.length === 0 && !hosted.isPending ? (
346-
<MenuItem disabled>No authors found</MenuItem>
349+
<MenuItem disabled>
350+
{hosted.error === null ? "No authors found" : "Couldn't search authors on the host"}
351+
</MenuItem>
347352
) : null}
348353
</MenuRadioGroup>
349354
</>
@@ -412,7 +417,9 @@ function PullRequestLabelChoices({
412417
onChange={setQuery}
413418
/>
414419
{visible.length === 0 && !hosted.isPending ? (
415-
<MenuItem disabled>No labels found</MenuItem>
420+
<MenuItem disabled>
421+
{hosted.error === null ? "No labels found" : "Couldn't search labels on the host"}
422+
</MenuItem>
416423
) : null}
417424
{visible.map((option) => {
418425
const key = option.name.toLowerCase();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,18 @@ describe("filter picker choices", () => {
852852
expect(selectedPullRequestAuthor(loaded, hosted, undefined)).toBeUndefined();
853853
});
854854

855+
it("puts the host's authors after the first loaded matches rather than after all of them", () => {
856+
const loaded = Array.from({ length: 40 }, (_, index) => ({
857+
actor: actor(`dev-${index}`),
858+
count: 1,
859+
mergedCount: 0,
860+
}));
861+
862+
const choices = pullRequestAuthorChoices(loaded, [actor("dev-from-host")], "dev");
863+
864+
expect(choices.slice(0, 30).map((choice) => choice.actor.login)).toContain("dev-from-host");
865+
});
866+
855867
it("keeps a loaded label's count when only the host's search found it", () => {
856868
const loaded = [{ name: "size:XL", color: "d93f0b", count: 7 }];
857869

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export function collectPullRequestListFacets(
134134
* then whatever the host found that no loaded row carries, so a name nobody has loaded yet is
135135
* still one search away.
136136
*/
137+
/** How many loaded matches come before the host's answers. */
138+
const HOSTED_CHOICE_ROOM = 15;
139+
137140
export function pullRequestAuthorChoices(
138141
facets: ReadonlyArray<PullRequestAuthorFacet>,
139142
hosted: ReadonlyArray<PullRequestActor>,
@@ -155,7 +158,8 @@ export function pullRequestAuthorChoices(
155158
seen.add(key);
156159
added.push(known.get(key) ?? { actor, count: 0, mergedCount: 0 });
157160
}
158-
return [...loaded, ...added];
161+
// The picker shows a short list, and loaded matches alone could fill it.
162+
return [...loaded.slice(0, HOSTED_CHOICE_ROOM), ...added, ...loaded.slice(HOSTED_CHOICE_ROOM)];
159163
}
160164

161165
/**

‎apps/web/src/state/pullRequests.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ export function usePullRequestFilterOptions(
390390
return {
391391
labels: query.values.flatMap(([, options]) => options.labels),
392392
authors: query.values.flatMap(([, options]) => options.authors),
393+
error: query.error,
393394
isPending: query.isPending,
394395
};
395396
}

0 commit comments

Comments
 (0)