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

Cleanup MenuItem API and deprecate using partials for second level menus #5309

Merged
merged 12 commits into from
Sep 25, 2023

Conversation

elia
Copy link
Member

@elia elia commented Aug 7, 2023

Summary

Remove #sections that was probably introduced in order to generate the submenu and later became just a way to check if the MenuItem was "selected" or not.

This paves the way for replacing the second level navigation partials with a list of children items.

The tab helper is also updated and uses explicit label: and match_path: options instead of the initial list of sections.

MenuItem#position replacement

MenuItem#position is deprecated and can be replaced by reordering menu items explicitly in the backend config:

products_menu = config.menu_items.find { _1.label == :products }
config.menu_items.insert(0, config.menu_items.delete(products_menu))

or

config.menu_items.sort_by! { %i[products orders settings promotions].index(_1.label) }

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.

@elia elia self-assigned this Aug 7, 2023
@github-actions github-actions bot added the changelog:solidus_backend Changes to the solidus_backend gem label Aug 7, 2023
@elia elia force-pushed the elia/menu-items-cleanup branch from 273f683 to 2cd1512 Compare August 8, 2023 16:42
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Aug 8, 2023
@elia elia force-pushed the elia/menu-items-cleanup branch 2 times, most recently from 58ed5d3 to 423029d Compare August 10, 2023 15:38
Block handling in ERB is different than a regular method. Regular
methods are interested in the return value, while for ERB we need to
capture the ERB output produced by running the block and discard the
return value. The `capture` method does just that.
@elia elia force-pushed the elia/menu-items-cleanup branch 5 times, most recently from ab47d60 to f6e8e70 Compare September 21, 2023 15:33
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #5309 (78497dd) into main (3994370) will increase coverage by 0.05%.
The diff coverage is 98.94%.

@@            Coverage Diff             @@
##             main    #5309      +/-   ##
==========================================
+ Coverage   88.71%   88.76%   +0.05%     
==========================================
  Files         563      564       +1     
  Lines       13896    13959      +63     
==========================================
+ Hits        12328    12391      +63     
  Misses       1568     1568              
Files Changed Coverage Δ
...ckend/lib/spree/backend_configuration/menu_item.rb 98.18% <97.56%> (-1.82%) ⬇️
...ckend/app/helpers/spree/admin/navigation_helper.rb 90.62% <100.00%> (+1.61%) ⬆️
backend/lib/spree/backend_configuration.rb 100.00% <100.00%> (ø)
.../backend_configuration/deprecated_tab_constants.rb 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@elia elia force-pushed the elia/menu-items-cleanup branch from f6e8e70 to 4903d35 Compare September 21, 2023 19:26
@elia elia changed the title [Backend] cleanup MenuItems api [Backend] cleanup MenuItems generation Sep 21, 2023
@elia elia mentioned this pull request Sep 21, 2023
3 tasks
elia added 10 commits September 21, 2023 22:43
Also moves `#icon` from a sequential argument to a keyword argument.

The list of sections was only used to match the current path, because
top-level menu items should be active whenever any of the children
items are active.
The first part will just setup options and the bottom of the method
takes care of generating the "tab".
The menu item will now be able to tell if a request matches itself.
Use MenuItem instances for second level backend menus instead of
partials.
The condition option was duplicating what the children were already
checking.
@elia elia force-pushed the elia/menu-items-cleanup branch from 3295e54 to f8f801e Compare September 21, 2023 20:43
@elia elia requested a review from rainerdema September 21, 2023 20:49
@elia elia marked this pull request as ready for review September 22, 2023 07:00
@elia elia requested a review from a team as a code owner September 22, 2023 07:00
Copy link
Contributor

@rainerdema rainerdema left a comment

Choose a reason for hiding this comment

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

Great work @elia! I appreciate the simplicity you've introduced, especially in creating new menu items without needing partial views. Thanks a lot!

@elia elia force-pushed the elia/menu-items-cleanup branch from f8f801e to b79954e Compare September 25, 2023 07:55
Rely on the implicit array ordering.
@elia elia force-pushed the elia/menu-items-cleanup branch from b79954e to 78497dd Compare September 25, 2023 08:50
@elia elia merged commit 1891495 into main Sep 25, 2023
@elia elia deleted the elia/menu-items-cleanup branch September 25, 2023 15:33
@elia elia changed the title [Backend] cleanup MenuItems generation Cleanup MenuItems api and deprecate partials Sep 26, 2023
@elia elia changed the title Cleanup MenuItems api and deprecate partials Cleanup MenuItem API and deprecate using partials for second level menus Sep 26, 2023
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 changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants