fix(web,mobile): pull request filters no longer offer the Scratch folder (#19179)
This commit is contained in:
1 parent
e093789dd2
commit
cb395ee13b
4 files changed
+67
-5
No files matched your search
@@ -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 }) => (
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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">,
|
||||
) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user