Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }) => (
Expand Down
37 changes: 37 additions & 0 deletions apps/mobile/src/features/pull-requests/pullRequestList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
pullRequestLabelColor,
scopedPullRequestListKey,
pullRequestListRowsAreEqual,
withoutScratchProjectScope,
} from "./pullRequestList";

function entry(number: number, patch: Partial<PullRequestListEntry> = {}): PullRequestListEntry {
Expand Down Expand Up @@ -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);
});
});
15 changes: 15 additions & 0 deletions apps/mobile/src/features/pull-requests/pullRequestList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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">,
) {
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/routes/_chat.pull-requests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading