From 32263f57358dabee38c599cfb7b02d637e417b3b Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 21 Oct 2022 16:22:07 +0000 Subject: [PATCH 01/30] Extract PageButton --- .../PaginationWidget/PageButton.tsx | 52 +++++++++++++++++++ .../PaginationWidget/PaginationWidget.tsx | 50 ++---------------- 2 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 site/src/components/PaginationWidget/PageButton.tsx diff --git a/site/src/components/PaginationWidget/PageButton.tsx b/site/src/components/PaginationWidget/PageButton.tsx new file mode 100644 index 0000000000000..72b2656a01599 --- /dev/null +++ b/site/src/components/PaginationWidget/PageButton.tsx @@ -0,0 +1,52 @@ +import Button from "@material-ui/core/Button" +import { makeStyles } from "@material-ui/core/styles" + +interface PageButtonProps { + activePage?: number + page?: number + placeholder?: string + numPages?: number + onPageClick?: (page: number) => void + disabled?: boolean +} + +export const PageButton = ({ + activePage, + page, + placeholder = "...", + numPages, + onPageClick, + disabled = false +}: PageButtonProps): JSX.Element => { + const styles = useStyles() + return ( + + ) +} + +const useStyles = makeStyles((theme) => ({ + pageButton: { + "&:not(:last-of-type)": { + marginRight: theme.spacing(0.5), + }, + }, + + activePageButton: { + borderColor: `${theme.palette.info.main}`, + backgroundColor: `${theme.palette.info.dark}`, + }, +})) diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index f2dfbfb0900ed..fad360f27c006 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -77,38 +77,6 @@ export const buildPagedList = ( return range(1, numPages) } -interface PageButtonProps { - activePage: number - page: number - numPages: number - onPageClick?: (page: number) => void -} - -const PageButton = ({ - activePage, - page, - numPages, - onPageClick, -}: PageButtonProps): JSX.Element => { - const styles = useStyles() - return ( - - ) -} - export const PaginationWidget = ({ prevLabel, nextLabel, @@ -155,13 +123,11 @@ export const PaginationWidget = ({ {buildPagedList(numPages, activePage).map((page) => typeof page !== "number" ? ( - + /> ) : ( ({ marginRight: `${theme.spacing(0.5)}px`, }, - pageButton: { - "&:not(:last-of-type)": { - marginRight: theme.spacing(0.5), - }, - }, - - activePageButton: { - borderColor: `${theme.palette.info.main}`, - backgroundColor: `${theme.palette.info.dark}`, - }, })) From 5837c28cc7ad9fdd188ee63c0b8f446c247562db Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 21 Oct 2022 16:24:02 +0000 Subject: [PATCH 02/30] Fix import --- site/src/components/PaginationWidget/PaginationWidget.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index fad360f27c006..2a69c7234eff1 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -6,6 +6,7 @@ import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight" import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" import { Maybe } from "components/Conditionals/Maybe" import { CSSProperties } from "react" +import { PageButton } from "./PageButton" export type PaginationWidgetProps = { prevLabel: string From a1303b0ef37fa19e9bfea775fe7f81b77004348d Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 21 Oct 2022 19:19:26 +0000 Subject: [PATCH 03/30] Extract utils --- .../PaginationWidget/PaginationWidget.tsx | 59 +------------------ .../{buildPagedList.test.ts => utils.test.ts} | 2 +- site/src/components/PaginationWidget/utils.ts | 58 ++++++++++++++++++ 3 files changed, 60 insertions(+), 59 deletions(-) rename site/src/components/PaginationWidget/{buildPagedList.test.ts => utils.test.ts} (93%) create mode 100644 site/src/components/PaginationWidget/utils.ts diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index 2a69c7234eff1..1f61156a01df9 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -7,6 +7,7 @@ import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" import { Maybe } from "components/Conditionals/Maybe" import { CSSProperties } from "react" import { PageButton } from "./PageButton" +import { buildPagedList, DEFAULT_RECORDS_PER_PAGE } from "./utils" export type PaginationWidgetProps = { prevLabel: string @@ -20,64 +21,6 @@ export type PaginationWidgetProps = { containerStyle?: CSSProperties } -/** - * Generates a ranged array with an option to step over values. - * Shamelessly stolen from: - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#sequence_generator_range - */ -const range = (start: number, stop: number, step = 1) => - Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step) - -export const DEFAULT_RECORDS_PER_PAGE = 25 -// Number of pages to the left or right of the current page selection. -const PAGE_NEIGHBORS = 1 -// Number of pages displayed for cases where there are multiple ellipsis showing. This can be -// thought of as the minimum number of page numbers to display when multiple ellipsis are showing. -const PAGES_TO_DISPLAY = PAGE_NEIGHBORS * 2 + 3 -// Total page blocks(page numbers or ellipsis) displayed, including the maximum number of ellipsis (2). -// This gives us maximum number of 7 page blocks to be displayed when the page neighbors value is 1. -const NUM_PAGE_BLOCKS = PAGES_TO_DISPLAY + 2 - -/** - * Builds a list of pages based on how many pages exist and where the user is in their navigation of those pages. - * List result is used to from the buttons that make up the Pagination Widget - */ -export const buildPagedList = ( - numPages: number, - activePage: number, -): (string | number)[] => { - if (numPages > NUM_PAGE_BLOCKS) { - let pages = [] - const leftBound = activePage - PAGE_NEIGHBORS - const rightBound = activePage + PAGE_NEIGHBORS - const beforeLastPage = numPages - 1 - const startPage = leftBound > 2 ? leftBound : 2 - const endPage = rightBound < beforeLastPage ? rightBound : beforeLastPage - - pages = range(startPage, endPage) - - const singleSpillOffset = PAGES_TO_DISPLAY - pages.length - 1 - const hasLeftOverflow = startPage > 2 - const hasRightOverflow = endPage < beforeLastPage - const leftOverflowPage = "left" - const rightOverflowPage = "right" - - if (hasLeftOverflow && !hasRightOverflow) { - const extraPages = range(startPage - singleSpillOffset, startPage - 1) - pages = [leftOverflowPage, ...extraPages, ...pages] - } else if (!hasLeftOverflow && hasRightOverflow) { - const extraPages = range(endPage + 1, endPage + singleSpillOffset) - pages = [...pages, ...extraPages, rightOverflowPage] - } else if (hasLeftOverflow && hasRightOverflow) { - pages = [leftOverflowPage, ...pages, rightOverflowPage] - } - - return [1, ...pages, numPages] - } - - return range(1, numPages) -} - export const PaginationWidget = ({ prevLabel, nextLabel, diff --git a/site/src/components/PaginationWidget/buildPagedList.test.ts b/site/src/components/PaginationWidget/utils.test.ts similarity index 93% rename from site/src/components/PaginationWidget/buildPagedList.test.ts rename to site/src/components/PaginationWidget/utils.test.ts index dbb34bd768048..a37e553a45260 100644 --- a/site/src/components/PaginationWidget/buildPagedList.test.ts +++ b/site/src/components/PaginationWidget/utils.test.ts @@ -1,4 +1,4 @@ -import { buildPagedList } from "./PaginationWidget" +import { buildPagedList } from "./utils" describe("unit/PaginationWidget", () => { describe("buildPagedList", () => { diff --git a/site/src/components/PaginationWidget/utils.ts b/site/src/components/PaginationWidget/utils.ts new file mode 100644 index 0000000000000..ecdb52966316b --- /dev/null +++ b/site/src/components/PaginationWidget/utils.ts @@ -0,0 +1,58 @@ + +/** + * Generates a ranged array with an option to step over values. + * Shamelessly stolen from: + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#sequence_generator_range + */ +const range = (start: number, stop: number, step = 1) => + Array.from({ length: (stop - start) / step + 1 }, (_, i) => start + i * step) + +export const DEFAULT_RECORDS_PER_PAGE = 25 +// Number of pages to the left or right of the current page selection. +const PAGE_NEIGHBORS = 1 +// Number of pages displayed for cases where there are multiple ellipsis showing. This can be +// thought of as the minimum number of page numbers to display when multiple ellipsis are showing. +const PAGES_TO_DISPLAY = PAGE_NEIGHBORS * 2 + 3 +// Total page blocks(page numbers or ellipsis) displayed, including the maximum number of ellipsis (2). +// This gives us maximum number of 7 page blocks to be displayed when the page neighbors value is 1. +const NUM_PAGE_BLOCKS = PAGES_TO_DISPLAY + 2 + +/** + * Builds a list of pages based on how many pages exist and where the user is in their navigation of those pages. + * List result is used to from the buttons that make up the Pagination Widget + */ +export const buildPagedList = ( + numPages: number, + activePage: number, +): (string | number)[] => { + if (numPages > NUM_PAGE_BLOCKS) { + let pages = [] + const leftBound = activePage - PAGE_NEIGHBORS + const rightBound = activePage + PAGE_NEIGHBORS + const beforeLastPage = numPages - 1 + const startPage = leftBound > 2 ? leftBound : 2 + const endPage = rightBound < beforeLastPage ? rightBound : beforeLastPage + + pages = range(startPage, endPage) + + const singleSpillOffset = PAGES_TO_DISPLAY - pages.length - 1 + const hasLeftOverflow = startPage > 2 + const hasRightOverflow = endPage < beforeLastPage + const leftOverflowPage = "left" + const rightOverflowPage = "right" + + if (hasLeftOverflow && !hasRightOverflow) { + const extraPages = range(startPage - singleSpillOffset, startPage - 1) + pages = [leftOverflowPage, ...extraPages, ...pages] + } else if (!hasLeftOverflow && hasRightOverflow) { + const extraPages = range(endPage + 1, endPage + singleSpillOffset) + pages = [...pages, ...extraPages, rightOverflowPage] + } else if (hasLeftOverflow && hasRightOverflow) { + pages = [leftOverflowPage, ...pages, rightOverflowPage] + } + + return [1, ...pages, numPages] + } + + return range(1, numPages) +} From ea126150a231e45b53c3e11fe1b080a2c858a9b3 Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 21 Oct 2022 23:01:50 +0000 Subject: [PATCH 04/30] Format --- site/src/components/PaginationWidget/PageButton.tsx | 2 +- site/src/components/PaginationWidget/utils.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/site/src/components/PaginationWidget/PageButton.tsx b/site/src/components/PaginationWidget/PageButton.tsx index 72b2656a01599..84ae2e56f92c2 100644 --- a/site/src/components/PaginationWidget/PageButton.tsx +++ b/site/src/components/PaginationWidget/PageButton.tsx @@ -16,7 +16,7 @@ export const PageButton = ({ placeholder = "...", numPages, onPageClick, - disabled = false + disabled = false, }: PageButtonProps): JSX.Element => { const styles = useStyles() return ( diff --git a/site/src/components/PaginationWidget/utils.ts b/site/src/components/PaginationWidget/utils.ts index ecdb52966316b..d358936d59e41 100644 --- a/site/src/components/PaginationWidget/utils.ts +++ b/site/src/components/PaginationWidget/utils.ts @@ -1,4 +1,3 @@ - /** * Generates a ranged array with an option to step over values. * Shamelessly stolen from: From 74666ee516d2b3725bbfbd996e27d2746ba7132f Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 21 Oct 2022 23:02:11 +0000 Subject: [PATCH 05/30] Separate pagination - wip --- .../PaginationWidget/PaginationWidget.tsx | 52 ++-- .../pages/WorkspacesPage/WorkspacesPage.tsx | 48 +--- .../WorkspacesPage/WorkspacesPageView.tsx | 18 +- .../workspaces/workspacesXService.ts | 240 +++++++++++++++++- 4 files changed, 279 insertions(+), 79 deletions(-) diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index 1f61156a01df9..8ba4a9bb9727c 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -6,39 +6,48 @@ import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight" import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" import { Maybe } from "components/Conditionals/Maybe" import { CSSProperties } from "react" +import { useSearchParams } from "react-router-dom" import { PageButton } from "./PageButton" import { buildPagedList, DEFAULT_RECORDS_PER_PAGE } from "./utils" export type PaginationWidgetProps = { prevLabel: string nextLabel: string - onPrevClick: () => void - onNextClick: () => void - onPageClick?: (page: number) => void + onPageChange: (offset: number, limit: number) => void numRecordsPerPage?: number numRecords?: number - activePage?: number containerStyle?: CSSProperties } export const PaginationWidget = ({ prevLabel, nextLabel, - onPrevClick, - onNextClick, - onPageClick, + onPageChange, numRecords, numRecordsPerPage = DEFAULT_RECORDS_PER_PAGE, - activePage = 1, containerStyle, }: PaginationWidgetProps): JSX.Element | null => { - const numPages = numRecords ? Math.ceil(numRecords / numRecordsPerPage) : 0 - const firstPageActive = activePage === 1 && numPages !== 0 - const lastPageActive = activePage === numPages && numPages !== 0 const theme = useTheme() const isMobile = useMediaQuery(theme.breakpoints.down("sm")) const styles = useStyles() + const [searchParams, setSearchParams] = useSearchParams() + const currentPage = searchParams.get("page") + ? Number(searchParams.get("page")) + : 1 + + const numPages = numRecords ? Math.ceil(numRecords / numRecordsPerPage) : 0 + const firstPageActive = currentPage === 1 && numPages !== 0 + const lastPageActive = currentPage === numPages && numPages !== 0 + + const changePage = (newPage: number) => { + // change the page in the url + setSearchParams({ page: newPage.toString() }) + // fetch new page of records + const offset = (newPage - 1) * numRecordsPerPage + onPageChange(offset, numRecordsPerPage) + } + // No need to display any pagination if we know the number of pages is 1 if (numPages === 1 || numRecords === 0) { return null @@ -50,7 +59,7 @@ export const PaginationWidget = ({ className={styles.prevLabelStyles} aria-label="Previous page" disabled={firstPageActive} - onClick={onPrevClick} + onClick={() => changePage(currentPage - 1)} >
{prevLabel}
@@ -59,26 +68,22 @@ export const PaginationWidget = ({ - {buildPagedList(numPages, activePage).map((page) => + {buildPagedList(numPages, currentPage).map((page) => typeof page !== "number" ? ( - + ) : ( changePage(page)} /> ), )} @@ -88,7 +93,7 @@ export const PaginationWidget = ({ - 0}> + - {buildPagedList(numPages, currentPage).map((page) => + {numPages && buildPagedList(numPages, currentPage).map((page) => typeof page !== "number" ? ( Date: Thu, 27 Oct 2022 16:24:03 +0000 Subject: [PATCH 26/30] fix stories --- site/src/pages/UsersPage/UsersPageView.stories.tsx | 13 +++++++++---- site/src/testHelpers/entities.ts | 5 +++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/site/src/pages/UsersPage/UsersPageView.stories.tsx b/site/src/pages/UsersPage/UsersPageView.stories.tsx index ed8ee67f81324..e4ccccc3af955 100644 --- a/site/src/pages/UsersPage/UsersPageView.stories.tsx +++ b/site/src/pages/UsersPage/UsersPageView.stories.tsx @@ -1,6 +1,7 @@ import { ComponentMeta, Story } from "@storybook/react" +import { createPaginationRef } from "components/PaginationWidget/utils" import { - MockSiteRoles, + MockAssignableSiteRoles, MockUser, MockUser2, } from "../../testHelpers/renderHelpers" @@ -9,6 +10,11 @@ import { UsersPageView, UsersPageViewProps } from "./UsersPageView" export default { title: "pages/UsersPageView", component: UsersPageView, + argTypes: { + paginationRef: { + defaultValue: createPaginationRef({ page: 1, limit: 25 }) + } + } } as ComponentMeta const Template: Story = (args) => ( @@ -18,8 +24,7 @@ const Template: Story = (args) => ( export const Admin = Template.bind({}) Admin.args = { users: [MockUser, MockUser2], - roles: MockSiteRoles, - canCreateUser: true, + roles: MockAssignableSiteRoles, canEditUsers: true, } @@ -32,7 +37,7 @@ SmallViewport.parameters = { } export const Member = Template.bind({}) -Member.args = { ...Admin.args, canCreateUser: false, canEditUsers: false } +Member.args = { ...Admin.args, canEditUsers: false } export const Empty = Template.bind({}) Empty.args = { ...Admin.args, users: [] } diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index d02f8bfd5b60f..444cb180e7189 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -48,8 +48,6 @@ export const MockAuditorRole: TypesGen.Role = { display_name: "Auditor", } -export const MockSiteRoles = [MockUserAdminRole, MockAuditorRole] - // assignableRole takes a role and a boolean. The boolean implies if the // actor can assign (add/remove) the role from other users. export function assignableRole( @@ -62,6 +60,9 @@ export function assignableRole( } } +export const MockSiteRoles = [MockUserAdminRole, MockAuditorRole] +export const MockAssignableSiteRoles = [assignableRole(MockUserAdminRole, true), assignableRole(MockAuditorRole, true)] + export const MockMemberPermissions = { viewAuditLog: false, } From 50c5825114f7c3a95c95c267a7553d4a612dc9cd Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Thu, 27 Oct 2022 16:51:40 +0000 Subject: [PATCH 27/30] Fix api helper --- site/src/api/api.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 0ae81552d78eb..90511a582b4cd 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -270,19 +270,22 @@ interface SearchParamOptions extends TypesGen.Pagination { export const getURLWithSearchParams = ( basePath: string, - options: SearchParamOptions + options?: SearchParamOptions ): string => { - const searchParams = new URLSearchParams() - - const keys = Object.keys(options) as (keyof SearchParamOptions)[] - keys.forEach((key) => { - const value = options[key] ?? "" - searchParams.append(key, value.toString()) - }) - - const searchString = searchParams.toString() - - return searchString ? `${basePath}?${searchString}` : basePath + if (options) { + const searchParams = new URLSearchParams() + const keys = Object.keys(options) as (keyof SearchParamOptions)[] + keys.forEach((key) => { + const value = options[key] + if (value !== undefined && value !== "") { + searchParams.append(key, value.toString()) + } + }) + const searchString = searchParams.toString() + return searchString ? `${basePath}?${searchString}` : basePath + } else { + return basePath + } } export const getWorkspaces = async ( From 2e249a0aa96748b029e857c9bbb8a9b48f8833bf Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Thu, 27 Oct 2022 17:11:27 +0000 Subject: [PATCH 28/30] Add test --- site/src/pages/UsersPage/UsersPage.test.tsx | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/site/src/pages/UsersPage/UsersPage.test.tsx b/site/src/pages/UsersPage/UsersPage.test.tsx index a15267ffd9822..6aceb1e3aa764 100644 --- a/site/src/pages/UsersPage/UsersPage.test.tsx +++ b/site/src/pages/UsersPage/UsersPage.test.tsx @@ -197,6 +197,8 @@ describe("UsersPage", () => { expect(users.length).toEqual(3) }) + + describe("suspend user", () => { describe("when it is success", () => { it("shows a success message and refresh the page", async () => { @@ -238,6 +240,28 @@ describe("UsersPage", () => { }) }) + describe("pagination", () => { + it("goes to next and previous page", async () => { + renderPage() + const user = userEvent.setup() + + const mock = jest + .spyOn(API, "getUsers") + .mockResolvedValueOnce([MockUser, MockUser2]) + + const nextButton = await screen.findByLabelText("Next page") + await user.click(nextButton) + + await waitFor(() => expect(API.getUsers).toBeCalledWith({ offset: 25, limit: 25, q: "" })) + + mock.mockClear() + const previousButton = await screen.findByLabelText("Previous page") + await user.click(previousButton) + + await waitFor(() => expect(API.getUsers).toBeCalledWith({ offset: 0, limit: 25, q: "" })) + }) + }) + describe("delete user", () => { describe("when it is success", () => { it("shows a success message and refresh the page", async () => { From 953428baa29102ea3612c2c93f0cf34214d635b7 Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Thu, 27 Oct 2022 17:11:51 +0000 Subject: [PATCH 29/30] Format --- site/src/api/api.ts | 2 +- .../PaginationWidget/PaginationWidget.tsx | 43 ++++++++++--------- site/src/pages/UsersPage/UsersPage.test.tsx | 10 +++-- .../pages/UsersPage/UsersPageView.stories.tsx | 6 +-- site/src/testHelpers/entities.ts | 5 ++- 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 90511a582b4cd..3804e83aed2aa 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -270,7 +270,7 @@ interface SearchParamOptions extends TypesGen.Pagination { export const getURLWithSearchParams = ( basePath: string, - options?: SearchParamOptions + options?: SearchParamOptions, ): string => { if (options) { const searchParams = new URLSearchParams() diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index 796407588452c..19d56ff195a26 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -34,12 +34,14 @@ export const PaginationWidget = ({ const currentPage = paginationState.context.page const numRecordsPerPage = paginationState.context.limit - const numPages = numRecords ? Math.ceil(numRecords / numRecordsPerPage) : undefined + const numPages = numRecords + ? Math.ceil(numRecords / numRecordsPerPage) + : undefined const firstPageActive = currentPage === 1 && numPages !== 0 const lastPageActive = currentPage === numPages && numPages !== 0 // No need to display any pagination if we know the number of pages is 1 or 0 - if (numPages && numPages <= 1 || numRecords === 0) { + if ((numPages && numPages <= 1) || numRecords === 0) { return null } @@ -64,24 +66,25 @@ export const PaginationWidget = ({ /> - {numPages && buildPagedList(numPages, currentPage).map((page) => - typeof page !== "number" ? ( - - ) : ( - send({ type: "GO_TO_PAGE", page })} - /> - ), - )} + {numPages && + buildPagedList(numPages, currentPage).map((page) => + typeof page !== "number" ? ( + + ) : ( + send({ type: "GO_TO_PAGE", page })} + /> + ), + )} diff --git a/site/src/pages/UsersPage/UsersPage.test.tsx b/site/src/pages/UsersPage/UsersPage.test.tsx index 6aceb1e3aa764..766581ca2dcf2 100644 --- a/site/src/pages/UsersPage/UsersPage.test.tsx +++ b/site/src/pages/UsersPage/UsersPage.test.tsx @@ -197,8 +197,6 @@ describe("UsersPage", () => { expect(users.length).toEqual(3) }) - - describe("suspend user", () => { describe("when it is success", () => { it("shows a success message and refresh the page", async () => { @@ -252,13 +250,17 @@ describe("UsersPage", () => { const nextButton = await screen.findByLabelText("Next page") await user.click(nextButton) - await waitFor(() => expect(API.getUsers).toBeCalledWith({ offset: 25, limit: 25, q: "" })) + await waitFor(() => + expect(API.getUsers).toBeCalledWith({ offset: 25, limit: 25, q: "" }), + ) mock.mockClear() const previousButton = await screen.findByLabelText("Previous page") await user.click(previousButton) - await waitFor(() => expect(API.getUsers).toBeCalledWith({ offset: 0, limit: 25, q: "" })) + await waitFor(() => + expect(API.getUsers).toBeCalledWith({ offset: 0, limit: 25, q: "" }), + ) }) }) diff --git a/site/src/pages/UsersPage/UsersPageView.stories.tsx b/site/src/pages/UsersPage/UsersPageView.stories.tsx index e4ccccc3af955..93b06cee66f57 100644 --- a/site/src/pages/UsersPage/UsersPageView.stories.tsx +++ b/site/src/pages/UsersPage/UsersPageView.stories.tsx @@ -12,9 +12,9 @@ export default { component: UsersPageView, argTypes: { paginationRef: { - defaultValue: createPaginationRef({ page: 1, limit: 25 }) - } - } + defaultValue: createPaginationRef({ page: 1, limit: 25 }), + }, + }, } as ComponentMeta const Template: Story = (args) => ( diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 444cb180e7189..c096a4c45dad7 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -61,7 +61,10 @@ export function assignableRole( } export const MockSiteRoles = [MockUserAdminRole, MockAuditorRole] -export const MockAssignableSiteRoles = [assignableRole(MockUserAdminRole, true), assignableRole(MockAuditorRole, true)] +export const MockAssignableSiteRoles = [ + assignableRole(MockUserAdminRole, true), + assignableRole(MockAuditorRole, true), +] export const MockMemberPermissions = { viewAuditLog: false, From 9056c44388454cdbb0bea693592bea790370832e Mon Sep 17 00:00:00 2001 From: Presley Pizzo Date: Fri, 28 Oct 2022 15:23:28 +0000 Subject: [PATCH 30/30] Make widget show all the time to avoid blink --- site/src/components/PaginationWidget/PaginationWidget.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/site/src/components/PaginationWidget/PaginationWidget.tsx b/site/src/components/PaginationWidget/PaginationWidget.tsx index 19d56ff195a26..e3765e524a398 100644 --- a/site/src/components/PaginationWidget/PaginationWidget.tsx +++ b/site/src/components/PaginationWidget/PaginationWidget.tsx @@ -40,11 +40,6 @@ export const PaginationWidget = ({ const firstPageActive = currentPage === 1 && numPages !== 0 const lastPageActive = currentPage === numPages && numPages !== 0 - // No need to display any pagination if we know the number of pages is 1 or 0 - if ((numPages && numPages <= 1) || numRecords === 0) { - return null - } - return (