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

[Admin] Add dynamic filters to ui/table component #5376

Merged

Conversation

rainerdema
Copy link
Contributor

@rainerdema rainerdema commented Sep 11, 2023

Summary

This PR enhances the ui/table component by introducing dynamic filtering capabilities.

  1. Dynamic Ransack Filter component: Enables creation of complex grouped queries based on user input from dropdown selections and checkboxes.
  2. Dynamic checkbox sorting: Active filters are now pushed to the top for better visibility.
  3. Dropdown Interactions: Added a click-outside event and introduced a dynamic search bar when selections exceed six.
  4. New filter options: Expanded filtering capabilities on the products and orders index pages.

Note:

  • Partially resolved an issue causing pagination exceptions in SQLite databases related to the order_search_key preference.
Add.dynamic.filters.to.ui.table.component.mov
Screenshot 2023-09-11 at 18 10 56 Screenshot 2023-09-11 at 18 10 59 Screenshot 2023-09-11 at 18 11 06

Lookbock:

Screenshot 2023-09-25 at 11 06 05 Screenshot 2023-09-25 at 11 05 50

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@rainerdema rainerdema self-assigned this Sep 11, 2023
@github-actions github-actions bot added changelog:solidus_admin changelog:solidus_core Changes to the solidus_core gem labels Sep 11, 2023
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch 11 times, most recently from f41c658 to a273d3a Compare September 21, 2023 08:46
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch 2 times, most recently from 1820224 to d32b379 Compare September 22, 2023 18:12
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch from d32b379 to 4acbb72 Compare September 25, 2023 08:50
@rainerdema rainerdema changed the title Add dynamic filters to ui/table component [Admin] Add dynamic filters to ui/table component Sep 25, 2023
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch from 4acbb72 to e54dff5 Compare September 25, 2023 09:04
@rainerdema rainerdema marked this pull request as ready for review September 25, 2023 09:04
@rainerdema rainerdema requested a review from a team as a code owner September 25, 2023 09:04
Copy link
Member

@elia elia left a comment

Choose a reason for hiding this comment

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

Looks great! Can't wait to see this merged 🙌

I left some comments, mostly nits around doing things with stimulus.

@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch from e54dff5 to 27a6e10 Compare September 27, 2023 14:01
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch 3 times, most recently from baac1b0 to eaed670 Compare September 27, 2023 17:46
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch 3 times, most recently from ba7dcbf to 79ffb75 Compare September 28, 2023 17:32
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch from 79ffb75 to 19a522f Compare September 29, 2023 10:40
@github-actions github-actions bot removed the changelog:solidus_core Changes to the solidus_core gem label Sep 29, 2023
@rainerdema rainerdema changed the base branch from nebulab/admin to main September 29, 2023 13:24
rainerdema and others added 4 commits October 10, 2023 12:05
Removing "_or_order_promotions_promotion_code_value" from the `order_search_key`
preference.
This part of the search key was causing exceptions during pagination due
to missing columns in the SQLite database.
Specifically, the exception was :
"ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: order_promotions_spree_orders.promotion_code_id)".

Note: This bug fix will be evaluated in a separate PR.
The ransack search param can now be dynamically set through the `ui/table`
component with a default value of `:q`.
In this way, the search will be triggered if there is any change in
the form and all the other internal data actions can be removed.
@elia elia force-pushed the rainerd/add-dropdown-filter-component branch from 19a522f to 55217e4 Compare October 10, 2023 11:00
elia and others added 9 commits October 10, 2023 13:02
Introduces a new Ransack filter component to dynamically generate advanced,
grouped query parameters.

Suppose you have a dropdown for: 'State', 'Variants', and 'Promotions',
And checkboxes for: 'state_eq', 'line_items_variant_id' and 'promotions_id'.

The component will dynamically create the following query parameters:
q[g][0][c][0][a][]: state
q[g][0][c][0][p]: eq
q[g][0][c][0][v][]: checkout
...
q[g][1][c][31][a][]: line_items_variant_id
q[g][1][c][31][p]: in
q[g][1][c][31][v][]: 2
...
q[g][2][c][42][a][]: promotions_id
q[g][2][c][42][p]: in
q[g][2][c][42][v][]: 8

This provides greater flexibility when configuring filters for the table component.

Usage in table component:

The `filters` method within the table component can be used to define the
attributes, predicates, and options for the dynamic filter.
This makes it convenient to set up intricate filters directly from the table
component's configuration.

For instance:
```
<%= render component('ui/table').new(
    ...
    filters: [
      {
        presentation: t('.filters.status'),
        combinator: 'or',
        attribute: "state",
        predicate: "eq",
        options: Spree::Order.state_machines[:state].states.map { |state| [state.value.titleize, state.value] }
      }
    ]
    ...
  ) %>
```
Sorts checkboxes based on their checked state, moving selected checkboxes to the top.
Improves user experience by making it easier to see active filters.
Implements a click-outside event with `stimulus-use` to automatically close
the filter details dropdown.
Adds a search input field inside the details dropdown whenever the number
of selections exceeds 6.
The search input allows for quick filtering of available options.
Uses URL query parameters to automatically check or uncheck checkboxes when
the component loads.
This is useful for sharing URLs with pre-applied filters.
Switched from using `stimulus-use` dispatch to explicit bubbling.
While using `stimulus-use`, targeting an upstream controller without
specifying the controller's name wasn't feasible in this context.
I've reverted to explicitly setting the event's bubbling property.
@elia elia force-pushed the rainerd/add-dropdown-filter-component branch from 55217e4 to 0d54847 Compare October 10, 2023 11:02
Copy link
Member

@elia elia left a comment

Choose a reason for hiding this comment

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

🙌

Enable functionality to allow users to toggle checkboxes by clicking
associated labels.
@rainerdema rainerdema force-pushed the rainerd/add-dropdown-filter-component branch from f2443dc to 6e78e0a Compare October 10, 2023 15:39
@rainerdema rainerdema merged commit dc8dad1 into solidusio:main Oct 10, 2023
9 checks passed
@rainerdema rainerdema deleted the rainerd/add-dropdown-filter-component branch October 10, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants