Skip to content

Commit

Permalink
Add new routes and helper for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler authored and syed-ali-tw committed Sep 19, 2024
1 parent ee24997 commit 01b1f9e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 33 deletions.
20 changes: 20 additions & 0 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ def show
render action: "show"
end

def metadata
render action: "show"
end

def history
render action: "show"
end

def admin
render action: "show"
end

def linking
render action: "show"
end

def unpublish
render action: "show"
end

protected

def setup_view_paths
Expand Down
32 changes: 32 additions & 0 deletions app/helpers/tabbed_nav_helper.rb
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
33 changes: 1 addition & 32 deletions app/views/editions/_secondary_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
<%= render "govuk_publishing_components/components/secondary_navigation", {
aria_label: "Document navigation",
items: [
{
label: "Edit",
href: "#1",
current: true,
},
{
label: "Tagging",
href: "#2",
},
{
label: "Metadata",
href: "#3"
},
{
label: "History and notes",
href: "#1",
current: true,
},
{
label: "Admin",
href: "#2"
},
{
label: "Related external links",
href: "#3",
},
{
label: "Unpublish",
href: "#3"
}
]
items: edition_nav_items(@edition),
} %>
11 changes: 10 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
resources :artefacts, only: %i[new create update]

constraints FeatureConstraint.new("design_system_edit") do
resources :editions, only: %i[show index]
resources :editions do
member do
get "metadata"
get "history"
get "admin"
get "related_external_links", to: "editions#linking"
get "tagging", to: "editions#linking"
get "unpublish"
end
end
end

get "editions/:id" => "legacy_editions#show"
Expand Down
47 changes: 47 additions & 0 deletions test/unit/helpers/admin/tabbed_nav_helper_test.rb
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

0 comments on commit 01b1f9e

Please sign in to comment.