diff --git a/packages/next/src/elements/Nav/index.client.tsx b/packages/next/src/elements/Nav/index.client.tsx index e5d922b520..02488e7208 100644 --- a/packages/next/src/elements/Nav/index.client.tsx +++ b/packages/next/src/elements/Nav/index.client.tsx @@ -24,21 +24,17 @@ export const DefaultNavClient: React.FC<{ routes: { browseByFolder: foldersRoute }, }, collections, - folders: { enabled } = {}, routes: { admin: adminRoute }, }, } = useConfig() const [folderCollectionSlugs] = React.useState(() => { - if (enabled) { - return collections.reduce((acc, collection) => { - if (collection.admin.folders) { - acc.push(collection.slug) - } - return acc - }, []) - } - return [] + return collections.reduce((acc, collection) => { + if (collection.admin.folders) { + acc.push(collection.slug) + } + return acc + }, []) }) const { i18n } = useTranslation() @@ -52,9 +48,7 @@ export const DefaultNavClient: React.FC<{ return ( - {enabled && folderCollectionSlugs.length > 0 && ( - - )} + {folderCollectionSlugs.length > 0 && } {groups.map(({ entities, label }, key) => { return ( diff --git a/packages/next/src/views/Root/getRouteData.ts b/packages/next/src/views/Root/getRouteData.ts index a806f5a6ab..2cd387acf1 100644 --- a/packages/next/src/views/Root/getRouteData.ts +++ b/packages/next/src/views/Root/getRouteData.ts @@ -112,16 +112,13 @@ export const getRouteData = ({ const isCollection = segmentOne === 'collections' let matchedCollection: SanitizedConfig['collections'][number] = undefined let matchedGlobal: SanitizedConfig['globals'][number] = undefined - const isFolderViewEnabled = config.folders?.enabled - const folderCollectionSlugs = isFolderViewEnabled - ? config.collections.reduce((acc, { slug, admin }) => { - if (admin?.folders) { - return [...acc, slug] - } - return acc - }, []) - : [] + const folderCollectionSlugs = config.collections.reduce((acc, { slug, admin }) => { + if (admin?.folders) { + return [...acc, slug] + } + return acc + }, []) const serverProps: ServerPropsFromView = { viewActions: config?.admin?.components?.actions || [], @@ -190,7 +187,7 @@ export const getRouteData = ({ viewType = 'account' } - if (isFolderViewEnabled && viewKey === 'browseByFolder') { + if (folderCollectionSlugs.length && viewKey === 'browseByFolder') { templateType = 'default' viewType = 'folders' } @@ -206,7 +203,10 @@ export const getRouteData = ({ templateClassName = baseClasses[segmentTwo] templateType = 'minimal' viewType = 'reset' - } else if (isFolderViewEnabled && `/${segmentOne}` === config.admin.routes.browseByFolder) { + } else if ( + folderCollectionSlugs.length && + `/${segmentOne}` === config.admin.routes.browseByFolder + ) { // --> /browse-by-folder/:folderID ViewToRender = { Component: oneSegmentViews.browseByFolder, @@ -261,7 +261,6 @@ export const getRouteData = ({ viewType = 'verify' } else if (isCollection && matchedCollection) { if ( - isFolderViewEnabled && segmentThree === config.folders.slug && folderCollectionSlugs.includes(matchedCollection.slug) ) { diff --git a/packages/next/src/views/Root/metadata.ts b/packages/next/src/views/Root/metadata.ts index 932718acfe..58b6548374 100644 --- a/packages/next/src/views/Root/metadata.ts +++ b/packages/next/src/views/Root/metadata.ts @@ -43,18 +43,14 @@ export const generatePageMetadata = async ({ params: paramsPromise, }: Args) => { const config = await configPromise - const params = await paramsPromise - const isFolderViewEnabled = config.folders.enabled - const folderCollectionSlugs = isFolderViewEnabled - ? config.collections.reduce((acc, { slug, admin }) => { - if (admin?.folders) { - return [...acc, slug] - } - return acc - }, []) - : [] + const folderCollectionSlugs = config.collections.reduce((acc, { slug, admin }) => { + if (admin?.folders) { + return [...acc, slug] + } + return acc + }, []) const segments = Array.isArray(params.segments) ? params.segments : [] const currentRoute = `/${segments.join('/')}` @@ -85,7 +81,7 @@ export const generatePageMetadata = async ({ break } case 1: { - if (isFolderViewEnabled && `/${segmentOne}` === config.admin.routes.browseByFolder) { + if (folderCollectionSlugs.length && `/${segmentOne}` === config.admin.routes.browseByFolder) { // --> /:folderCollectionSlug meta = await oneSegmentMeta.folders({ config, i18n }) } else if (segmentOne === 'account') { @@ -108,7 +104,10 @@ export const generatePageMetadata = async ({ if (`/${segmentOne}` === config.admin.routes.reset) { // --> /reset/:token meta = await generateResetPasswordViewMetadata({ config, i18n }) - } else if (isFolderViewEnabled && `/${segmentOne}` === config.admin.routes.browseByFolder) { + } else if ( + folderCollectionSlugs.length && + `/${segmentOne}` === config.admin.routes.browseByFolder + ) { // --> /browse-by-folder/:folderID meta = await generateBrowseByFolderMetadata({ config, i18n }) } else if (isCollection) { diff --git a/packages/payload/src/config/defaults.ts b/packages/payload/src/config/defaults.ts index e646bb8a83..96ca034785 100644 --- a/packages/payload/src/config/defaults.ts +++ b/packages/payload/src/config/defaults.ts @@ -115,7 +115,6 @@ export const addDefaultsToConfig = (config: Config): Config => { config.folders = { slug: foldersSlug, debug: false, - enabled: false, fieldName: parentFolderFieldName, ...(config.folders || {}), } diff --git a/packages/payload/src/config/types.ts b/packages/payload/src/config/types.ts index 94278df483..b1cce747f3 100644 --- a/packages/payload/src/config/types.ts +++ b/packages/payload/src/config/types.ts @@ -1002,12 +1002,6 @@ export type Config = { * @default false */ debug?: boolean - /** - * Enable folders in the admin panel - * - * @default false - */ - enabled?: boolean /** * The Folder field name * diff --git a/packages/payload/src/folders/addFolderCollections.ts b/packages/payload/src/folders/addFolderCollections.ts index 4dfe6dc474..7a0dc8b6d3 100644 --- a/packages/payload/src/folders/addFolderCollections.ts +++ b/packages/payload/src/folders/addFolderCollections.ts @@ -8,53 +8,51 @@ export async function addFolderCollections(config: NonNullable): Promise return } - if (config.folders?.enabled) { - const enabledCollectionSlugs: CollectionSlug[] = [] - const debug = Boolean(config.folders?.debug) - const folderFieldName = config.folders.fieldName as unknown as string - const folderSlug = config.folders.slug as unknown as CollectionSlug + const enabledCollectionSlugs: CollectionSlug[] = [] + const debug = Boolean(config?.folders?.debug) + const folderFieldName = config?.folders?.fieldName as unknown as string + const folderSlug = config?.folders?.slug as unknown as CollectionSlug - 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', - }, + 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', }, - index: true, - label: 'Folder', - relationTo: folderSlug, - }) - enabledCollectionSlugs.push(collection.slug) - } + }, + index: true, + label: 'Folder', + relationTo: folderSlug, + }) + enabledCollectionSlugs.push(collection.slug) } } - - if (enabledCollectionSlugs.length) { - let folderCollection = createFolderCollection({ - slug: folderSlug, - collectionSlugs: enabledCollectionSlugs, - debug, - folderFieldName, - }) - - if ( - Array.isArray(config.folders.collectionOverrides) && - config.folders.collectionOverrides.length - ) { - for (const override of config.folders.collectionOverrides) { - folderCollection = await override({ collection: folderCollection }) - } - } - config.collections.push(folderCollection) - } + } + + if (enabledCollectionSlugs.length) { + let folderCollection = createFolderCollection({ + slug: folderSlug, + collectionSlugs: enabledCollectionSlugs, + debug, + folderFieldName, + }) + + if ( + Array.isArray(config?.folders?.collectionOverrides) && + config?.folders.collectionOverrides.length + ) { + for (const override of config.folders.collectionOverrides) { + folderCollection = await override({ collection: folderCollection }) + } + } + config.collections.push(folderCollection) } } diff --git a/packages/ui/src/elements/BulkUpload/EditForm/index.tsx b/packages/ui/src/elements/BulkUpload/EditForm/index.tsx index bb7a041d7d..29aa48585c 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({ = ({ label={getTranslation(collectionConfig?.labels?.plural, i18n)} /> ), - config.folders.enabled && collectionConfig.admin.folders && ( + collectionConfig.admin.folders && (