silverstripe / silverstripe-admin

Silverstripe Admin Component
BSD 3-Clause "New" or "Revised" License
25 stars 92 forks source link

Can't search against `many_many` relations in `GridFieldFilterHeader` #1746

Open sabina-talipova opened 4 months ago

sabina-talipova commented 4 months ago

Description

This problem was identified during the work on task https://github.com/silverstripe/silverstripe-admin/issues/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

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

Related issue