File tree Expand file tree Collapse file tree
components/views/CustomCollectionView Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -282,7 +282,11 @@ export const RootPage = async ({
282282 clientProps : {
283283 browseByFolderSlugs,
284284 clientConfig,
285+ collectionSlug : collectionConfig ?. slug ,
286+ docID : routeParams . id ,
285287 documentSubViewType,
288+ folderID,
289+ globalSlug : globalConfig ?. slug ,
286290 viewType,
287291 } satisfies AdminViewClientProps ,
288292 Component : DefaultView . payloadComponent ,
Original file line number Diff line number Diff line change @@ -34,7 +34,11 @@ export type AdminViewConfig = {
3434export type AdminViewClientProps = {
3535 browseByFolderSlugs ?: SanitizedCollectionConfig [ 'slug' ] [ ]
3636 clientConfig : ClientConfig
37+ collectionSlug ?: SanitizedCollectionConfig [ 'slug' ]
38+ docID ?: number | string
3739 documentSubViewType ?: DocumentSubViewTypes
40+ folderID ?: number | string
41+ globalSlug ?: SanitizedGlobalConfig [ 'slug' ]
3842 viewType : ViewTypes
3943}
4044
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ export const CustomCollectionView: CollectionConfig = {
1212 path : '/grid' ,
1313 exact : true ,
1414 } ,
15+ gridClient : {
16+ Component : '/components/views/CustomCollectionView/Client.js#CustomCollectionViewClient' ,
17+ path : '/grid-client' ,
18+ exact : true ,
19+ } ,
1520 } ,
1621 } ,
1722 } ,
Original file line number Diff line number Diff line change 1+ 'use client'
2+ import type { AdminViewClientProps } from 'payload'
3+
4+ import { useConfig } from '@payloadcms/ui'
5+ import React from 'react'
6+
7+ import { customCollectionViewClientTitle } from '../../../shared.js'
8+
9+ export function CustomCollectionViewClient ( { collectionSlug } : AdminViewClientProps ) {
10+ const { getEntityConfig } = useConfig ( )
11+
12+ if ( ! collectionSlug ) {
13+ return null
14+ }
15+
16+ const clientCollectionConfig = getEntityConfig ( { collectionSlug } )
17+
18+ if ( ! clientCollectionConfig ) {
19+ return null
20+ }
21+
22+ const { labels } = clientCollectionConfig
23+
24+ return (
25+ < div
26+ style = { {
27+ marginTop : 'calc(var(--base) * 2)' ,
28+ paddingLeft : 'var(--gutter-h)' ,
29+ paddingRight : 'var(--gutter-h)' ,
30+ } }
31+ >
32+ < h1 id = "custom-collection-view-client-title" > { customCollectionViewClientTitle } </ h1 >
33+ < p id = "custom-collection-view-client-slug" > { clientCollectionConfig . slug } </ p >
34+ < p id = "custom-collection-view-client-label" > { String ( labels ?. plural ) } </ p >
35+ </ div >
36+ )
37+ }
Original file line number Diff line number Diff line change @@ -783,6 +783,22 @@ describe('General', () => {
783783 'Custom Collection View' ,
784784 )
785785 } )
786+
787+ test ( 'should render custom collection view as a client component' , async ( ) => {
788+ await page . goto (
789+ formatAdminURL ( {
790+ adminRoute,
791+ path : '/collections/custom-collection-view/grid-client' ,
792+ serverURL,
793+ } ) ,
794+ )
795+ await expect ( page . locator ( 'h1#custom-collection-view-client-title' ) ) . toContainText (
796+ 'Custom Collection View (Client)' ,
797+ )
798+ await expect ( page . locator ( '#custom-collection-view-client-slug' ) ) . toContainText (
799+ 'custom-collection-view' ,
800+ )
801+ } )
786802 } )
787803
788804 describe ( 'header actions' , ( ) => {
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ export const customViewTitle = 'Custom View'
2020
2121export const customCollectionViewTitle = 'Custom Collection View'
2222
23+ export const customCollectionViewClientTitle = 'Custom Collection View (Client)'
24+
2325export const customParamViewTitle = 'Custom Param View'
2426
2527export const customNestedViewTitle = 'Custom Nested View'
You can’t perform that action at this time.
0 commit comments