Skip to content

feat(next): support custom collection-level views#1

Merged
robinscholz merged 7 commits into
mainfrom
copilot/fix-issue-15386
Jan 29, 2026
Merged

feat(next): support custom collection-level views#1
robinscholz merged 7 commits into
mainfrom
copilot/fix-issue-15386

Conversation

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown

Summary

This PR adds support for custom collection-level views in Payload CMS, resolving issue payloadcms#15386.

Changes

  • Update CollectionAdminOptions type to allow custom views at collection level
  • Create helper function to check for custom collection views by route
  • Modify getRouteData.ts to check for custom collection views before defaulting to edit views
  • Add test collection with custom grid view
  • Add E2E test to verify routing works
  • Fix TypeScript errors
  • Address code review feedback
  • Run security scan (no issues)
  • Ensure folders take precedence over custom views
  • Fix TypeScript build errors in dependent packages

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 } | undefined to allow custom views at the collection level while maintaining compatibility with existing edit and list properties.

Routing Order

The routing logic checks in this priority order:

  1. Trash views - /collections/:slug/trash
  2. Folder views - /collections/:slug/:folderSlug (built-in feature)
  3. Custom collection views - /collections/:slug/:customPath (NEW)
  4. Edit views - /collections/:slug/:id or /collections/:slug/create

This 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 (edit and list).

Example Usage

const mediaCollection = {
  slug: 'media',
  admin: {
    components: {
      views: {
        grid: {
          Component: '@/components#GridView',
          path: '/grid',
          exact: true,
        },
      },
    },
  },
  // ...
}

Accessible at: /collections/media/grid

Security

  • CodeQL scan: No issues found
  • No dependencies added
  • No security vulnerabilities introduced

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 29, 2026 09:56
- 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>
Copilot AI changed the title [WIP] Fix issue 15386 in Payload CMS feat(next): support custom collection-level views Jan 29, 2026
Copilot AI requested a review from robinscholz January 29, 2026 10:20

@robinscholz robinscholz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown
Author

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.

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 robinscholz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copilot AI commented Jan 29, 2026

Copy link
Copy Markdown
Author

Have you ran tests? I get the following error:

Fixed in commit 55bad88. The index signature now uses a union type that includes undefined, making it compatible with the optional edit and list properties. The build should now succeed for @payloadcms/plugin-search and all other packages.

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:

  • fastdl.mongodb.org
    • Triggering command: /usr/local/bin/node node ./postinstall.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from robinscholz January 29, 2026 11:08
@robinscholz robinscholz marked this pull request as ready for review January 29, 2026 11:25
@robinscholz robinscholz merged commit c890e63 into main Jan 29, 2026
@robinscholz robinscholz deleted the copilot/fix-issue-15386 branch January 29, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants