Skip to content
TypeScript

fix(web,mobile): pull request filters no longer offer the Scratch folder (#19179)

olivercb395ee13b5b
diff --git a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
index c37e957a4d1..e3e8d3d0eb1 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
@@ -34,6 +34,7 @@ import {
scopedPullRequestListKey as pullRequestKey,
type EnvironmentPullRequestListEntry,
PR_LIST_PAGE_SIZE,
+ withoutScratchProjectScope,
} from "./pullRequestList";
import { useDebouncedValue } from "../../state/queries";
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
@@ -102,7 +103,12 @@ export function PullRequestsScreen(
},
[navigation, selectAndroidWorkspace],
);
- const controls = listControls.controlsFor(environmentId);
+ const allProjects = useProjects();
+ const savedControls = listControls.controlsFor(environmentId);
+ const controls = useMemo(
+ () => withoutScratchProjectScope(savedControls, allProjects),
+ [allProjects, savedControls],
+ );
const targets = useMemo(
() =>
environments
@@ -175,8 +181,9 @@ export function PullRequestsScreen(
].sort(),
}));
}
- const projects = useProjects().filter(
- (project) => environmentId === null || project.environmentId === environmentId,
+ const projects = allProjects.filter(
+ (project) =>
+ !project.isScratch && (environmentId === null || project.environmentId === environmentId),
);
const renderPullRequest = useCallback(
({ item }: { readonly item: EnvironmentPullRequestListEntry }) => (
diff --git a/apps/mobile/src/features/pull-requests/pullRequestList.test.ts b/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
index f3a085e02b4..de5dd166ff1 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestList.test.ts
@@ -18,6 +18,7 @@ import {
pullRequestLabelColor,
scopedPullRequestListKey,
pullRequestListRowsAreEqual,
+ withoutScratchProjectScope,
} from "./pullRequestList";
function entry(number: number, patch: Partial<PullRequestListEntry> = {}): PullRequestListEntry {
@@ -373,3 +374,39 @@ describe("mobile PR scan and filters", () => {
expect(pullRequestLabelColor("not-a-color")).toBeNull();
});
});
+
+describe("withoutScratchProjectScope", () => {
+ const projects = [
+ { id: "repo", environmentId: "env-a" },
+ { id: "scratch", environmentId: "env-a", isScratch: true as const },
+ ];
+
+ it("reads a scope saved on the Scratch folder as all projects", () => {
+ const controls = withoutScratchProjectScope(
+ { ...DEFAULT_PR_LIST_CONTROLS, projectId: "scratch", projectEnvironmentId: "env-a" },
+ projects,
+ );
+ expect(controls.projectId).toBeUndefined();
+ expect(controls.projectEnvironmentId).toBeUndefined();
+ });
+
+ it("keeps a repository scope, and one whose projects have not arrived yet", () => {
+ const repository = {
+ ...DEFAULT_PR_LIST_CONTROLS,
+ projectId: "repo",
+ projectEnvironmentId: "env-a",
+ };
+ expect(withoutScratchProjectScope(repository, projects)).toBe(repository);
+ const pending = { ...repository, projectId: "scratch" };
+ expect(withoutScratchProjectScope(pending, [])).toBe(pending);
+ });
+
+ it("keeps another server's project that shares the Scratch folder's id", () => {
+ const elsewhere = {
+ ...DEFAULT_PR_LIST_CONTROLS,
+ projectId: "scratch",
+ projectEnvironmentId: "env-b",
+ };
+ expect(withoutScratchProjectScope(elsewhere, projects)).toBe(elsewhere);
+ });
+});
diff --git a/apps/mobile/src/features/pull-requests/pullRequestList.ts b/apps/mobile/src/features/pull-requests/pullRequestList.ts
index 4527ba1e295..f0deeef6c97 100644
--- a/apps/mobile/src/features/pull-requests/pullRequestList.ts
+++ b/apps/mobile/src/features/pull-requests/pullRequestList.ts
@@ -15,6 +15,21 @@ export const DEFAULT_PR_LIST_CONTROLS: PullRequestListControls = {
sort: "updated",
};
+/** A scope saved on the Scratch folder is no longer offered, so it reads as "All projects". */
+export function withoutScratchProjectScope(
+ controls: PullRequestListControls,
+ projects: readonly { id: string; environmentId: string; isScratch?: true }[],
+): PullRequestListControls {
+ return projects.some(
+ (project) =>
+ project.isScratch &&
+ project.id === controls.projectId &&
+ project.environmentId === controls.projectEnvironmentId,
+ )
+ ? { ...controls, projectId: undefined, projectEnvironmentId: undefined }
+ : controls;
+}
+
export function pullRequestListKey(
item: Pick<PullRequestListEntry, "host" | "repository" | "number">,
) {
diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx
index f5ff710c1ac..bbd05e76cbb 100644
--- a/apps/web/src/routes/_chat.pull-requests.tsx
+++ b/apps/web/src/routes/_chat.pull-requests.tsx
@@ -411,9 +411,12 @@ function PullRequestsRouteView() {
// the one wrong answer the empty state can give.
const projectsKnown = useAllEnvironmentShellsBootstrapped();
// Only the projects the page can actually read: one on an environment that cannot list pull
- // requests could neither be listed nor acted on.
+ // requests could neither be listed nor acted on, and the Scratch folder is never a repository.
const projects = useMemo(
- () => allProjects.filter((project) => environmentIds.includes(project.environmentId)),
+ () =>
+ allProjects.filter(
+ (project) => !project.isScratch && environmentIds.includes(project.environmentId),
+ ),
[allProjects, environmentIds],
);
const environmentLabels = useMemo(