From c4269d25d3ce5a3f59c2fa42a96b2adf8c995539 Mon Sep 17 00:00:00 2001 From: Jacob Fletcher Date: Sat, 16 Nov 2024 14:05:50 -0500 Subject: [PATCH] fix(next): custom default root views (#9247) Fixes #9246. Custom default root views (account and dashboard) were not being properly thread to the custom component renderer. Custom account views were also improperly _stacking_ instead of _replacing_ the default view. Tests for this are incoming. To properly test this we need to wrap our default root views with custom ones, so that out existing `admin` test suite can continue to work alongside tests specifically for this issue. --- packages/next/src/views/Account/index.tsx | 10 +++------- packages/next/src/views/Dashboard/index.tsx | 4 +--- .../src/bin/generateImportMap/parsePayloadComponent.ts | 1 + 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/next/src/views/Account/index.tsx b/packages/next/src/views/Account/index.tsx index 961235a2b..49608f61d 100644 --- a/packages/next/src/views/Account/index.tsx +++ b/packages/next/src/views/Account/index.tsx @@ -37,11 +37,7 @@ export const Account: React.FC = async ({ } = initPageResult const { - admin: { - components: { views: { Account: CustomAccountComponent } = {} } = {}, - theme, - user: userSlug, - }, + admin: { theme, user: userSlug }, routes: { api }, serverURL, } = config @@ -142,7 +138,8 @@ export const Account: React.FC = async ({ /> = async ({ user, }} /> - diff --git a/packages/next/src/views/Dashboard/index.tsx b/packages/next/src/views/Dashboard/index.tsx index b342813c4..9171472a3 100644 --- a/packages/next/src/views/Dashboard/index.tsx +++ b/packages/next/src/views/Dashboard/index.tsx @@ -31,8 +31,6 @@ export const Dashboard: React.FC = async ({ visibleEntities, } = initPageResult - const CustomDashboardComponent = config.admin.components?.views?.Dashboard - const collections = config.collections.filter( (collection) => permissions?.collections?.[collection.slug]?.read && @@ -115,7 +113,7 @@ export const Dashboard: React.FC = async ({ Link, locale, }} - Component={CustomDashboardComponent} + Component={config.admin?.components?.views?.Dashboard?.Component} Fallback={DefaultDashboard} importMap={payload.importMap} serverProps={{ diff --git a/packages/payload/src/bin/generateImportMap/parsePayloadComponent.ts b/packages/payload/src/bin/generateImportMap/parsePayloadComponent.ts index 5747f0fb0..03964eb7d 100644 --- a/packages/payload/src/bin/generateImportMap/parsePayloadComponent.ts +++ b/packages/payload/src/bin/generateImportMap/parsePayloadComponent.ts @@ -7,6 +7,7 @@ export function parsePayloadComponent(PayloadComponent: PayloadComponent): { if (!PayloadComponent) { return null } + const pathAndMaybeExport = typeof PayloadComponent === 'string' ? PayloadComponent : PayloadComponent.path