Skip to content

Commit c52df24

Browse files
TonybynMp4claudemaria-rcksjuliusmarminge
authored
fix(prs): reviewer menu searches past the first page and keeps GitLab's requested reviewers (#22489)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 508f869 commit c52df24

26 files changed

Lines changed: 593 additions & 65 deletions

File tree

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

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { useAtomValue } from "@effect/atom-react";
66
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
77
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
88
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
9+
import {
10+
hostReviewerQuery,
11+
reviewerCandidateView,
12+
type ReviewerTruncation,
13+
} from "@t3tools/client-runtime/pull-request-reviewers";
914
import type { PullRequestReviewerCandidate } from "@t3tools/contracts";
1015
import { useRef, useState } from "react";
1116
import { FlatList, Pressable, ScrollView, View } from "react-native";
@@ -17,10 +22,21 @@ import { Button } from "../../components/ui/Button";
1722
import { SymbolView } from "../../components/ui/AppSymbol";
1823
import { composerPullRequests } from "../../state/pull-requests";
1924
import { useEnvironmentQuery } from "../../state/query";
25+
import { useDebouncedValue } from "../../state/queries";
2026
import { useAtomCommand } from "../../state/use-atom-command";
2127
import { PullRequestAvatar } from "./PullRequestPresentation";
2228
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
2329

30+
const TRUNCATED_LABELS: Record<ReviewerTruncation, (error: string | null) => string> = {
31+
unsearchable: () =>
32+
"The provider has more reviewers than it returned. Find additional reviewers on the provider.",
33+
searchable: () => "The provider has more reviewers than are listed here. Search to find them.",
34+
"search-failed": (error) =>
35+
`Only listed reviewers are matched: the provider search failed. ${error ?? ""}`,
36+
"search-truncated": () =>
37+
"More reviewers match than the provider returned. Keep typing to narrow it down.",
38+
};
39+
2440
export function PullRequestReviewersScreen({ route }: StaticScreenProps<PullRequestParams>) {
2541
const navigation = useNavigation();
2642
const contentTopInset = useContentTopInset();
@@ -51,16 +67,30 @@ export function PullRequestReviewersScreen({ route }: StaticScreenProps<PullRequ
5167
const [pending, setPending] = useState<string | null>(null);
5268
const [error, setError] = useState<string | null>(null);
5369
const inFlight = useRef(false);
54-
const candidates = (() => {
55-
const needle = query.trim().toLowerCase();
56-
return [...(result.data?.candidates ?? [])]
57-
.filter((candidate) =>
58-
`${candidate.login} ${candidate.name ?? ""}`.toLowerCase().includes(needle),
59-
)
60-
.sort(
61-
(a, b) => Number(b.isRequested) - Number(a.isRequested) || a.login.localeCompare(b.login),
62-
);
63-
})();
70+
const debouncedQuery = useDebouncedValue(query.trim(), 250);
71+
const searchInput = {
72+
loaded: result.data,
73+
searchable: pr?.capabilities.reviewers.searchCandidates === true,
74+
query,
75+
debouncedQuery,
76+
};
77+
const hostQuery = hostReviewerQuery(searchInput);
78+
const searchResult = useEnvironmentQuery(
79+
hostQuery !== null
80+
? composerPullRequests.reviewerSearch({
81+
...target,
82+
input: { ...target.input, query: hostQuery },
83+
})
84+
: null,
85+
);
86+
const view = reviewerCandidateView({
87+
...searchInput,
88+
search: searchResult,
89+
});
90+
const candidates = [...view.candidates].sort(
91+
(a, b) => Number(b.isRequested) - Number(a.isRequested) || a.login.localeCompare(b.login),
92+
);
93+
const queryError = result.error ?? view.searchError;
6494
// A new search shows its best matches from the top.
6595
const search = (next: string) => {
6696
setQuery(next);
@@ -93,6 +123,7 @@ export function PullRequestReviewersScreen({ route }: StaticScreenProps<PullRequ
93123
);
94124
return;
95125
}
126+
if (hostQuery !== null) searchResult.refresh();
96127
if (!pr?.capabilities.reviewers.listCandidates) {
97128
search("");
98129
detail.refresh();
@@ -181,30 +212,34 @@ export function PullRequestReviewersScreen({ route }: StaticScreenProps<PullRequ
181212
);
182213
}}
183214
ListEmptyComponent={
184-
result.isPending && !result.data ? (
215+
(result.isPending && !result.data) || view.searchPending ? (
185216
<AppActivityIndicator className="my-8" />
186217
) : (
187218
<View className="px-4 py-6">
188219
<EmptyState
189220
title={
190-
result.error
221+
queryError
191222
? "Couldn't load reviewers"
192223
: query.trim()
193224
? "No matching reviewers"
194225
: "No reviewers available"
195226
}
196-
detail={result.error ?? "Search people and teams with access to this repository."}
227+
detail={queryError ?? "Search people and teams with access to this repository."}
197228
variant="plain"
198229
/>
199-
{result.error ? <Button label="Retry" onPress={result.refresh} /> : null}
230+
{queryError ? (
231+
<Button
232+
label="Retry"
233+
onPress={result.error ? result.refresh : searchResult.refresh}
234+
/>
235+
) : null}
200236
</View>
201237
)
202238
}
203239
ListFooterComponent={
204-
result.data?.truncated ? (
240+
view.truncation ? (
205241
<Text className="px-4 py-4 text-xs text-foreground-muted">
206-
The provider has more reviewers than it returned. Find additional reviewers on the
207-
provider.
242+
{TRUNCATED_LABELS[view.truncation](view.searchError)}
208243
</Text>
209244
) : undefined
210245
}

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
type PullRequestRoutingIdentityResult,
5959
type PullRequestReviewVerdict,
6060
type PullRequestReviewerCandidateList,
61+
type PullRequestReviewerCandidatesInput,
6162
type PullRequestReviewerRequestInput,
6263
type PullRequestLabelCandidateList,
6364
type PullRequestLabelChangeInput,
@@ -274,7 +275,7 @@ export class PullRequestService extends Context.Service<
274275
input: PullRequestReactionInput,
275276
) => Effect.Effect<void, PullRequestError>;
276277
readonly reviewerCandidates: (
277-
input: PullRequestRef,
278+
input: PullRequestReviewerCandidatesInput,
278279
) => Effect.Effect<PullRequestReviewerCandidateList, PullRequestError>;
279280
readonly requestReviewers: (
280281
input: PullRequestReviewerRequestInput,
@@ -2499,6 +2500,7 @@ export const make = Effect.gen(function* () {
24992500
repository: project.repository,
25002501
host: project.host,
25012502
number: input.number,
2503+
query: input.query,
25022504
})
25032505
.pipe(Effect.mapError(toPullRequestError("reviewerCandidates")))
25042506
: Effect.fail(

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

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@ import type {
44
PullRequestRef,
55
PullRequestReviewerCandidate,
66
} from "@t3tools/contracts";
7+
import {
8+
hostReviewerQuery,
9+
reviewerCandidateView,
10+
type ReviewerTruncation,
11+
} from "@t3tools/client-runtime/pull-request-reviewers";
712
import { CheckIcon, UserPlusIcon } from "lucide-react";
813
import { useState } from "react";
914

1015
import { pullRequestEnvironment } from "~/state/pullRequests";
1116
import { useEnvironmentQuery } from "~/state/query";
17+
import { useDebouncedValue } from "~/state/queries";
1218
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
1319

1420
import { toastManager } from "../ui/toast";
1521
import { PullRequestCandidatePicker } from "./PullRequestCandidatePicker";
1622
import { PullRequestActorLabel } from "./pullRequestPresentation";
1723
import { readableFailure } from "./pullRequestDetail.logic";
1824

19-
function matches(candidate: PullRequestReviewerCandidate, query: string): boolean {
20-
if (query.length === 0) return true;
21-
const needle = query.toLowerCase();
22-
return (
23-
candidate.login.toLowerCase().includes(needle) ||
24-
(candidate.name ?? "").toLowerCase().includes(needle)
25-
);
26-
}
25+
const TRUNCATED_LABELS: Record<ReviewerTruncation, (error: string | null) => string> = {
26+
unsearchable: () =>
27+
"This repository has more people with access than are listed here. Ask for the rest on the host.",
28+
searchable: () =>
29+
"This repository has more people with access than are listed here. Search to find them.",
30+
"search-failed": (error) =>
31+
`Only the people already listed are matched: the host search failed. ${error ?? ""}`,
32+
"search-truncated": () =>
33+
"More people match than the host returned. Keep typing to narrow it down.",
34+
};
2735

2836
export function PullRequestReviewerPicker({
2937
environmentId,
3038
reference,
3139
allowed,
40+
searchable,
3241
}: {
3342
environmentId: EnvironmentId;
3443
reference: PullRequestRef;
3544
allowed: boolean;
45+
searchable: boolean;
3646
}) {
3747
const [open, setOpen] = useState(false);
3848
const [query, setQuery] = useState("");
@@ -41,13 +51,26 @@ export function PullRequestReviewerPicker({
4151
const candidatesQuery = useEnvironmentQuery(
4252
open ? pullRequestEnvironment.reviewerCandidates({ environmentId, input: reference }) : null,
4353
);
54+
// Past the first page the host is asked, since what was loaded cannot answer for the rest.
55+
const debouncedQuery = useDebouncedValue(query.trim(), 250);
56+
const searchInput = { loaded: candidatesQuery.data, searchable, query, debouncedQuery };
57+
const hostQuery = hostReviewerQuery(searchInput);
58+
const searchResult = useEnvironmentQuery(
59+
open && hostQuery !== null
60+
? pullRequestEnvironment.reviewerSearch({
61+
environmentId,
62+
input: { ...reference, query: hostQuery },
63+
})
64+
: null,
65+
);
4466
const requestReviewers = useAtomCommand(pullRequestEnvironment.requestReviewers, {
4567
reportFailure: false,
4668
});
4769

48-
const candidates = (candidatesQuery.data?.candidates ?? []).filter((entry) =>
49-
matches(entry, query),
50-
);
70+
const { candidates, searchPending, searchError, truncation } = reviewerCandidateView({
71+
...searchInput,
72+
search: searchResult,
73+
});
5174

5275
const toggle = async (candidate: PullRequestReviewerCandidate) => {
5376
if (pending !== null) return;
@@ -74,6 +97,9 @@ export function PullRequestReviewerPicker({
7497
});
7598
return;
7699
}
100+
// The command reads the loaded list again only for somebody it lacked, and a search result
101+
// is keyed by what was typed, so the one on screen is read here or it keeps the old request.
102+
if (hostQuery !== null) searchResult.refresh();
77103
toastManager.add({
78104
type: "success",
79105
title: candidate.isRequested
@@ -93,14 +119,20 @@ export function PullRequestReviewerPicker({
93119
query={query}
94120
onQueryChange={setQuery}
95121
searchLabel="Search people with access"
96-
isPending={candidatesQuery.isPending && candidatesQuery.data === null}
97-
error={candidatesQuery.data === null ? candidatesQuery.error : null}
122+
isPending={(candidatesQuery.isPending && candidatesQuery.data === null) || searchPending}
123+
error={
124+
candidatesQuery.data === null
125+
? candidatesQuery.error
126+
: candidates.length === 0
127+
? searchError
128+
: null
129+
}
98130
candidates={candidates}
99131
emptyLabel="Nobody else has access to this repository."
100132
noMatchLabel="Nobody with access matches that."
101133
errorLabel="The people with access could not be read."
102-
truncated={candidatesQuery.data?.truncated === true}
103-
truncatedLabel="This repository has more people with access than are listed here. Ask for the rest on the host."
134+
truncated={truncation !== null}
135+
truncatedLabel={truncation === null ? "" : TRUNCATED_LABELS[truncation](searchError)}
104136
candidateKey={(candidate) => `${candidate.kind}:${candidate.id}`}
105137
disabled={pending !== null}
106138
onSelect={(candidate) => void toggle(candidate)}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ export function PullRequestSummaryTab({
802802
{detail.capabilities.reviewers.request &&
803803
detail.capabilities.reviewers.listCandidates ? (
804804
<PullRequestReviewerPicker
805+
searchable={detail.capabilities.reviewers.searchCandidates === true}
805806
environmentId={environmentId}
806807
reference={reference}
807808
allowed={detail.viewerPermissions.requestReviewers}

‎packages/client-runtime/package.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@
527527
"types": "./src/modelTraits.ts",
528528
"default": "./src/modelTraits.ts"
529529
},
530+
"./pull-request-reviewers": {
531+
"types": "./src/pullRequestReviewers.ts",
532+
"default": "./src/pullRequestReviewers.ts"
533+
},
530534
"./provider-clients": {
531535
"types": "./src/providerClients.ts",
532536
"default": "./src/providerClients.ts"

0 commit comments

Comments
 (0)