feat(next): support custom collection-level views#1
Conversation
- Update CollectionAdminOptions type to allow custom views at collection level - Create getCustomCollectionViewByRoute helper function - Modify getRouteData.ts to check for custom collection views before defaulting to edit views - Add test collection with custom grid view - Add test to verify custom collection view routing Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
- Add null check for views object - Change viewKey return value from null to undefined for consistency - Address code cleanliness issues Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
robinscholz
left a comment
There was a problem hiding this comment.
I believe the folders logic should take precedence over any custom views we add. So getRouteData would need to be updated slightly to reflect this.
Reordered the routing logic so that folder views are checked before custom collection views. Order is now: trash → folders → custom views → edit views Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
Updated in commit 88cfdb7. The routing logic now checks folders before custom views, ensuring built-in features maintain priority. Order is now: trash → folders → custom views → edit views |
robinscholz
left a comment
There was a problem hiding this comment.
Have you ran tests? I get the following error:
@payloadcms/plugin-search:build: src/Search/index.ts:74:13 - error TS2322: Type '{ list: { actions: { path: string; serverProps: { collectionLabels: CollectionLabels; searchCollections: string[]; searchSlug: string; }; }[]; }; }' is not assignable to type '{ [key: string]: AdminViewConfig; edit?: EditConfig | undefined; list?: { actions?: CustomComponent[] | undefined; Component?: PayloadComponent | undefined; } | undefined; }'.
@payloadcms/plugin-search:build: Property 'list' is incompatible with index signature.
@payloadcms/plugin-search:build: Object literal may only specify known properties, and 'actions' does not exist in type 'AdminViewConfig'.
@payloadcms/plugin-search:build:
@payloadcms/plugin-search:build: 74 actions: [
@payloadcms/plugin-search:build: ~~~~~~~
@payloadcms/plugin-search:build:
@payloadcms/plugin-search:build:
@payloadcms/plugin-search:build: Found 1 error in src/Search/index.ts:74
@payloadcms/plugin-search:build:
@payloadcms/plugin-search:build: ELIFECYCLE Command failed with exit code 2.
@payloadcms/plugin-search:build: ELIFECYCLE Command failed with exit code 2.
…inition Changed the index signature to use a union type that includes undefined, allowing it to be compatible with optional properties like edit and list. This fixes the build error in @payloadcms/plugin-search and other packages. Co-authored-by: robinscholz <8195463+robinscholz@users.noreply.github.com>
Fixed in commit 55bad88. The index signature now uses a union type that includes Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
This PR adds support for custom collection-level views in Payload CMS, resolving issue payloadcms#15386.
Changes
Implementation Details
Type Changes (
packages/payload/src/collections/config/types.ts)Added index signature with union type
[key: string]: AdminViewConfig | EditConfig | { actions?: CustomComponent[]; Component?: PayloadComponent } | undefinedto allow custom views at the collection level while maintaining compatibility with existingeditandlistproperties.Routing Order
The routing logic checks in this priority order:
/collections/:slug/trash/collections/:slug/:folderSlug(built-in feature)/collections/:slug/:customPath(NEW)/collections/:slug/:idor/collections/:slug/createThis ensures built-in features like folders maintain priority over custom views.
Routing Logic (
packages/next/src/views/Root/getRouteData.ts)Added check for custom collection views, positioned after folders but before edit views.
Helper Function (
packages/next/src/views/Root/getCustomCollectionViewByRoute.ts)Created helper to find custom collection views by matching the current route against configured view paths, skipping known view types (
editandlist).Example Usage
Accessible at:
/collections/media/gridSecurity
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.