Skip to content

Commit 9f70fcc

Browse files
Bil0000claude
andauthored
fix(prs): typed qualifiers filter mobile PR search and sync the draft menu (#19934)
Mobile now parses GitHub-style qualifiers (draft:, label:, author:, review:, status:, namespaced labels) out of PR search through the shared client-runtime parser, and Filters → Draft on web and mobile reflects and replaces a typed draft: qualifier. Co-authored-by: Bil0000 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e10f5d1 commit 9f70fcc

9 files changed

Lines changed: 404 additions & 275 deletions

File tree

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import {
2+
applyPullRequestDraftFilterChange,
3+
parsePullRequestQuery,
4+
} from "@t3tools/client-runtime/pull-request-query";
15
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
26
import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
37
import { useNavigation } from "@react-navigation/native";
48
import { use, useCallback, useEffect, useMemo, useRef, useState } from "react";
5-
import { ProjectId } from "@t3tools/contracts";
69
import { useAtomValue } from "@effect/atom-react";
710
import {
811
Keyboard,
@@ -30,10 +33,10 @@ import { usePullRequestListActions } from "./usePullRequestListActions";
3033
import {
3134
filterPullRequestList,
3235
pullRequestListFacets,
36+
pullRequestListInput,
3337
pullRequestListRowsAreEqual,
3438
scopedPullRequestListKey as pullRequestKey,
3539
type EnvironmentPullRequestListEntry,
36-
PR_LIST_PAGE_SIZE,
3740
withoutScratchProjectScope,
3841
} from "./pullRequestList";
3942
import { useDebouncedValue } from "../../state/queries";
@@ -79,6 +82,8 @@ export function PullRequestsScreen(
7982
);
8083
const debouncedQuery = useDebouncedValue(tab.query.trim(), 180);
8184
const query = tab.searchMode === "resting" ? "" : debouncedQuery;
85+
const typedQuery = tab.searchMode === "resting" ? "" : tab.query;
86+
const typedDraft = parsePullRequestQuery(typedQuery).filters.draft;
8287
const listControls = usePullRequestListControls();
8388
const selectedEnvironmentId = listControls.environmentId;
8489
const environmentId = environments.some((item) => item.environmentId === selectedEnvironmentId)
@@ -121,14 +126,7 @@ export function PullRequestsScreen(
121126
.sort((left, right) => left.environmentId.localeCompare(right.environmentId))
122127
.map((environment) => ({
123128
environmentId: environment.environmentId,
124-
input: {
125-
state: controls.state,
126-
involvement: controls.involvement,
127-
filters: controls.filters,
128-
limit: PR_LIST_PAGE_SIZE,
129-
...(controls.projectId ? { projectId: ProjectId.make(controls.projectId) } : {}),
130-
...(query ? { query } : {}),
131-
},
129+
input: pullRequestListInput(controls, query),
132130
})),
133131
[environments, environmentId, configs, controls, query],
134132
);
@@ -281,9 +279,20 @@ export function PullRequestsScreen(
281279
}))}
282280
environmentId={environmentId}
283281
onEnvironmentChange={listControls.setEnvironmentId}
284-
value={controls}
282+
value={
283+
typedDraft
284+
? { ...controls, filters: { ...controls.filters, draft: typedDraft } }
285+
: controls
286+
}
285287
onChange={(next) => {
286-
listControls.setControls(environmentId, next);
288+
const update = applyPullRequestDraftFilterChange(
289+
typedQuery,
290+
controls.filters,
291+
next.filters,
292+
);
293+
listControls.setControls(environmentId, { ...next, filters: update.filters });
294+
if (update.query !== typedQuery)
295+
workspace.dispatch({ type: "query", tab: "pullRequests", query: update.query });
287296
void listRef.current?.scrollToOffset({
288297
offset: Platform.OS === "ios" ? -insets.top : 0,
289298
animated: false,

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
mergePullRequestListEntries,
1313
mergeEnvironmentPullRequestPages,
1414
nextPullRequestListInput,
15+
PR_LIST_PAGE_SIZE,
1516
pullRequestListFacets,
1617
pullRequestListHead,
18+
pullRequestListInput,
1719
pullRequestListReviewStatus,
1820
pullRequestLabelColor,
1921
scopedPullRequestListKey,
@@ -289,6 +291,11 @@ describe("mobile PR scan and filters", () => {
289291
new Set(),
290292
).map((row) => row.number),
291293
).toEqual([1]);
294+
expect(
295+
filterPullRequestList(rows, DEFAULT_PR_LIST_CONTROLS, viewers, "author:@me", new Set()).map(
296+
(row) => row.number,
297+
),
298+
).toEqual([1]);
292299
});
293300
it("combines label groups, exclusions, draft and review filters", () => {
294301
const rows = [
@@ -314,6 +321,29 @@ describe("mobile PR scan and filters", () => {
314321
),
315322
).toEqual([1]);
316323
});
324+
it("reads a typed draft qualifier as a filter and searches only the text left over", () => {
325+
expect(pullRequestListInput(DEFAULT_PR_LIST_CONTROLS, "draft:false fix")).toEqual({
326+
state: "open",
327+
involvement: "all",
328+
filters: { draft: "hide" },
329+
limit: PR_LIST_PAGE_SIZE,
330+
query: "fix",
331+
});
332+
const rows = [
333+
entry(1, { title: "Fix parser" }),
334+
entry(2, { title: "Fix drafts", isDraft: true }),
335+
entry(3),
336+
];
337+
expect(
338+
filterPullRequestList(
339+
rows,
340+
DEFAULT_PR_LIST_CONTROLS,
341+
{},
342+
"draft:false fix",
343+
new Set(["github.com"]),
344+
).map((row) => row.number),
345+
).toEqual([1]);
346+
});
317347
it("does not label unsupported review summaries as reviewed or match text locally on host-search results", () => {
318348
expect(
319349
filterPullRequestList(

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import type {
2-
EnvironmentId,
3-
PullRequestListEntry,
4-
PullRequestListInput,
5-
PullRequestListResult,
1+
import { parsePullRequestQuery } from "@t3tools/client-runtime/pull-request-query";
2+
import {
3+
ProjectId,
4+
resolvePullRequestAuthorFilter,
5+
type EnvironmentId,
6+
type PullRequestListEntry,
7+
type PullRequestListInput,
8+
type PullRequestListResult,
69
} from "@t3tools/contracts";
710
import type { PullRequestListControls } from "../../persistence/mobile-preferences";
811

@@ -138,6 +141,21 @@ export function pullRequestListHead(
138141
};
139142
}
140143

144+
export function pullRequestListInput(
145+
controls: PullRequestListControls,
146+
query: string,
147+
): PullRequestListInput {
148+
const parsed = parsePullRequestQuery(query);
149+
return {
150+
state: controls.state,
151+
involvement: controls.involvement,
152+
filters: { ...controls.filters, ...parsed.filters },
153+
limit: PR_LIST_PAGE_SIZE,
154+
...(controls.projectId ? { projectId: ProjectId.make(controls.projectId) } : {}),
155+
...(parsed.text ? { query: parsed.text } : {}),
156+
};
157+
}
158+
141159
export function nextPullRequestListInput(
142160
pages: PullRequestListPages,
143161
input: PullRequestListInput,
@@ -186,8 +204,9 @@ export function filterPullRequestList<
186204
connectedEnvironmentIds?: ReadonlySet<string>,
187205
) {
188206
const normalize = (value: string) => value.toLowerCase();
189-
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
190-
const { filters } = controls;
207+
const parsed = parsePullRequestQuery(query);
208+
const words = parsed.text.toLowerCase().split(/\s+/).filter(Boolean);
209+
const filters = { ...controls.filters, ...parsed.filters };
191210
const filtered = entries.filter((entry) => {
192211
if (controls.state !== "all" && entry.state !== controls.state) return false;
193212
if (controls.projectId && entry.projectId !== controls.projectId) return false;
@@ -204,8 +223,8 @@ export function filterPullRequestList<
204223
if ((filters.draft === "only" && !entry.isDraft) || (filters.draft === "hide" && entry.isDraft))
205224
return false;
206225
if (filters.author) {
207-
const author = filters.author === "me" ? viewer : filters.author;
208-
if (!author || normalize(entry.author?.login ?? "") !== normalize(author)) return false;
226+
const author = resolvePullRequestAuthorFilter(filters.author, viewer);
227+
if (normalize(entry.author?.login ?? "") !== normalize(author)) return false;
209228
}
210229
if (filters.review && entry.reviewDecision && entry.reviewDecision !== filters.review)
211230
return false;

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

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
groupPullRequestsByInvolvement,
2020
matchesPullRequestFilters,
2121
matchesPullRequestQuery,
22-
parsePullRequestQuery,
2322
pullRequestStatsBatches,
2423
pullRequestStatsKeysToRequest,
2524
pullRequestStatsRefreshBatches,
@@ -557,84 +556,6 @@ describe("narrowing rows by the filters a host may not have applied", () => {
557556
});
558557
});
559558

560-
describe("reading qualifiers out of a typed query", () => {
561-
it("keeps quoted values whole and separates negation", () => {
562-
expect(parsePullRequestQuery('label:"needs design" -label:wip Fix the parser')).toEqual({
563-
text: "Fix the parser",
564-
filters: { labels: [["needs design"]], excludedLabels: ["wip"] },
565-
});
566-
});
567-
568-
it("reads a comma-separated list as one group either name satisfies", () => {
569-
expect(parsePullRequestQuery("label:size:S,size:XS").filters.labels).toEqual([
570-
["size:S", "size:XS"],
571-
]);
572-
});
573-
574-
it("keeps the spaces in a quoted name of a list, and drops an empty part", () => {
575-
expect(parsePullRequestQuery('label:"needs design","wip"').filters.labels).toEqual([
576-
["needs design", "wip"],
577-
]);
578-
expect(parsePullRequestQuery("label:a,,b").filters.labels).toEqual([["a", "b"]]);
579-
});
580-
581-
it("excludes every name of a negated list", () => {
582-
expect(parsePullRequestQuery("-label:a,b").filters).toEqual({ excludedLabels: ["a", "b"] });
583-
});
584-
585-
it("makes each label qualifier its own group, so the groups are an AND", () => {
586-
expect(parsePullRequestQuery("label:bug label:a,b").filters.labels).toEqual([
587-
["bug"],
588-
["a", "b"],
589-
]);
590-
});
591-
592-
it("reads the scalar qualifiers in GitHub's own spelling", () => {
593-
expect(
594-
parsePullRequestQuery("author:octocat DRAFT:false review:changes_requested status:failure")
595-
.filters,
596-
).toEqual({
597-
author: "octocat",
598-
draft: "hide",
599-
review: "changes-requested",
600-
checks: "failing",
601-
});
602-
});
603-
604-
it("leaves an unknown value and a stray colon as text, and reads an unknown key as a label", () => {
605-
const parsed = parsePullRequestQuery("milestone:v2 draft:maybe status: parser");
606-
expect(parsed.filters).toEqual({ labels: [["milestone:v2"]] });
607-
expect(parsed.text).toBe("draft:maybe status: parser");
608-
});
609-
610-
it("reads a quoted name holding a comma as the one label it is", () => {
611-
expect(parsePullRequestQuery('label:"needs,triage"').filters.labels).toEqual([
612-
["needs,triage"],
613-
]);
614-
expect(parsePullRequestQuery('-label:"needs,triage"').filters.excludedLabels).toEqual([
615-
"needs,triage",
616-
]);
617-
});
618-
619-
it("cuts a typed query back to what the contract carries", () => {
620-
const many = Array.from({ length: 14 }, (_, index) => `l${index}`).join(",");
621-
const long = "x".repeat(240);
622-
const parsed = parsePullRequestQuery(`label:${many} label:${long} author:${long}`);
623-
expect(parsed.filters.labels?.[0]).toHaveLength(10);
624-
expect(parsed.filters.labels?.[1]).toEqual(["x".repeat(200)]);
625-
expect(parsed.filters.author).toBe("x".repeat(200));
626-
});
627-
628-
it("cuts a namespaced label after its key is prefixed on", () => {
629-
const parsed = parsePullRequestQuery(`size:${"x".repeat(240)}`);
630-
expect(parsed.filters.labels).toEqual([[`size:${"x".repeat(240)}`.slice(0, 200)]]);
631-
});
632-
633-
it("answers an empty query with an empty everything", () => {
634-
expect(parsePullRequestQuery(" ")).toEqual({ text: "", filters: {} });
635-
});
636-
});
637-
638559
describe("resolveProjectScope", () => {
639560
const projects = [{ id: "p1" }, { id: "p2" }];
640561

@@ -1508,58 +1429,6 @@ describe("the server a saved selection names", () => {
15081429
});
15091430
});
15101431

1511-
describe("colon-namespaced labels typed as a search", () => {
1512-
it("reads an unknown key as the label it almost always is", () => {
1513-
expect(parsePullRequestQuery("size:XXL").filters.labels).toEqual([["size:XXL"]]);
1514-
expect(parsePullRequestQuery("vouch:trusted").filters.labels).toEqual([["vouch:trusted"]]);
1515-
expect(parsePullRequestQuery("size:XXL").text).toBe("");
1516-
});
1517-
1518-
it("reads the key as the namespace of every bare name in its list", () => {
1519-
expect(parsePullRequestQuery("size:S,XS").filters.labels).toEqual([["size:S", "size:XS"]]);
1520-
});
1521-
1522-
it("leaves a name that already carries its own namespace alone", () => {
1523-
expect(parsePullRequestQuery("size:S,size:XS").filters.labels).toEqual([["size:S", "size:XS"]]);
1524-
});
1525-
1526-
it("excludes one the same way", () => {
1527-
expect(parsePullRequestQuery("-size:XXL").filters.excludedLabels).toEqual(["size:XXL"]);
1528-
expect(parsePullRequestQuery("-size:S,XS").filters.excludedLabels).toEqual([
1529-
"size:S",
1530-
"size:XS",
1531-
]);
1532-
});
1533-
1534-
it("keeps a quoted token as text, which is the way back to a literal search", () => {
1535-
const parsed = parsePullRequestQuery('"size:XXL"');
1536-
expect(parsed.filters.labels).toBeUndefined();
1537-
expect(parsed.text).toBe('"size:XXL"');
1538-
});
1539-
1540-
it("reads a hyphenated namespace as a label too", () => {
1541-
expect(parsePullRequestQuery("priority-1:high").filters.labels).toEqual([["priority-1:high"]]);
1542-
expect(parsePullRequestQuery("priority-1:high").text).toBe("");
1543-
});
1544-
1545-
it("leaves a pasted link alone rather than naming a label after its scheme", () => {
1546-
const parsed = parsePullRequestQuery("https://github.com/pingdotgg/t3code/pull/1");
1547-
expect(parsed.filters.labels).toBeUndefined();
1548-
expect(parsed.text).toBe("https://github.com/pingdotgg/t3code/pull/1");
1549-
});
1550-
1551-
it("mixes with the keys it does know, and with plain words", () => {
1552-
const parsed = parsePullRequestQuery("area:web draft:true wizard label:bug");
1553-
expect(parsed.filters).toEqual({ labels: [["area:web"], ["bug"]], draft: "only" });
1554-
expect(parsed.text).toBe("wizard");
1555-
});
1556-
1557-
it("shares the ceiling with the labels typed as labels", () => {
1558-
const many = Array.from({ length: 12 }, (_, index) => `area:${index}`).join(" ");
1559-
expect(parsePullRequestQuery(many).filters.labels).toHaveLength(10);
1560-
});
1561-
});
1562-
15631432
describe("the priority groups against a paginated feed", () => {
15641433
const authoredRow = (number: number, updatedAt: string) =>
15651434
entry({ number, updatedAt, author: { login: "Bilal", name: null, avatarUrl: null } });

0 commit comments

Comments
 (0)