-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: add support for polymorphic uploads #14363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…oad collection selection
…hanced collection visibility
|
I think the where builder will need to be adjusted to handle (by constraining options) poly upload fields. Similar to how the relationship field does here: https://github.com/payloadcms/payload/blob/main/packages/ui/src/elements/WhereBuilder/field-types.tsx |
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for polymorphic uploads to Payload CMS, allowing upload fields to reference multiple upload collections. This mirrors the existing polymorphic relationship functionality and works with both single and multiple file uploads via the hasMany property.
Key changes:
- Upload fields can now accept an array of collection slugs in
relationToinstead of just a single slug - Bulk uploader UI updated to support collection selection for polymorphic uploads
- Type definitions updated to handle polymorphic upload data structures across the codebase
Reviewed Changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
test/uploads/payload-types.ts |
Updated type definitions from numeric to string IDs for upload collections |
test/fields/seed.ts |
Modified seed data to use polymorphic upload format with relationTo and value structure |
test/fields/payload-types.ts |
Added polymorphic type definitions for multi-upload fields |
test/fields/collections/UploadPoly/e2e.spec.ts |
New E2E test for single polymorphic upload functionality |
test/fields/collections/UploadMultiPoly/e2e.spec.ts |
New E2E test for multi-file polymorphic upload functionality |
test/fields/collections/UploadMulti/index.ts |
Updated upload field to support multiple collections |
packages/ui/src/fields/Upload/types.ts |
Added type definitions for polymorphic upload values and deprecated signatures |
packages/ui/src/fields/Upload/index.tsx |
Added logic to transform values for polymorphic uploads |
packages/ui/src/fields/Upload/RelationshipContent/index.tsx |
Added collection slug pill display for polymorphic uploads |
packages/ui/src/fields/Upload/Input.tsx |
Major refactor to handle polymorphic upload data fetching and state management |
packages/ui/src/fields/Upload/HasOne/index.tsx |
Added support for displaying collection slug |
packages/ui/src/fields/Upload/HasMany/index.tsx |
Added support for displaying collection slug |
packages/ui/src/elements/WhereBuilder/field-types.tsx |
Changed upload field filter component from Text to Relationship |
packages/ui/src/elements/WhereBuilder/Condition/Relationship/types.ts |
Extended relationship filter to support upload fields |
packages/ui/src/elements/WhereBuilder/Condition/Relationship/index.tsx |
Updated to handle both relationship and upload field types |
packages/ui/src/elements/WhereBuilder/Condition/DefaultFilter/index.tsx |
Added case for upload field filtering |
packages/ui/src/elements/ReactSelect/MultiValue/index.tsx |
Added null safety for option value access |
packages/plugin-seo/src/fields/MetaImage/index.ts |
Added type assertion for upload field |
packages/payload/src/fields/config/types.ts |
Enabled polymorphic upload field types |
packages/next/src/views/Version/RenderFieldsToDiff/fields/Upload/index.tsx |
Updated version diff rendering to handle polymorphic uploads |
packages/graphql/src/schema/fieldToSchemaMap.ts |
Updated GraphQL resolvers to handle polymorphic uploads and filter non-GraphQL collections |
docs/fields/upload.mdx |
Added documentation for polymorphic uploads feature |
.github/workflows/main.yml |
Added new E2E test collections to CI workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I tested manually some different configs with localization and versions.drafts enabled and it all seems to be working great. Nice job! |
|
🚀 This is included in version v3.63.0 |
This PR adds support for polymorphic uploads similar to polymorphic relationships. Closes #13912 It works with bulk upload as well and in the bulk uploader you can choose which collection the files are uploaded into. You can enable this by adding an array of slugs into `relationTo`: ```ts import type { CollectionConfig } from 'payload' export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { name: 'media', type: 'upload', relationTo: ['images', 'documents', 'videos'], // references multiple upload collections }, ], } ``` It can also be combined with `hasMany`: ```ts import type { CollectionConfig } from 'payload' export const ExampleCollection: CollectionConfig = { slug: 'example-collection', fields: [ { name: 'media', type: 'upload', relationTo: ['images', 'documents', 'videos'], // references multiple upload collections hasMany: true, // allows multiple uploads }, ], } ``` **Known issue**: #12014 Filtering by polymorphic relationships is currently broken and I'll work on that in a separate PR.
This PR adds support for polymorphic uploads similar to polymorphic relationships. Closes #13912
It works with bulk upload as well and in the bulk uploader you can choose which collection the files are uploaded into.
You can enable this by adding an array of slugs into
relationTo:It can also be combined with
hasMany:Known issue: #12014
Filtering by polymorphic relationships is currently broken and I'll work on that in a separate PR.