feat: extend listSearchableFields relationship fields to include subfields
This commit is contained in:
@@ -50,6 +50,7 @@ type Args = {
|
||||
}
|
||||
|
||||
export const sanitizeFields = async ({
|
||||
collectionConfig,
|
||||
config,
|
||||
existingFieldNames = new Set(),
|
||||
fields,
|
||||
@@ -114,6 +115,28 @@ export const sanitizeFields = async ({
|
||||
throw new InvalidFieldRelationship(field, relationship)
|
||||
}
|
||||
})
|
||||
|
||||
if (Array.isArray(collectionConfig?.admin?.listSearchableFields)) {
|
||||
const listSearchableIndex = collectionConfig.admin.listSearchableFields?.indexOf(
|
||||
`${joinPath ? joinPath + '.' : ''}${field.name}`,
|
||||
)
|
||||
if (listSearchableIndex !== -1 && typeof field.relationTo === 'string') {
|
||||
const relatedCollection = config.collections.find(
|
||||
(collection) => collection.slug === field.relationTo,
|
||||
)
|
||||
const searchableRelationFields = relatedCollection?.admin?.listSearchableFields || [
|
||||
relatedCollection?.admin?.useAsTitle ? relatedCollection.admin.useAsTitle : 'id',
|
||||
]
|
||||
collectionConfig.admin.listSearchableFields.splice(
|
||||
listSearchableIndex,
|
||||
1,
|
||||
...searchableRelationFields.map(
|
||||
(relationFieldName) =>
|
||||
`${joinPath ? joinPath + '.' : ''}${field.name}.${relationFieldName}`,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (field.min && !field.minRows) {
|
||||
|
||||
@@ -11,7 +11,7 @@ export const Posts: CollectionConfig = {
|
||||
defaultColumns: ['id', 'number', 'title', 'description', 'demoUIField'],
|
||||
description: 'This is a custom collection description.',
|
||||
group: 'One',
|
||||
listSearchableFields: ['id', 'title', 'description', 'number'],
|
||||
listSearchableFields: ['id', 'title', 'description', 'number', 'relationship', 'upload'],
|
||||
components: {
|
||||
beforeListTable: [
|
||||
'/components/ResetColumns/index.js#ResetDefaultColumnsButton',
|
||||
|
||||
Reference in New Issue
Block a user