Skip to content

Commit

Permalink
DEVPROD-6523: Patch Submission Filter (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon authored May 28, 2024
1 parent ef6245a commit 0f7c5de
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
32 changes: 31 additions & 1 deletion apps/spruce/cypress/integration/myPatches/my_patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,37 @@ describe("My Patches Page", () => {
"/version/5ecedafb562343215a7ff297/tasks?statuses=success",
);
});

describe("Patch submission selctor", () => {
it("Clicking the patch submission selector updates the URL, and renders patches", () => {
cy.visit(MY_PATCHES_ROUTE);
cy.dataCy("requester-selector").click();
const cliPatchTitle = "main: EVG-7823 add a commit queue message (#4048)";
const prPatchTitle =
"evergreen-ci/evergreen' pull request #3186 by bsamek: EVG-7425 Don't send ShouldExit to unprovisioned hosts (https://github.com/evergreen-ci/evergreen/pull/3186)";
cy.dataCy("patch-card").first().contains(cliPatchTitle);
cy.dataCy("github_pull_request-option").click();
urlSearchParamsAreUpdated({
pathname: MY_PATCHES_ROUTE,
paramName: "requesters",
search: "github_pull_request",
});
cy.dataCy("patch-card").first().contains(prPatchTitle);
cy.dataCy("patch_request-option").click();
urlSearchParamsAreUpdated({
pathname: MY_PATCHES_ROUTE,
paramName: "requesters",
search: "github_pull_request,patch_request",
});
cy.dataCy("patch-card").first().contains(cliPatchTitle);
cy.dataCy("github_pull_request-option").click();
urlSearchParamsAreUpdated({
pathname: MY_PATCHES_ROUTE,
paramName: "requesters",
search: "patch_request",
});
cy.dataCy("patch-card").first().contains(cliPatchTitle);
});
});
describe("Commit queue checkbox", () => {
it("Clicking the commit queue checkbox updates the URL, requests patches and renders patches", () => {
cy.visit(MY_PATCHES_ROUTE);
Expand Down
44 changes: 44 additions & 0 deletions apps/spruce/src/components/PatchesPage/RequesterSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Combobox, ComboboxOption } from "@leafygreen-ui/combobox";
import { githubPRRequester, patchRequester } from "constants/patch";
import { requesterSubscriberOptions } from "constants/triggers";
import { useStatusesFilter } from "hooks";
import { PatchPageQueryParams } from "types/patch";

export const RequesterSelector: React.FC = () => {
const { inputValue: statusVal, setAndSubmitInputValue: statusValOnChange } =
useStatusesFilter({ urlParam: PatchPageQueryParams.Requesters });

return (
<Combobox
label=""
data-cy="requester-selector"
placeholder="Patch submission"
value={statusVal}
multiselect
onChange={statusValOnChange}
overflow="scroll-x"
>
{options.map(({ displayName, key, value }) => (
<ComboboxOption
key={key}
value={value}
displayName={displayName}
data-cy={`${value}-option`}
/>
))}
</Combobox>
);
};

const options = [
{
displayName: requesterSubscriberOptions[githubPRRequester],
value: githubPRRequester,
key: githubPRRequester,
},
{
displayName: requesterSubscriberOptions[patchRequester],
value: patchRequester,
key: patchRequester,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import { PatchPageQueryParams, ALL_PATCH_STATUS } from "types/patch";
*/
export const usePatchesQueryParams = (): Omit<
Required<PatchesInput>,
"includeCommitQueue" | "onlyCommitQueue" | "requesters"
"includeCommitQueue" | "onlyCommitQueue"
> => {
const [patchName] = useQueryParam<string>(PatchPageQueryParams.PatchName, "");
const [rawStatuses] = useQueryParam<string[]>(
PatchPageQueryParams.Statuses,
[],
);
const [requesters] = useQueryParam<string[]>(
PatchPageQueryParams.Requesters,
[],
);
const [hidden] = useQueryParam(PatchPageQueryParams.Hidden, false);
const { limit, page } = usePagination();
const statuses = rawStatuses.filter((v) => v && v !== ALL_PATCH_STATUS);
Expand All @@ -28,6 +32,7 @@ export const usePatchesQueryParams = (): Omit<
includeHidden: hidden || Cookies.get(INCLUDE_HIDDEN_PATCHES) === "true",
page,
patchName: `${patchName}`,
requesters,
statuses,
};
};
2 changes: 2 additions & 0 deletions apps/spruce/src/constants/patch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const commitQueueAlias = "__commit_queue";
export const commitQueueRequester = "merge_test";
export const githubMergeRequester = "github_merge_request";
export const githubPRRequester = "github_pull_request";
export const patchRequester = "patch_request";
export const unlinkedPRUsers = new Set(["github_pull_request", "parent_patch"]);
2 changes: 2 additions & 0 deletions apps/spruce/src/pages/UserPatches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Cookies from "js-cookie";
import { useParams } from "react-router-dom";
import { useUserPatchesAnalytics } from "analytics";
import { PatchesPage } from "components/PatchesPage";
import { RequesterSelector } from "components/PatchesPage/RequesterSelector";
import { usePatchesQueryParams } from "components/PatchesPage/usePatchesQueryParams";
import { INCLUDE_COMMIT_QUEUE_USER_PATCHES } from "constants/cookies";
import { DEFAULT_POLL_INTERVAL } from "constants/index";
Expand Down Expand Up @@ -52,6 +53,7 @@ export const UserPatches = () => {
return (
<PatchesPage
analyticsObject={analyticsObject}
filterComp={<RequesterSelector />}
pageTitle={pageTitle}
loading={loading && !data?.user.patches}
pageType="user"
Expand Down
1 change: 1 addition & 0 deletions apps/spruce/src/types/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum PatchPageQueryParams {
Page = "page",
Limit = "limit",
Hidden = "hidden",
Requesters = "requesters",
}

export enum PatchStatus {
Expand Down

0 comments on commit 0f7c5de

Please sign in to comment.