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

[Bug] Unable to use filter of type 'view' #5638

Closed
GiuseppeBenfenati opened this issue Aug 28, 2024 · 3 comments · Fixed by #5646
Closed

[Bug] Unable to use filter of type 'view' #5638

GiuseppeBenfenati opened this issue Aug 28, 2024 · 3 comments · Fixed by #5646

Comments

@GiuseppeBenfenati
Copy link

I configured in list operation a filter with custom view:

CRUD::filter('path')
    ->label(getTrans('labels.questions'))
    ->type('view')
    ->view('vendor.backpack.crud.filters.path_field')
    ->whenActive(function ($value) {
        CRUD::addClause('pathHasNode', $value);
    });

I received Exception

Undefined array key "view"

View component use 'view' key to include custom view

@include($filter->options['view'])

I think the problem is in the CrudFilter class can't convert view method in options key because 'view' is already a class property

I ovverided view component and used another key

@include($filter->options['customView'])
CRUD::filter('path')
    ->label(getTrans('labels.questions'))
    ->type('view')
    ->customView('vendor.backpack.crud.filters.path_field')
    ->whenActive(function ($value) {
        CRUD::addClause('pathHasNode', $value);
    });
Copy link

welcome bot commented Aug 28, 2024

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use GitHub Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - GitHub Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@karandatwani92
Copy link
Contributor

Hey @GiuseppeBenfenati

Sorry for the inconvenience, and thanks for reporting the BUG. I'm escalating the issue for the fix.

@pxpm In my investigation, I found the following:

// works ✅
$this->crud->filter('simple_filter')
    ->type('simple')
    ->whenActive(function () {
        $this->crud->addClause('where', 'checkbox', '1');
    });

// works ✅
$this->crud->addFilter(
    [ // add a "simple" filter called Draft
        'name'  => 'simple_view_filter',
        'label' => 'SimpleView',
        'type'  => 'view',
        'view'  => 'backpack.pro::filters.simple',
    ],
    false, // the simple filter has no values, just the "Draft" label specified above
    function () { // if the filter is active (the GET parameter "draft" exits)
        $this->crud->addClause('where', 'checkbox', '1');
    }
);

// same thing with fluent syntax doesn't work ❌
$this->crud->filter('simple_view_filter')
    ->type('view')
    ->view('backpack.pro::filters.simple')
    ->whenActive(function () {
        $this->crud->addClause('where', 'checkbox', '1');
    });

@pxpm
Copy link
Contributor

pxpm commented Sep 2, 2024

Hey @GiuseppeBenfenati thanks for the report.

Sorry the filters api is a little bit messy, we will give it some love. 🙏
I've just merged a fix in backpack/crud, I will tag a new version later today that at least will make the fluent behave more similar to the old array syntax.

What I usually do, and I advice anyone to do, is something along this lines:

CRUD::filter('path')->type('path_field')->viewNamespace('vendor.backpack.crud.filters')->whenActive(function ($value) {
        CRUD::addClause('pathHasNode', $value);
    });

After the update, the way you defined should work just fine, but if you want a more future-proof, I would use the one I told you now.

Cheers

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

Successfully merging a pull request may close this issue.

3 participants