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

[POC] "Agnostic" filters #5714

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open

[POC] "Agnostic" filters #5714

wants to merge 3 commits into from

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Nov 6, 2024

WHY

BEFORE - What was wrong? What was happening before this PR?

Filters were tightly coupled with the datatable making it impossible to use in a page that didn't had the datatable.

AFTER - What is happening after this PR?

Filters can be used in any page, and developer can configure the actions to perform when they are enabled/disabled.

image

HOW

How did you achieve that, in technical terms?

transformed the filters_navbar into a component that can be reused.
refactored the filters to emit events when they are changed.

Is it a breaking change?

If you have filters_navbar.blade.php overwritten yes it is.

@pxpm pxpm assigned tabacitu and pxpm Nov 6, 2024
@pxpm pxpm added the v7 label Nov 6, 2024
@susanu
Copy link
Contributor

susanu commented Nov 27, 2024

Off topic: Would you consider adding support for global filters?
Example: A filter that will be displayed on all pages, lets say a date range filter.
On the cruds that have a date range filter, just take the values from the global one (if you set it this way).
Use case: You want to see statistics about last week on multiple cruds and don't want to set the date range every time you navigate to the crud.

Cheers!

@tabacitu
Copy link
Member

Hi @susanu - I think that's an interesting idea, but a very niche one. I see how it would be useful (I have a company select in one project too). But I don't think Backpack needs to help with it... it's ok for the dev to do it custom, since it's IS very custom, and particular to that project. We're not looking to add any "could-have" features, only "must-have" and "should-have". But it would make for a very interesting article - I'll give you that! Wanna write it?

@susanu
Copy link
Contributor

susanu commented Nov 28, 2024

Hi @tabacitu,

I'm better at writing code than articles.
After v7 is released and filters can be reused in other places, i will submit a pull request, when time allows it, for this feature.

Cheers!

@pxpm
Copy link
Contributor Author

pxpm commented Dec 2, 2024

@susanu "theoretically" that's already possible.

You can store the "global" filter (you can't use the native filters (yet!)) in a session variable, and add a middleware, or similar approach, that reads from that session variable and redirects the user to say admin/invoices?date=2024-01-01. If the date filter exist on the invoice crud, it will be automatically applied.

Thanks for the suggestion, eagerly waiting for the PR 👍

Base automatically changed from allow-datatables-url-configuration to next December 5, 2024 11:07
Copy link
Member

@tabacitu tabacitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with making it a component. I agree with the naming. Please redo the event names so it's backpack:filters:clear like I said in https://github.com/Laravel-Backpack/PRO/pull/296 too, merge next into this, test it, and give it back.

@include('crud::inc.export_buttons')

<script type="text/javascript">
// listen to `Backpack:filters-cleared` event
document.addEventListener('Backpack:filters-cleared', function (event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document.addEventListener('Backpack:filters-cleared', function (event) {
document.addEventListener('backpack:filters:cleared', function (event) {

crud.updateUrl(new_url);
});

document.addEventListener('Backpack:filter-changed', function (event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document.addEventListener('Backpack:filter-changed', function (event) {
document.addEventListener('backpack:filter:changed', function (event) {

@tabacitu tabacitu assigned pxpm and unassigned tabacitu Dec 5, 2024
pxpm and others added 3 commits December 6, 2024 11:44
@pxpm pxpm force-pushed the agnostic-filters branch from 6e40e3a to a719f19 Compare December 6, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants