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

Fix "Stock" admin nav double highlight #2969

Merged
merged 2 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backend/app/models/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BackendConfiguration < Preferences::Configuration

# An item which should be drawn in the admin menu
class MenuItem
attr_reader :icon, :label, :partial, :condition, :sections, :url
attr_reader :icon, :label, :partial, :condition, :sections, :url, :match_path

attr_accessor :position

Expand All @@ -39,14 +39,17 @@ class MenuItem
# @param url [String] A url where this link should send the user to
# @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] (nil) If the {url} to determine the active tab is ambigous
# you can pass a String or Regexp to identify this menu item
def initialize(
sections,
icon,
condition: nil,
label: nil,
partial: nil,
url: nil,
position: nil
position: nil,
match_path: nil
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
)

@condition = condition || -> { true }
Expand All @@ -56,6 +59,7 @@ def initialize(
@partial = partial
@url = url
@position = position
@match_path = match_path
end
end

Expand Down Expand Up @@ -111,6 +115,7 @@ def menu_items
condition: -> { can?(:admin, Spree::StockItem) },
label: :stock,
url: :admin_stock_items_path,
match_path: '/stock_items',
position: 3
),
MenuItem.new(
Expand Down
3 changes: 2 additions & 1 deletion backend/app/views/spree/admin/shared/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*menu_item.sections,
icon: menu_item.icon,
label: menu_item.label,
url: menu_item.url.is_a?(Symbol) ? spree.public_send(menu_item.url) : menu_item.url
url: menu_item.url.is_a?(Symbol) ? spree.public_send(menu_item.url) : menu_item.url,
match_path: menu_item.match_path,
) do
%>
<%- render partial: menu_item.partial if menu_item.partial %>
Expand Down
17 changes: 17 additions & 0 deletions backend/spec/models/spree/backend_configuration/menu_item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Spree::BackendConfiguration::MenuItem do
describe '#match_path' do
subject do
described_class.new([], nil, {
match_path: '/stock_items'
}).match_path
end

it 'can be read' do
is_expected.to eq('/stock_items')
end
end
end
22 changes: 22 additions & 0 deletions backend/spec/models/spree/backend_configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'spec_helper'
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved

RSpec.describe Spree::BackendConfiguration do
describe '#menu_items' do
subject do
described_class.new.menu_items
end

describe 'menu tab for stock items' do
let(:stock_menu_item) do
subject.detect { |item| item.label == :stock }
end

# Regression for https://github.com/solidusio/solidus/issues/2950
it 'has match_path set to /stock_items' do
expect(stock_menu_item.match_path).to eq('/stock_items')
end
end
end
end