-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-10189: Add pagination to waterfall (#461)
- Loading branch information
Showing
19 changed files
with
546 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe("pagination", () => { | ||
beforeEach(() => { | ||
cy.visit("/project/spruce/waterfall"); | ||
}); | ||
|
||
it("url query params update as page changes", () => { | ||
cy.location("search").should("equal", ""); | ||
|
||
cy.dataCy("next-page-button").click(); | ||
cy.dataCy("waterfall-skeleton").should("not.exist"); | ||
cy.location("search").should("contain", "maxOrder"); | ||
|
||
cy.dataCy("prev-page-button").click(); | ||
cy.dataCy("waterfall-skeleton").should("not.exist"); | ||
cy.location("search").should("contain", "minOrder"); | ||
}); | ||
|
||
it("versions update correctly as page changes", () => { | ||
const firstPageFirstCommit = "2ab1c56"; | ||
const secondPageFirstCommit = "e391612"; | ||
|
||
cy.dataCy("version-labels").children().should("have.length", 6); | ||
cy.dataCy("version-labels").children().eq(0).contains(firstPageFirstCommit); | ||
|
||
cy.dataCy("next-page-button").click(); | ||
cy.dataCy("version-labels").children().should("have.length", 5); | ||
cy.dataCy("version-labels") | ||
.children() | ||
.eq(0) | ||
.contains(secondPageFirstCommit); | ||
|
||
cy.dataCy("prev-page-button").click(); | ||
cy.dataCy("version-labels").children().should("have.length", 6); | ||
cy.dataCy("version-labels").children().eq(0).contains(firstPageFirstCommit); | ||
}); | ||
|
||
it("builds update correctly as page changes", () => { | ||
cy.dataCy("build-group").children().as("builds"); | ||
cy.get("@builds").eq(0).children().should("have.length", 1); | ||
cy.get("@builds").eq(1).children().should("have.length", 8); | ||
cy.get("@builds").eq(2).children().should("have.length", 0); | ||
cy.get("@builds").eq(3).children().should("have.length", 1); | ||
cy.get("@builds").eq(4).children().should("have.length", 8); | ||
cy.get("@builds").eq(5).children().should("have.length", 8); | ||
|
||
cy.dataCy("next-page-button").click(); | ||
cy.get("@builds").eq(0).children().should("have.length", 8); | ||
cy.get("@builds").eq(1).children().should("have.length", 0); | ||
cy.get("@builds").eq(2).children().should("have.length", 8); | ||
cy.get("@builds").eq(3).children().should("have.length", 8); | ||
cy.get("@builds").eq(4).children().should("have.length", 1); | ||
|
||
cy.dataCy("prev-page-button").click(); | ||
cy.get("@builds").eq(0).children().should("have.length", 1); | ||
cy.get("@builds").eq(1).children().should("have.length", 8); | ||
cy.get("@builds").eq(2).children().should("have.length", 0); | ||
cy.get("@builds").eq(3).children().should("have.length", 1); | ||
cy.get("@builds").eq(4).children().should("have.length", 8); | ||
cy.get("@builds").eq(5).children().should("have.length", 8); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ fragment WaterfallVersion on Version { | |
} | ||
id | ||
message | ||
order | ||
requester | ||
revision | ||
...UpstreamProject | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
apps/spruce/src/pages/waterfall/PaginationButtons/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useTransition } from "react"; | ||
import styled from "@emotion/styled"; | ||
import Button from "@leafygreen-ui/button"; | ||
import { useWaterfallAnalytics } from "analytics"; | ||
import Icon from "components/Icon"; | ||
import { size } from "constants/tokens"; | ||
import { WaterfallPagination } from "gql/generated/types"; | ||
import { useQueryParams } from "hooks/useQueryParam"; | ||
import { WaterfallFilterOptions } from "types/waterfall"; | ||
|
||
interface PaginationButtonsProps { | ||
pagination: WaterfallPagination | undefined; | ||
} | ||
|
||
export const PaginationButtons: React.FC<PaginationButtonsProps> = ({ | ||
pagination, | ||
}) => { | ||
const { sendEvent } = useWaterfallAnalytics(); | ||
const [, startTransition] = useTransition(); | ||
const [queryParams, setQueryParams] = useQueryParams(); | ||
|
||
const { hasNextPage, hasPrevPage, nextPageOrder, prevPageOrder } = | ||
pagination ?? {}; | ||
|
||
const onNextClick = () => { | ||
sendEvent({ name: "Changed page", direction: "next" }); | ||
startTransition(() => { | ||
setQueryParams({ | ||
...queryParams, | ||
[WaterfallFilterOptions.MaxOrder]: nextPageOrder, | ||
[WaterfallFilterOptions.MinOrder]: undefined, | ||
}); | ||
}); | ||
}; | ||
|
||
const onPrevClick = () => { | ||
sendEvent({ | ||
name: "Changed page", | ||
direction: "previous", | ||
}); | ||
startTransition(() => { | ||
setQueryParams({ | ||
...queryParams, | ||
[WaterfallFilterOptions.MaxOrder]: undefined, | ||
[WaterfallFilterOptions.MinOrder]: prevPageOrder, | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ButtonContainer> | ||
<Button | ||
data-cy="prev-page-button" | ||
disabled={!hasPrevPage} | ||
leftGlyph={<Icon glyph="ChevronLeft" />} | ||
onClick={onPrevClick} | ||
/> | ||
<Button | ||
data-cy="next-page-button" | ||
disabled={!hasNextPage} | ||
leftGlyph={<Icon glyph="ChevronRight" />} | ||
onClick={onNextClick} | ||
/> | ||
</ButtonContainer> | ||
); | ||
}; | ||
|
||
const ButtonContainer = styled.div` | ||
display: flex; | ||
gap: ${size.xs}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.