sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

After setting filters with configureDefaultFilterValues, they do not show as removable #4497

Closed mmucklo closed 4 years ago

mmucklo commented 7 years ago

Environment

Sonata packages

$ composer show sonata-project/*
# Put the result here.
sonata-project/admin-bundle              3.18.2             The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.0              Symfony SonataBlockBundle
sonata-project/cache                     1.0.7              Cache library
sonata-project/core-bundle               3.2.0              Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       dev-master aec01f1 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle dev-master ab4ba73 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       dev-master 36bac7e Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1              Lightweight Exporter library

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle          dev-master 0241b13 Integrates Assetic into Symfony2
symfony/monolog-bundle          v3.0.3             Symfony MonologBundle
symfony/phpunit-bridge          v3.2.4             Symfony PHPUnit Bridge
symfony/polyfill-intl-icu       v1.3.0             Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring       v1.3.0             Symfony polyfill for the Mbstring extension
symfony/polyfill-php54          v1.3.0             Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55          v1.3.0             Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56          v1.3.0             Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70          v1.3.0             Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util           v1.3.0             Symfony utilities for portability of PHP codes
symfony/psr-http-message-bridge v0.3               PSR HTTP message bridge
symfony/security-acl            v3.0.0             Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle      v2.4.2             Symfony SwiftmailerBundle
symfony/symfony                 v3.2.4             The Symfony PHP framework```

#### PHP version

```bash
$ php -v
PHP 7.0.18 (cli) (built: Apr 18 2017 12:04:39) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
    with Zend OPcache v7.0.18, Copyright (c) 1999-2017, by Zend Technologies```

Subject

A Default filter is not easily removable.

1) Overrode configureDefaultFilterValues(...) in an Admin class. 2) Added a default filter with ChoiceType::TYPE_NOT_CONTAINS

Documentation says class is ChoiceFilter::TYPE_.... but there's no constant in that class https://sonata-project.org/bundles/admin/master/doc/reference/action_list.html

3) Filter works as expected, however, I'm unable to easily remove it as all I see is a blank filter section when loaded (see screen capture)

Steps to reproduce

See above

Expected results

A way to remove the filter

Actual results

No apparent way to remove the filter

screen shot 2017-05-26 at 5 57 29 pm
core23 commented 7 years ago

Can you provide a PR with a fix @mmucklo ?

mmucklo commented 7 years ago

@core23 any clue where I should begin looking?

core23 commented 7 years ago

Maybe have a look at this PR where the feature was introduced https://github.com/sonata-project/SonataAdminBundle/pull/4059

Kalyse commented 7 years ago

@mmucklo https://github.com/sonata-project/SonataAdminBundle/pull/4059/files#r133965341

Kalyse commented 7 years ago

I just added the following:

On Load vr_332

vr_331


 {%  if admin.isDefaultFilter(filter.formName) %}
    <div class="panel panel-default">
        <div class="panel-body">
            <b>Default filter</b> {{ filter.options.placeholder }}
                 - <a href="#" class="sonata-toggle-filter sonata-ba-action" filter-target="filter-{{ admin.uniqid }}-{{ filter.name }}" filter-container="filter-container-{{ admin.uniqid() }}">
                        <i class="fa {{ (filter.isActive() or filter.options['show_filter']) ? 'fa-check-square-o' : 'fa-square-o' }}"></i>{{ filter.label|trans({}, filter.translationDomain ?: admin.translationDomain) }}
                        </a> <span class="text-muted">(edit)</span>
        </div>
    </div>
{% endif %}```
core23 commented 7 years ago

Can you provide a PR if you find a solution @Kalyse

tknuppe commented 6 years ago

Hi @mmucklo Just in case you haven't found a solution yet. I had the same problem and just added the filter values directly inside the $datagridValues variable instead of set them inside configureDefaultFilterValues method. Then the filters will show up in the filters section and can be removed (except for the checkboxes in the example but thats another problem with checkboxes in filters which do not have a third state).

Note: This is a workaround. I don't know if this will work in the future but for now it seems to help a lot.

Example:

protected $datagridValues = array(
    'name' => array ('type' => EqualType::TYPE_IS_EQUAL, 'value' => 'ipsum lorem'),
    'is_verified' => array ('type' => EqualType::TYPE_IS_EQUAL, 'value' => true),
    'is_locked' => array ('type' => EqualType::TYPE_IS_EQUAL, 'value' => false),
    'is_active' => array ('type' => EqualType::TYPE_IS_EQUAL, 'value' => true),
    '_page' => 1,
    '_sort_order' => 'ASC',
    '_sort_by' => 'another_nr',
);
stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.