Skip to content

Commit

Permalink
Be able to set and pass match_path from MenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Nov 23, 2018
1 parent a5876d2 commit 04f4214
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 6 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
)

@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
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

0 comments on commit 04f4214

Please sign in to comment.