Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't search against many_many relations in GridFieldFilterHeader #1746

Open
sabina-talipova opened this issue May 12, 2024 · 0 comments
Open

Comments

@sabina-talipova
Copy link
Contributor

sabina-talipova commented May 12, 2024

Description

This problem was identified during the work on task #1733

Since this task is complex in nature and requires changes to some main files, which may affect the operation of some other elements and functionality of the CMS. So, when working with SearchableDropdownField, we process and use the received data differently, so we should analyse how this field is used in CMS.

It is also worth noting that this problem was identified when creating this field using FormBuilder (tested by Search Options and Asset Admin).

This field works great if the data is processed on the client side before being sent to the server, for example when saving new values. Therefore, at the moment, this problem has been identified only when using SearchableDropdownField with search, but it is possible that this problem may appear when using SearchableDropdownField in other cases when, after sending data to the server, the server returns this value and updates state and then these values are displayed in another CMS field , for example when displaying tags with values.

I did some research on this issue and identified some areas that need to be updated for SearchableMultiDropdownField to work correctly with multi values.
First of all, we need to use a unified approach when storing SearchableField data in state. This is due to the fact that react-select as a value object / array of objects.
This in turn will break the approach used for searching. Since the search occurs by a specific value, string or number. Therefore, we should also make changes to the following function (See).
It is also possible that changes should be made to the SearchContext since in the current implementation the search by many-many relationships does not occur.
The next item that might need to be updated is "GridFieldState" to support looking up many-many relationships.

tl;dr

There's no way to search against a many_many relation in the GridFieldFilterHeader right now. Other fields and relations including many_many do work as expected.

Searching with a SearchableMultiDropdownField with multi values doesn't work, which is a related concern.

See discussion here for more details:

Step to reproduce

  • Add the following code to the test project:
<?php

namespace App\Extension;

use SilverStripe\Core\Extension;
use SilverStripe\Forms\SearchableMultiDropdownField;
use SilverStripe\Security\Member;

class GroupSearchableFieldsExtension extends Extension
{
    public function updateSearchableFields(array &$fields)
    {
        $fields['Members'] = [
            'title' => 'Users',
            'field' => SearchableMultiDropdownField::create('MemberID', 'Users', Member::get()),
        ];
    }
}
SilverStripe\Security\Group:
  extensions:
    - App\Extension\GroupSearchableFieldsExtension
  • Create a group and make it the child of a group
  • Add members to the new group (at least 2)
  • In /admin/security/groups click the search magnifying glass, then click the "search options" dropdown.
  • In the "Users" dropdown, select new members and click "Search"
  • Server doesn't return any results and selected values will be removed from SearchableDropdownField.

Related issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants