Skip to content

Commit

Permalink
Deprecate the use of MenuItem#position
Browse files Browse the repository at this point in the history
Rely on the implicit array ordering.
  • Loading branch information
elia committed Sep 25, 2023
1 parent ff604f6 commit 78497dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/shared/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% Spree::Backend::Config.menu_items.sort_by { |item| item.position || Float::INFINITY }.each do |menu_item| %>
<% Spree::Backend::Config.menu_items.each do |menu_item| %>
<% if menu_item.render_in?(self) %>
<%=
tab(
Expand Down
11 changes: 0 additions & 11 deletions backend/lib/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ def theme_path(user_theme = nil)
#
# @!attribute menu_items
# @return [Array<Spree::BackendConfiguration::MenuItem>]
#
# Positioning can be determined by setting the position attribute to
# an Integer or nil. Menu Items will be rendered with smaller lower values
# first and higher values last. A position value of nil will cause the menu
# item to be rendered at the end of the list.
attr_writer :menu_items

# Return the menu items which should be drawn in the menu
Expand All @@ -86,14 +81,12 @@ def menu_items
return_authorizations|
shipments
)}x,
position: 0
),
MenuItem.new(
label: :products,
icon: 'th-large',
condition: -> { can?(:admin, Spree::Product) },
partial: 'spree/admin/shared/product_sub_menu',
position: 1,
data_hook: :admin_product_sub_tabs,
children: [
MenuItem.new(
Expand Down Expand Up @@ -129,7 +122,6 @@ def menu_items
condition: -> { can?(:admin, Spree::Promotion) },
url: :admin_promotions_path,
data_hook: :admin_promotion_sub_tabs,
position: 2,
children: [
MenuItem.new(
label: :promotions,
Expand All @@ -147,15 +139,13 @@ def menu_items
match_path: %r{/(stock_items)},
condition: -> { can?(:admin, Spree::StockItem) },
url: :admin_stock_items_path,
position: 3,
),
MenuItem.new(
label: :users,
icon: 'user',
match_path: %r{/(users|store_credits)},
condition: -> { Spree.user_class && can?(:admin, Spree.user_class) },
url: :admin_users_path,
position: 4,
),
MenuItem.new(
label: :settings,
Expand All @@ -164,7 +154,6 @@ def menu_items
partial: 'spree/admin/shared/settings_sub_menu',
condition: -> { can? :admin, Spree::Store },
url: :admin_stores_path,
position: 5,
children: [
MenuItem.new(
label: :stores,
Expand Down
9 changes: 5 additions & 4 deletions backend/lib/spree/backend_configuration/menu_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def sections # rubocop:disable Style/TrivialAccessors
end
deprecate sections: :label, deprecator: Spree::Deprecation

attr_accessor :position
attr_accessor :position # rubocop:disable Layout/EmptyLinesAroundAttributeAccessor
deprecate position: nil, deprecator: Spree::Deprecation
deprecate "position=": nil, deprecator: Spree::Deprecation

# @param icon [String] The icon to draw for this menu item
# @param condition [Proc] A proc which returns true if this menu item
Expand All @@ -21,8 +23,6 @@ def sections # rubocop:disable Style/TrivialAccessors
# menu item.
# @param children [Array<Spree::BackendConfiguration::MenuItem>] An array
# @param url [String|Symbol] A url where this link should send the user to or a Symbol representing a route name
# @param position [Integer] The position in which the menu item should render
# nil will cause the item to render last
# @param match_path [String, Regexp, callable] (nil) If the {url} to determine the active tab is ambigous
# you can pass a String, Regexp or callable to identify this menu item. The callable
# accepts a request object and returns a Boolean value.
Expand Down Expand Up @@ -60,9 +60,10 @@ def initialize(
@partial = partial
@children = children
@url = url
@position = position
@data_hook = data_hook
@match_path = match_path

self.position = position if position # Use the setter to deprecate
end

def render_in?(view_context)
Expand Down

0 comments on commit 78497dd

Please sign in to comment.