Skip to content

fix: Don't show pagination during workspaces load #4743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 25, 2022
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
27 changes: 13 additions & 14 deletions site/src/components/PaginationWidget/PaginationWidget.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ import { render } from "../../testHelpers/renderHelpers"
import { PaginationWidget } from "./PaginationWidget"

describe("PaginatedList", () => {
it("displays an accessible previous and next button regardless of the number of pages", async () => {
const { container } = render(
it("displays an accessible previous and next button", () => {
render(
<PaginationWidget
prevLabel="Previous"
nextLabel="Next"
numRecords={200}
numRecordsPerPage={12}
activePage={1}
onPrevClick={() => jest.fn()}
onNextClick={() => jest.fn()}
/>,
)

expect(
await screen.findByRole("button", { name: "Previous page" }),
).toBeTruthy()
expect(
await screen.findByRole("button", { name: "Next page" }),
).toBeTruthy()
// Shouldn't render any pages if no records are passed in
screen.getByRole("button", { name: "Previous page" }),
).toBeInTheDocument()
expect(
await container.querySelectorAll(`button[name="Page button"]`),
).toHaveLength(0)
screen.getByRole("button", { name: "Next page" }),
).toBeInTheDocument()
})

it("displays the expected number of pages with one ellipsis tile", async () => {
it("displays the expected number of pages with one ellipsis tile", () => {
const { container } = render(
<PaginationWidget
prevLabel="Previous"
Expand All @@ -41,11 +40,11 @@ describe("PaginatedList", () => {

// 7 total spaces. 6 are page numbers, one is ellipsis
expect(
await container.querySelectorAll(`button[name="Page button"]`),
container.querySelectorAll(`button[name="Page button"]`),
).toHaveLength(6)
})

it("displays the expected number of pages with two ellipsis tiles", async () => {
it("displays the expected number of pages with two ellipsis tiles", () => {
const { container } = render(
<PaginationWidget
prevLabel="Previous"
Expand All @@ -61,7 +60,7 @@ describe("PaginatedList", () => {

// 7 total spaces. 2 sets of ellipsis on either side of the active page
expect(
await container.querySelectorAll(`button[name="Page button"]`),
container.querySelectorAll(`button[name="Page button"]`),
).toHaveLength(5)
})
})
4 changes: 2 additions & 2 deletions site/src/components/PaginationWidget/PaginationWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export const PaginationWidget = ({
const isMobile = useMediaQuery(theme.breakpoints.down("sm"))
const styles = useStyles()

// No need to display any pagination if we know the number of pages is 1
if (numPages === 1 || numRecords === 0) {
// No need to display any pagination if we know the number of pages is 1 or 0
if (numPages <= 1 || numRecords === 0) {
return null
}

Expand Down