chore: moves collections folders property to the top level (#12508)

This commit is contained in:
Jarrod Flesch
2025-05-22 16:01:33 -04:00
committed by GitHub
parent f75d62c79b
commit d83b2bf3fa
17 changed files with 37 additions and 63 deletions

View File

@@ -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
},
],

View File

@@ -30,7 +30,7 @@ export const DefaultNavClient: React.FC<{
const [folderCollectionSlugs] = React.useState<string[]>(() => {
return collections.reduce<string[]>((acc, collection) => {
if (collection.admin.folders) {
if (collection.folders) {
acc.push(collection.slug)
}
return acc

View File

@@ -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

View File

@@ -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

View File

@@ -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: [],

View File

@@ -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<TSlug extends CollectionSlug = any> = {
*/
endpoints?: false | Omit<Endpoint, 'root'>[]
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
*/

View File

@@ -15,25 +15,23 @@ export async function addFolderCollections(config: NonNullable<Config>): 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)
}
}

View File

@@ -24,7 +24,7 @@ export async function queryDocumentsAndFoldersFromJoin({
}: QueryDocumentsAndFoldersArgs): Promise<QueryDocumentsAndFoldersResults> {
const folderCollectionSlugs: string[] = payload.config.collections.reduce<string[]>(
(acc, collection) => {
if (collection?.admin?.folders) {
if (collection?.folders) {
acc.push(collection.slug)
}
return acc

View File

@@ -169,7 +169,7 @@ export function EditForm({
<Upload_v4
collectionSlug={collectionConfig.slug}
customActions={[
collectionConfig.admin.folders && (
collectionConfig.folders && (
<MoveDocToFolder
buttonProps={{
buttonStyle: 'pill',

View File

@@ -157,7 +157,7 @@ export const DocumentControls: React.FC<{
const showCopyToLocale = localization && !collectionConfig?.admin?.disableCopyToLocale
const showFolderMetaIcon = collectionConfig && collectionConfig.admin.folders
const showFolderMetaIcon = collectionConfig && collectionConfig.folders
const showLockedMetaIcon = user && readOnlyForIncomingUser
return (

View File

@@ -20,7 +20,7 @@ export function CollectionTypePill() {
const [allCollectionOptions] = React.useState(() => {
return config.collections.reduce(
(acc, collection) => {
if (collection.admin.folders) {
if (collection.folders) {
acc.push({
label: getTranslation(collection.labels?.plural, i18n),
value: collection.slug,

View File

@@ -107,7 +107,7 @@ export const CollectionListHeader: React.FC<ListHeaderProps> = ({
label={getTranslation(collectionConfig?.labels?.plural, i18n)}
/>
),
collectionConfig.admin.folders && (
collectionConfig.folders && (
<ListFolderPills
collectionConfig={collectionConfig}
key="list-header-buttons"

View File

@@ -4,8 +4,8 @@ export const Autosave: CollectionConfig = {
slug: 'autosave',
admin: {
useAsTitle: 'title',
folders: true,
},
folders: true,
fields: [
{
name: 'title',

View File

@@ -4,8 +4,8 @@ export const Drafts: CollectionConfig = {
slug: 'drafts',
admin: {
useAsTitle: 'title',
folders: true,
},
folders: true,
fields: [
{
name: 'title',

View File

@@ -3,8 +3,6 @@ import type { CollectionConfig } from 'payload'
export const Media: CollectionConfig = {
slug: 'media',
upload: true,
admin: {
folders: true,
},
folders: true,
fields: [],
}

View File

@@ -6,8 +6,8 @@ export const Posts: CollectionConfig = {
slug: postSlug,
admin: {
useAsTitle: 'title',
folders: true,
},
folders: true,
fields: [
{
name: 'title',

View File

@@ -1,19 +0,0 @@
import { rootParserOptions } from '../../eslint.config.js'
import testEslintConfig from '../eslint.config.js'
/** @typedef {import('eslint').Linter.Config} Config */
/** @type {Config[]} */
export const index = [
...testEslintConfig,
{
languageOptions: {
parserOptions: {
...rootParserOptions,
tsconfigRootDir: import.meta.dirname,
},
},
},
]
export default index