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

Backend: Make order search fields configurable #5776

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jun 5, 2024

The order search depends on legacy promotion system associations to be present, but we don't want to introduce Deface as a core dependency. Therefore, we must make the search fields for orders configurable.

This introduces a new configuration option on the Backend configuration: Spree::Backend::Config.order_search_fields. This Array holds hashes with a :partial key that indicates which partial should render this search field.

Optionally, one can specify an :if key with a lambda as the value that gets executed at runtime, so that unnecessary fields ("Store" for installations with only one store instance) are not displayed.

Complex fields can be done by specifying a custom partial, such as the :date_range_picker partial in this PR.

Labels for the search fields can be specified as two-value arrays that represent arguments to I18n.t. By the time this array is loaded, I18n does not have its translations loaded, so I have to go this somewhat complicated route.

Because the input fields have to be a flat list now, we can't do the sorting into columns thing we did before, but we can use a column for each input to make things flow nicely.

Before:
grafik

After:
grafik

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

@github-actions github-actions bot added the changelog:solidus_backend Changes to the solidus_backend gem label Jun 5, 2024
@mamhoff mamhoff force-pushed the configurable-index-filters branch 2 times, most recently from 748932b to d661790 Compare June 6, 2024 06:25
@mamhoff mamhoff marked this pull request as ready for review June 6, 2024 06:37
@mamhoff mamhoff requested a review from a team as a code owner June 6, 2024 06:37
@mamhoff mamhoff force-pushed the configurable-index-filters branch from 77d6b19 to 257c000 Compare June 6, 2024 12:04
@mamhoff
Copy link
Contributor Author

mamhoff commented Jun 6, 2024

Failing because of rails/sprockets-rails#524

The order search depends on legacy promotion system associations to be
present, but we don't want to introduce Deface as a core dependency.
Therefore, we must make the search fields for orders configurable.

This introduces a new configuration option on the Backend configuration:
`Spree::Backend::Config.search_fields`. This Hash has controller paths
as keys, and arrays that holds hashes with a `:partial` key that indicates
which partial should render this search field.

Optionally, one can specify an `:if` key with a lambda as the value that
gets executed at runtime, so that unnecessary fields ("Store" for
installations with only one store instance) are not displayed.

Complex fields can be done by specifying a custom partial, such as the
`:date_range_picker` partial in this PR.

The third key, `:locals` contains a has of the local variables inside
the partial. Anything that needs to be computed dynamically should be
done with a lambda here.
@mamhoff mamhoff force-pushed the configurable-index-filters branch from 257c000 to 05ca204 Compare June 6, 2024 14:37
This search field depends on the `Spree::Order#promotions` relation to
be available and searchable. This is not given with a null promotion
system or the upcoming new promotion system, where relations will have a
different name. So we only add it if solidus_legacy_promotions is also
loaded.
@mamhoff mamhoff force-pushed the configurable-index-filters branch from 05ca204 to 800d0f8 Compare June 6, 2024 14:56
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.89%. Comparing base (ea09d7e) to head (800d0f8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5776      +/-   ##
==========================================
+ Coverage   88.87%   88.89%   +0.01%     
==========================================
  Files         711      711              
  Lines       16885    16906      +21     
==========================================
+ Hits        15007    15028      +21     
  Misses       1878     1878              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

For the CHANGELOG entry:

If there are deface overrides with order search classes as targets, they need to be converted into search fields via preferences.:

Spree::Backend::Config.search_fields["spree/admin/orders"].push({
  partial: "spree/admin/shared/search_fields/date_range_picker",
  locals: {
    attribute: :shipped_at,
    label: -> { I18n.t(:date_range, scope: :spree) }
  }
})

@tvdeyen tvdeyen merged commit 8048013 into solidusio:main Jun 11, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants