Skip to content

Commit

Permalink
Do not append title to breadcrumbs on show_list pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rvsia committed Jul 30, 2019
1 parent 64c36f7 commit b856a23
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/controllers/mixins/breadcrumbs_mixin.rb
Expand Up @@ -22,7 +22,8 @@ def data_for_breadcrumbs
breadcrumbs.push(special_page_breadcrumb(@tagitems || @politems || @ownershipitems || @retireitems))

# Append title breadcrumb if they exist and not same as previous breadcrumb (eg "Editing name")
if @title && @title != breadcrumbs.compact.last.try(:[], :title)
# Also do not append when user is on show_list page, the menu title is used instead of it
if @title && !same_as_last_breadcrumb?(breadcrumbs, @title) && !show_list_page?
breadcrumbs.push(:title => @title)
end
else
Expand Down Expand Up @@ -150,6 +151,20 @@ def not_show_page?
(action_name == "show" && params["display"] && !%w[dashboard main].include?(params["display"])) || (action_name != "show")
end

# User is on show_list page
# A lot of pages has different header than last item in menu
# The last item in menu is an abbreviation of the header
# So, breadcrumbs should contain only the abbreviation
def show_list_page?
action_name == "show_list"
end

# Checks if the title is same as the last item in breadcrumbs
# If so, then there is no reason to append the title to breadcrumbs
def same_as_last_breadcrumb?(breadcrumbs, title)
title == breadcrumbs.compact.last.try(:[], :title)
end

# Controls on tagging screen if the tagged item is floating_ip
def floating_ip_address?(variable)
(variable&.respond_to?(:has_attribute?) && variable&.has_attribute?(:address)) || controller_name == 'floating_ips'
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/mixins/breadcrumbs_mixin_spec.rb
Expand Up @@ -193,6 +193,52 @@ class BreadcrumbsTestController < ActionController::Base
)
end
end

it "not contain header on show_list page" do
allow(subject).to receive(:action_name).and_return("show_list")
subject.instance_variable_set(:@title, "Do not show me")

expect(subject.data_for_breadcrumbs).to eq(
[
{:title=>"First Layer"},
{:title=>"Second Layer"}
]
)
end

it "contain header on not show_list page" do
allow(subject).to receive(:action_name).and_return("edot")
subject.instance_variable_set(:@title, "Do show me")

expect(subject.data_for_breadcrumbs).to eq(
[
{:title=>"First Layer"},
{:title=>"Second Layer"},
{:title=>"Do show me"}
]
)
end
end

describe "#same_as_last_breadcrumb?" do
let(:breadcrumbs) do
[
{:title=>"controller"},
{:title=>"header"}
]
end

it "returns true if header is same as last breadcrumb" do
expect(subject.send(:same_as_last_breadcrumb?, breadcrumbs, "header")).to eq(true)
end

it "returns false if header is not same as last breadcrumb" do
expect(subject.send(:same_as_last_breadcrumb?, breadcrumbs, "different header")).to eq(false)
end

it "returns false if header is same as last breadcrumb but it in the breadcrumbs on different place" do
expect(subject.send(:same_as_last_breadcrumb?, breadcrumbs, "controller")).to eq(false)
end
end

describe "#special_page_breadcrumb" do
Expand Down

0 comments on commit b856a23

Please sign in to comment.