From a2429cf61d5d09c229ba089804675a97a6eadfeb Mon Sep 17 00:00:00 2001 From: Gautam Singh <5769869+gautamsi@users.noreply.github.com> Date: Sun, 23 Jun 2024 14:36:45 -0500 Subject: [PATCH] wip --- eslint.config.js | 1 + .../admin-ui/pages/App/index.tsx | 18 +++--- .../admin-ui/pages/CreateItemPage/index.tsx | 11 ++-- .../admin-ui/pages/HomePage/index.tsx | 19 ++++-- .../admin-ui/pages/ItemPage/index.tsx | 16 +++-- .../pages/ListPage/FieldSelection.tsx | 36 +++++++---- .../admin-ui/pages/ListPage/SortSelection.tsx | 13 +++- .../admin-ui/pages/ListPage/index.tsx | 41 +++++++++---- .../admin-ui/pages/ListPage/useFilters.tsx | 10 +++- .../pages/ListPage/useSelectedFields.tsx | 10 +++- .../admin-ui/pages/ListPage/useSort.tsx | 10 +++- .../core/src/admin-ui/admin-meta-graphql.ts | 6 ++ .../src/admin-ui/components/Navigation.tsx | 10 ++-- .../src/admin-ui/components/Pagination.tsx | 20 ++++++- packages/core/src/admin-ui/context.tsx | 9 +++ packages/core/src/admin-ui/router.tsx | 3 +- .../src/admin-ui/system/generateAdminUI.ts | 59 +++---------------- packages/core/src/admin-ui/templates/app.ts | 58 ++++++++++++++---- .../src/admin-ui/templates/create-item.ts | 6 +- packages/core/src/admin-ui/templates/home.ts | 3 +- packages/core/src/admin-ui/templates/index.ts | 34 ++++------- packages/core/src/admin-ui/templates/item.tsx | 6 +- packages/core/src/admin-ui/templates/list.tsx | 6 +- .../src/admin-ui/utils/useLazyMetadata.tsx | 3 + .../admin-ui/utils/usePreventNavigation.tsx | 55 ++++++++++------- packages/core/src/lib/admin-meta-resolver.ts | 15 +++++ packages/core/src/lib/create-admin-meta.ts | 4 +- packages/core/src/lib/createSystem.ts | 7 ++- packages/core/src/scripts/dev.ts | 2 +- packages/core/src/types/admin-meta.ts | 1 + packages/core/src/types/config/index.ts | 6 +- pnpm-lock.yaml | 25 ++++---- 32 files changed, 322 insertions(+), 201 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 68370173174..3dfad4ee69b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,6 +7,7 @@ module.exports = tseslint.config( { ignores: [ '**/.keystone/', + '**/.next/', '**/dist/', '**/node_modules/', '**/syntax-error.js', diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.tsx index 49d0da8982c..463bfed85a6 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/App/index.tsx @@ -1,11 +1,15 @@ import React from 'react' import { Core } from '@keystone-ui/core' -import { type AppProps } from 'next/app' import { type DocumentNode } from 'graphql' import { type AdminConfig, type FieldViews } from '../../../../types' import { ErrorBoundary } from '../../../../admin-ui/components' import { KeystoneProvider } from '../../../../admin-ui/context' +type AdminProps = { + children: React.ReactNode + config: AppConfig +} + type AppConfig = { adminConfig: AdminConfig adminMetaHash: string @@ -14,16 +18,14 @@ type AppConfig = { apiPath: string } -export const getApp = - (props: AppConfig) => - ({ Component, pageProps }: AppProps) => { - return ( +export function Layout ({ children, config }: AdminProps) { + return ( - + - + {children} ) - } + } \ No newline at end of file diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx index e437e65af8f..56dea57730a 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/CreateItemPage/index.tsx @@ -4,7 +4,7 @@ import { Box, jsx } from '@keystone-ui/core' import { LoadingDots } from '@keystone-ui/loading' import { Button } from '@keystone-ui/button' -import { useRouter } from 'next/router' +import { useRouter } from 'next/navigation' import { Fields } from '../../../../admin-ui/utils' import { PageContainer } from '../../../../admin-ui/components/PageContainer' import { useKeystone, useList } from '../../../../admin-ui' @@ -45,13 +45,10 @@ function CreatePageForm (props: { list: ListMeta }) { ) } -type CreateItemPageProps = { listKey: string } +type CreateItemPageProps = { params: { listKey: string } } -export const getCreateItemPage = (props: CreateItemPageProps) => () => - - -function CreateItemPage (props: CreateItemPageProps) { - const list = useList(props.listKey) +export function CreateItemPage ({ params }: CreateItemPageProps) { + const list = useList(params.listKey) const { createViewFieldModes } = useKeystone() return ( diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx index c64ab913080..9ec0e23b4ff 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/HomePage/index.tsx @@ -16,10 +16,12 @@ import { Link, type LinkProps } from '../../../../admin-ui/router' function ListCard ({ listKey, count, - hideCreate + hideCreate, + basePath, }: { listKey: string hideCreate: boolean + basePath: string count: | { type: 'success', count: number } | { type: 'no-access' } @@ -31,7 +33,7 @@ function ListCard ({ return (
{hideCreate === false && !list.isSingleton && ( - + Create {list.singular} @@ -106,7 +108,7 @@ function CreateButton (props: LinkProps) { export function HomePage () { const { - adminMeta: { lists }, + adminMeta: { lists, config }, visibleLists, } = useKeystone() const query = useMemo( @@ -114,6 +116,9 @@ export function HomePage () { query { keystone { adminMeta { + config { + adminPath + } lists { key hideCreate @@ -158,10 +163,11 @@ export function HomePage () { ) } return Object.keys(lists).map(key => { - if (!visibleLists.lists.has(key)) { + const list = lists[key] + if (!visibleLists.lists.has(list.key)) { return null } - const result = dataGetter.get(key) + const result = dataGetter.get(list.key) return ( ) }) diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx index b5f3d46cd42..ebe8366d26d 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ItemPage/index.tsx @@ -45,7 +45,10 @@ import { CreateButtonLink } from '../../../../admin-ui/components/CreateButtonLi import { BaseToolbar, ColumnLayout, ItemPageHeader } from './common' type ItemPageProps = { - listKey: string + params: { + id: string + listKey: string + } } function useEventCallback any>(callback: Func): Func { @@ -330,11 +333,9 @@ function DeleteButton ({ ) } -export const getItemPage = (props: ItemPageProps) => () => - -function ItemPage ({ listKey }: ItemPageProps) { - const list = useList(listKey) - const id = useRouter().query.id as string +export function ItemPage ({ params }: ItemPageProps) { + const list = useList(params?.listKey) + const id = params?.id as string const { query, selectedFields } = useMemo(() => { const selectedFields = Object.entries(list.fields) @@ -385,6 +386,9 @@ function ItemPage ({ listKey }: ItemPageProps) { item: ItemData keystone: { adminMeta: { + config: { + adminPath: string + } list: { fields: { path: string diff --git a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/FieldSelection.tsx b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/FieldSelection.tsx index fcfd317dfba..4f6fb63a66d 100644 --- a/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/FieldSelection.tsx +++ b/packages/core/src/___internal-do-not-use-will-break-in-patch/admin-ui/pages/ListPage/FieldSelection.tsx @@ -5,7 +5,7 @@ import { Box, jsx } from '@keystone-ui/core' import { ChevronDownIcon } from '@keystone-ui/icons/icons/ChevronDownIcon' import { Options, OptionPrimitive, CheckMark } from '@keystone-ui/options' import { Popover } from '@keystone-ui/popover' -import { useRouter } from 'next/router' +import { usePathname, useRouter, useSearchParams } from 'next/navigation' import { type ListMeta } from '../../../../types' import { useSelectedFields } from './useSelectedFields' @@ -19,7 +19,7 @@ function isArrayEqual (arrA: string[], arrB: string[]) { return true } -const Option: typeof OptionPrimitive = props => { +const Option: typeof OptionPrimitive = (props) => { return ( {props.children} @@ -33,7 +33,9 @@ const Option: typeof OptionPrimitive = props => { } // TODO: return type required by pnpm :( -export const fieldSelectionOptionsComponents: Parameters[0]['components'] = { +export const fieldSelectionOptionsComponents: Parameters< + typeof Options +>[0]['components'] = { Option, } @@ -45,18 +47,26 @@ export function FieldSelection ({ fieldModesByFieldPath: Record }) { const router = useRouter() + const pathname = usePathname() + const searchParams = useSearchParams() + + // Create a query object that behaves like the old query object + const query = {} + for (let [key, value] of searchParams.entries()) { + query[key] = value + } const selectedFields = useSelectedFields(list, fieldModesByFieldPath) const setNewSelectedFields = (selectedFields: string[]) => { if (isArrayEqual(selectedFields, list.initialColumns)) { - const { fields: _ignore, ...otherQueryFields } = router.query + const { fields: _ignore, ...otherQueryFields } = query router.push({ query: otherQueryFields }) } else { - router.push({ query: { ...router.query, fields: selectedFields.join(',') } }) + router.push({ query: { ...query, fields: selectedFields.join(',') } }) } } const fields: { value: string, label: string, isDisabled: boolean }[] = [] - Object.keys(fieldModesByFieldPath).forEach(fieldPath => { + Object.keys(fieldModesByFieldPath).forEach((fieldPath) => { if (fieldModesByFieldPath[fieldPath] === 'read') { fields.push({ value: fieldPath, @@ -72,7 +82,13 @@ export function FieldSelection ({ triggerRenderer={({ triggerProps }) => { return (