From bf9e4ff87db4840922e2d8b02f1f7feba512a789 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 23 Feb 2024 11:03:41 -0600 Subject: [PATCH] move libs/pagination too and get rid of @oxide/pagination alias --- .prettierrc.js | 1 + app/layouts/helpers.tsx | 2 +- .../__tests__/use-pagination.spec.ts | 0 {libs => app}/pagination/index.tsx | 0 app/table/QueryTable.tsx | 3 +- libs/pagination/Pagination.tsx | 57 ------------------- tsconfig.json | 4 +- 7 files changed, 6 insertions(+), 61 deletions(-) rename {libs => app}/pagination/__tests__/use-pagination.spec.ts (100%) rename {libs => app}/pagination/index.tsx (100%) delete mode 100644 libs/pagination/Pagination.tsx diff --git a/.prettierrc.js b/.prettierrc.js index 0a64eadc10..dbce9f0a1d 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -18,6 +18,7 @@ export default { '', '^@oxide/(.*)$', '', + '^~/(.*)$', '^app/(.*)$', '', '^[./]', diff --git a/app/layouts/helpers.tsx b/app/layouts/helpers.tsx index c2e8aed343..5be7c6880b 100644 --- a/app/layouts/helpers.tsx +++ b/app/layouts/helpers.tsx @@ -8,10 +8,10 @@ import { useRef } from 'react' import { Outlet } from 'react-router-dom' -import { Pagination } from '@oxide/pagination' import { SkipLinkTarget } from '@oxide/ui' import { classed } from '@oxide/util' +import { Pagination } from '~/pagination' import { PageActionsTarget } from 'app/components/PageActions' import { useScrollRestoration } from 'app/hooks/use-scroll-restoration' diff --git a/libs/pagination/__tests__/use-pagination.spec.ts b/app/pagination/__tests__/use-pagination.spec.ts similarity index 100% rename from libs/pagination/__tests__/use-pagination.spec.ts rename to app/pagination/__tests__/use-pagination.spec.ts diff --git a/libs/pagination/index.tsx b/app/pagination/index.tsx similarity index 100% rename from libs/pagination/index.tsx rename to app/pagination/index.tsx diff --git a/app/table/QueryTable.tsx b/app/table/QueryTable.tsx index f0851fd50a..c028b267c9 100644 --- a/app/table/QueryTable.tsx +++ b/app/table/QueryTable.tsx @@ -31,10 +31,11 @@ import { type Result, type ResultItem, } from '@oxide/api' -import { Pagination, usePagination } from '@oxide/pagination' import { EmptyMessage, TableEmptyBox } from '@oxide/ui' import { invariant, isOneOf } from '@oxide/util' +import { Pagination, usePagination } from '~/pagination' + import { DefaultCell } from './cells' import { getActionsCol, getMultiSelectCol, getSelectCol, type MakeActions } from './columns' import { Table } from './Table' diff --git a/libs/pagination/Pagination.tsx b/libs/pagination/Pagination.tsx deleted file mode 100644 index 175ccfe712..0000000000 --- a/libs/pagination/Pagination.tsx +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - * - * Copyright Oxide Computer Company - */ -import { useState } from 'react' -import tunnel from 'tunnel-rat' - -import { - Pagination as UIPagination, - type PaginationProps as UIPaginationProps, -} from '@oxide/ui' - -const Tunnel = tunnel('pagination') - -interface PaginationProps extends UIPaginationProps { - /** If true pagination will be rendered wherever `Pagination.Target` is included */ - inline?: boolean -} -export function Pagination({ inline = false, ...props }: PaginationProps) { - if (inline) return - - return ( - - - - ) -} - -Pagination.Target = Tunnel.Out - -type PageToken = string | undefined - -export function usePagination() { - const [prevPages, setPrevPages] = useState([]) - const [currentPage, setCurrentPage] = useState() - - const goToPrevPage = () => { - const prevPage = prevPages.pop() - setCurrentPage(prevPage) - setPrevPages(prevPages) - } - - const goToNextPage = (nextPageToken: string) => { - setPrevPages([...prevPages, currentPage]) - setCurrentPage(nextPageToken) - } - - return { - currentPage, - goToNextPage, - goToPrevPage, - hasPrev: prevPages.length > 0, - } -} diff --git a/tsconfig.json b/tsconfig.json index eb00553393..69b8fc99bd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,14 +12,14 @@ "noEmit": true, "outDir": "dist", "paths": { + "~/*": ["app/*"], "app/*": ["app/*"], "@oxide/gen/*": ["libs/api/__generated__/*"], "@oxide/api": ["libs/api/index.ts"], "@oxide/api-mocks": ["libs/api-mocks/index.ts"], "@oxide/ui": ["libs/ui/index.ts"], "@oxide/util": ["libs/util/index.ts"], - "@oxide/table": ["app/table/index.ts"], - "@oxide/pagination": ["libs/pagination/index.tsx"] + "@oxide/table": ["app/table/index.ts"] }, "resolveJsonModule": true, "rootDir": ".",