diff --git a/docs/folders/overview.mdx b/docs/folders/overview.mdx index f44266f1ad..8d1307ee9e 100644 --- a/docs/folders/overview.mdx +++ b/docs/folders/overview.mdx @@ -1,6 +1,6 @@ --- title: Folders -label: Folders +label: Overview order: 10 desc: Folders allow you to group documents across collections, and are a great way to organize your content. keywords: folders, folder, content organization @@ -95,9 +95,7 @@ const config = buildConfig({ { slug: 'pages', // highlight-start - admin: { - folders: true, // defaults to false - }, + folders: true, // defaults to false // highlight-end }, ], diff --git a/packages/next/src/elements/Nav/index.client.tsx b/packages/next/src/elements/Nav/index.client.tsx index 02488e7208..aff575704b 100644 --- a/packages/next/src/elements/Nav/index.client.tsx +++ b/packages/next/src/elements/Nav/index.client.tsx @@ -30,7 +30,7 @@ export const DefaultNavClient: React.FC<{ const [folderCollectionSlugs] = React.useState(() => { return collections.reduce((acc, collection) => { - if (collection.admin.folders) { + if (collection.folders) { acc.push(collection.slug) } return acc diff --git a/packages/next/src/views/Root/getRouteData.ts b/packages/next/src/views/Root/getRouteData.ts index 2cd387acf1..01ab6e3f60 100644 --- a/packages/next/src/views/Root/getRouteData.ts +++ b/packages/next/src/views/Root/getRouteData.ts @@ -113,8 +113,8 @@ export const getRouteData = ({ let matchedCollection: SanitizedConfig['collections'][number] = undefined let matchedGlobal: SanitizedConfig['globals'][number] = undefined - const folderCollectionSlugs = config.collections.reduce((acc, { slug, admin }) => { - if (admin?.folders) { + const folderCollectionSlugs = config.collections.reduce((acc, { slug, folders }) => { + if (folders) { return [...acc, slug] } return acc diff --git a/packages/next/src/views/Root/metadata.ts b/packages/next/src/views/Root/metadata.ts index 58b6548374..d08560b32b 100644 --- a/packages/next/src/views/Root/metadata.ts +++ b/packages/next/src/views/Root/metadata.ts @@ -45,8 +45,8 @@ export const generatePageMetadata = async ({ const config = await configPromise const params = await paramsPromise - const folderCollectionSlugs = config.collections.reduce((acc, { slug, admin }) => { - if (admin?.folders) { + const folderCollectionSlugs = config.collections.reduce((acc, { slug, folders }) => { + if (folders) { return [...acc, slug] } return acc diff --git a/packages/payload/src/collections/config/defaults.ts b/packages/payload/src/collections/config/defaults.ts index c91a51a4da..324737322e 100644 --- a/packages/payload/src/collections/config/defaults.ts +++ b/packages/payload/src/collections/config/defaults.ts @@ -69,7 +69,6 @@ export const addDefaultsToCollectionConfig = (collection: CollectionConfig): Col custom: {}, enableRichTextLink: true, enableRichTextRelationship: true, - folders: false, useAsTitle: 'id', ...(collection.admin || {}), pagination: { @@ -83,6 +82,7 @@ export const addDefaultsToCollectionConfig = (collection: CollectionConfig): Col collection.custom = collection.custom ?? {} collection.endpoints = collection.endpoints ?? [] collection.fields = collection.fields ?? [] + collection.folders = collection.folders ?? false collection.hooks = { afterChange: [], diff --git a/packages/payload/src/collections/config/types.ts b/packages/payload/src/collections/config/types.ts index f4689baaed..0d02188329 100644 --- a/packages/payload/src/collections/config/types.ts +++ b/packages/payload/src/collections/config/types.ts @@ -345,11 +345,6 @@ export type CollectionAdminOptions = { disableCopyToLocale?: boolean enableRichTextLink?: boolean enableRichTextRelationship?: boolean - /** - * Enables folders for this collection - * @deprecated this property will move out of `admin` in the next patch - */ - folders?: CollectionFoldersConfiguration /** * Specify a navigational group for collections in the admin sidebar. * - Provide a string to place the entity in a custom group. @@ -445,6 +440,10 @@ export type CollectionConfig = { */ endpoints?: false | Omit[] fields: Field[] + /** + * Enables folders for this collection + */ + folders?: CollectionFoldersConfiguration /** * Specify which fields should be selected always, regardless of the `select` query which can be useful that the field exists for access control / hooks */ diff --git a/packages/payload/src/folders/addFolderCollections.ts b/packages/payload/src/folders/addFolderCollections.ts index 7a0dc8b6d3..f232e845e9 100644 --- a/packages/payload/src/folders/addFolderCollections.ts +++ b/packages/payload/src/folders/addFolderCollections.ts @@ -15,25 +15,23 @@ export async function addFolderCollections(config: NonNullable): Promise for (let i = 0; i < config.collections.length; i++) { const collection = config.collections[i] - if (collection?.admin?.folders) { - if (collection) { - collection.fields.push({ - name: folderFieldName, - type: 'relationship', - admin: { - allowCreate: false, - allowEdit: false, - components: { - Cell: '@payloadcms/ui/rsc#FolderTableCell', - Field: '@payloadcms/ui/rsc#FolderEditField', - }, + if (collection && collection?.folders) { + collection.fields.push({ + name: folderFieldName, + type: 'relationship', + admin: { + allowCreate: false, + allowEdit: false, + components: { + Cell: '@payloadcms/ui/rsc#FolderTableCell', + Field: '@payloadcms/ui/rsc#FolderEditField', }, - index: true, - label: 'Folder', - relationTo: folderSlug, - }) - enabledCollectionSlugs.push(collection.slug) - } + }, + index: true, + label: 'Folder', + relationTo: folderSlug, + }) + enabledCollectionSlugs.push(collection.slug) } } diff --git a/packages/payload/src/folders/utils/getFoldersAndDocumentsFromJoin.ts b/packages/payload/src/folders/utils/getFoldersAndDocumentsFromJoin.ts index 43d1c65b9e..1a56af1f36 100644 --- a/packages/payload/src/folders/utils/getFoldersAndDocumentsFromJoin.ts +++ b/packages/payload/src/folders/utils/getFoldersAndDocumentsFromJoin.ts @@ -24,7 +24,7 @@ export async function queryDocumentsAndFoldersFromJoin({ }: QueryDocumentsAndFoldersArgs): Promise { const folderCollectionSlugs: string[] = payload.config.collections.reduce( (acc, collection) => { - if (collection?.admin?.folders) { + if (collection?.folders) { acc.push(collection.slug) } return acc diff --git a/packages/ui/src/elements/BulkUpload/EditForm/index.tsx b/packages/ui/src/elements/BulkUpload/EditForm/index.tsx index 29aa48585c..bb830a707d 100644 --- a/packages/ui/src/elements/BulkUpload/EditForm/index.tsx +++ b/packages/ui/src/elements/BulkUpload/EditForm/index.tsx @@ -169,7 +169,7 @@ export function EditForm({ { return config.collections.reduce( (acc, collection) => { - if (collection.admin.folders) { + if (collection.folders) { acc.push({ label: getTranslation(collection.labels?.plural, i18n), value: collection.slug, diff --git a/packages/ui/src/views/List/ListHeader/index.tsx b/packages/ui/src/views/List/ListHeader/index.tsx index 01a4553666..a4b94769f3 100644 --- a/packages/ui/src/views/List/ListHeader/index.tsx +++ b/packages/ui/src/views/List/ListHeader/index.tsx @@ -107,7 +107,7 @@ export const CollectionListHeader: React.FC = ({ label={getTranslation(collectionConfig?.labels?.plural, i18n)} /> ), - collectionConfig.admin.folders && ( + collectionConfig.folders && (