-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2328 from alphagov/448-implement-sub-navigation-p…
…ublishing-component Add Sub Navigation component to Edit page
- Loading branch information
Showing
9 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module TabbedNavHelper | ||
def edition_nav_items(edition) | ||
nav_items = [] | ||
items = %w[edit tagging metadata history admin related_external_links unpublish] | ||
|
||
items.each do |item| | ||
nav_items << standard_nav_items(item, edition) | ||
end | ||
|
||
nav_items.flatten | ||
end | ||
|
||
def standard_nav_items(item, edition) | ||
url = item.eql?("edit") ? url_for([:edition, { id: edition.id }]) : url_for([:edition, { action: item, id: edition.id }]) | ||
|
||
label = Edition::Tab[item].title | ||
href = url | ||
current = request.path == url | ||
|
||
edit_nav_item(label, href, current) | ||
end | ||
|
||
def edit_nav_item(label, href, current) | ||
[ | ||
{ | ||
label:, | ||
href:, | ||
current:, | ||
}, | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= render "govuk_publishing_components/components/secondary_navigation", { | ||
aria_label: "Document navigation", | ||
items: edition_nav_items(@edition), | ||
} %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,8 @@ | |
], | ||
} %> | ||
</div> | ||
|
||
<div class="govuk-grid-column-full"> | ||
<%= render partial: "secondary_navigation" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "test_helper" | ||
|
||
class TabbedNavHelperTest < ActionView::TestCase | ||
test "#secondary_navigation_tabs_items for edit edition page" do | ||
resource = FactoryBot.create(:guide_edition, title: "Edit page title", state: "draft") | ||
|
||
expected_output = [ | ||
{ | ||
label: "Edit", | ||
href: "/editions/#{resource.id}", | ||
current: false, | ||
}, | ||
{ | ||
label: "Tagging", | ||
href: "/editions/#{resource.id}/tagging", | ||
current: false, | ||
}, | ||
{ | ||
label: "Metadata", | ||
href: "/editions/#{resource.id}/metadata", | ||
current: false, | ||
}, | ||
{ | ||
label: "History and notes", | ||
href: "/editions/#{resource.id}/history", | ||
current: false, | ||
}, | ||
{ | ||
label: "Admin", | ||
href: "/editions/#{resource.id}/admin", | ||
current: false, | ||
}, | ||
{ | ||
label: "Related external links", | ||
href: "/editions/#{resource.id}/related_external_links", | ||
current: false, | ||
}, | ||
{ | ||
label: "Unpublish", | ||
href: "/editions/#{resource.id}/unpublish", | ||
current: false, | ||
}, | ||
] | ||
|
||
assert_equal expected_output, edition_nav_items(resource) | ||
end | ||
end |