payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.42k stars 1.49k forks source link

Wrong placeholder on related search #4916

Open mat-twg opened 8 months ago

mat-twg commented 8 months ago

Link to reproduction

No response

Describe the Bug

Wrong placeholder on related search

image

image

Expected placeholder:

Serach by Name, Type Or File Name

To Reproduce

Create two collections and run:

export const DocumentsTypes: CollectionConfig = {
  slug: 'documents-types',
  admin: {
    useAsTitle: 'name',
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true,
    },
  ],
}

export const Documents: CollectionConfig = {
  slug: 'documents',
  admin: {
    useAsTitle: 'name',
    listSearchableFields: ['filename', 'name', 'type.name'],
  },
  upload: {
    staticDir: path.resolve(__dirname, '../../../../documents'),
    mimeTypes: ['application/pdf'],
  },
  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'type',
      type: 'relationship',
      relationTo: 'documents-types',
      required: true,
    },
    {
      name: 'name',
      type: 'text',
      required: true,
    },
  ],
}

Payload Version

2.8.2

Adapters and Plugins

No response

SimYunSup commented 8 months ago

I think Payload is not provide searching field value in related document.

However, you cannot query on any field values within the related document. Since we are referencing multiple collections, the field you are querying on may not exist and break the query.

https://payloadcms.com/docs/fields/relationship#querying-and-filtering-polymorphic-relationships

that placeholder is correct because related field value is not provided, so skip presenting.

mat-twg commented 8 months ago

I think Payload is not provide searching field value in related document.

However, you cannot query on any field values within the related document. Since we are referencing multiple collections, the field you are querying on may not exist and break the query. https://payloadcms.com/docs/fields/relationship#querying-and-filtering-polymorphic-relationships

that placeholder is correct because related field value is not provided, so skip presenting.

provided as well by mongodb

image image

SimYunSup commented 8 months ago

Sorry, I got it wrong. It is working beacause querying on non-polymorphic relationship is working.

But It must be work like new feature.

In the case of polymorphic and nested field in relocation field, there may be a lot of errors, and I think there should be a discussion on how to handle the label.

mat-twg commented 8 months ago

What is there to think? the table(document/collecction) has a type (eg. type.name, type.anything.field) field, it is indicated in the listSearchableFields, it should be displayed in the placeholder, the errors you mention should be taken care of by the developer.

-- Just take first split by '.' not the last one, or print TypeName

SimYunSup commented 8 months ago
  1. It can produce a lot of bug because there is many edge cases. This is just working because relationship field in where is working. So I think it is not just developing problem.
    • nested value in relationship field.
    • Access denied field in relationship field.
    • relationship field in relationship field.
    • How about i18n?
  2. I think it is better to use filter option. I think searching on field in relationship field must be disabled on listSearchableFields. And if you want to relationship field in listSearchableFields, It will be New Feature.
mat-twg commented 7 months ago

Everything you described is of course the case... but still it seems to me that this applies to relational databases as well, however we are discussing a simple thing - this is the value in the placeholder, no matter what the base is, it will be the same in all cases , for example: field.name -> FieldName As for "i18n", it still does not work correctly or requires additional configuration of the search fields.

SimYunSup commented 7 months ago

I think this request should be categorized as New Feature as we need "additional configuration". The reason I listed the cases is that I need additional configuration for such edge cases.

If this is a bug, I think it is a bug that does not cause errors when the field (ex. type.name ) is put in listSearchableFields.