Files
payloadcms/test/joins/collections/Categories.ts
Dan Ribbens 2ec4d0c2ef feat: join field admin.defaultColumns (#9982)
Add the ability to specify which columns should appear in the
relationship table of a join fields

The new property is in the Join field `admin.defaultColumns` and can be
set to an array of strings containing the field names in the desired
order.
2024-12-15 03:31:31 +00:00

123 lines
2.7 KiB
TypeScript

import type { CollectionConfig } from 'payload'
import { categoriesSlug, hiddenPostsSlug, postsSlug } from '../shared.js'
import { singularSlug } from './Singular.js'
export const Categories: CollectionConfig = {
slug: categoriesSlug,
admin: {
useAsTitle: 'name',
},
fields: [
{
name: 'name',
type: 'text',
},
// Alternative tabs usage
// {
// type: 'tabs',
// tabs: [
// {
// label: 'Unnamed tab',
// fields: [
// {
// name: 'relatedPosts',
// label: 'Related Posts',
// type: 'join',
// collection: postsSlug,
// on: 'category',
// },
// ],
// },
// {
// name: 'group',
// fields: [
// {
// name: 'relatedPosts',
// label: 'Related Posts (Group)',
// type: 'join',
// collection: postsSlug,
// on: 'group.category',
// },
// ],
// },
// ],
// },
{
name: 'relatedPosts',
label: 'Related Posts',
type: 'join',
admin: {
components: {
afterInput: ['/components/AfterInput.js#AfterInput'],
beforeInput: ['/components/BeforeInput.js#BeforeInput'],
Description: '/components/CustomDescription/index.js#FieldDescriptionComponent',
},
},
collection: postsSlug,
defaultSort: '-title',
defaultLimit: 5,
on: 'category',
maxDepth: 1,
},
{
name: 'hasManyPosts',
type: 'join',
collection: postsSlug,
admin: {
description: 'Static Description',
},
on: 'categories',
},
{
name: 'hasManyPostsLocalized',
type: 'join',
collection: postsSlug,
on: 'categoriesLocalized',
},
{
name: 'hiddenPosts',
type: 'join',
collection: hiddenPostsSlug,
on: 'category',
},
{
name: 'group',
type: 'group',
fields: [
{
name: 'relatedPosts',
label: 'Related Posts (Group)',
type: 'join',
collection: postsSlug,
on: 'group.category',
admin: {
defaultColumns: ['id', 'createdAt', 'title'],
},
},
{
name: 'camelCasePosts',
type: 'join',
collection: postsSlug,
on: 'group.camelCaseCategory',
},
],
},
{
name: 'singulars',
type: 'join',
collection: singularSlug,
on: 'category',
},
{
name: 'filtered',
type: 'join',
collection: postsSlug,
on: 'category',
where: {
isFiltered: { not_equals: true },
},
},
],
}