From e1efb14aab78921d8d7752c1f6cbf6ff5a63690b Mon Sep 17 00:00:00 2001 From: davidtrussler Date: Tue, 17 Sep 2024 11:58:53 +0100 Subject: [PATCH] Add sub navigation tab and their respective routes to edit page Add new routes and helper for tabs --- Gemfile | 2 +- Gemfile.lock | 6 +-- app/assets/stylesheets/application.scss | 2 + app/controllers/editions_controller.rb | 20 ++++++++ app/helpers/tabbed_nav_helper.rb | 32 +++++++++++++ .../editions/_secondary_navigation.html.erb | 4 ++ app/views/editions/show.html.erb | 4 ++ config/routes.rb | 11 ++++- test/integration/edition_edit_test.rb | 13 +++++ .../helpers/admin/tabbed_nav_helper_test.rb | 47 +++++++++++++++++++ 10 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 app/helpers/tabbed_nav_helper.rb create mode 100644 app/views/editions/_secondary_navigation.html.erb create mode 100644 test/unit/helpers/admin/tabbed_nav_helper_test.rb diff --git a/Gemfile b/Gemfile index 90eb1b09d..6d60ce5b6 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem "gds-sso" gem "govspeak" gem "govuk_admin_template" gem "govuk_app_config" -gem "govuk_publishing_components" +gem 'govuk_publishing_components' gem "govuk_sidekiq" gem "has_scope" gem "html2text" diff --git a/Gemfile.lock b/Gemfile.lock index 2d6e554b8..71a0b2365 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -239,10 +239,10 @@ GEM sentry-rails (~> 5.3) sentry-ruby (~> 5.3) statsd-ruby (~> 1.5) - govuk_personalisation (0.16.0) + govuk_personalisation (1.0.0) plek (>= 1.9.0) rails (>= 6, < 8) - govuk_publishing_components (41.1.1) + govuk_publishing_components (43.3.0) govuk_app_config govuk_personalisation (>= 0.7.0) kramdown @@ -688,7 +688,7 @@ GEM rexml (3.3.6) strscan rinku (2.0.6) - rouge (4.3.0) + rouge (4.4.0) rubocop (1.64.1) json (~> 2.3) language_server-protocol (>= 3.17.0) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 0a6375e47..d403b16d5 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,6 +1,7 @@ $govuk-page-width: 1140px; // GOVUK Design System +@import "govuk/base"; @import 'govuk_publishing_components/govuk_frontend_support'; @import 'govuk_publishing_components/component_support'; @import 'govuk_publishing_components/components/button'; @@ -23,6 +24,7 @@ $govuk-page-width: 1140px; @import 'govuk_publishing_components/components/notice'; @import 'govuk_publishing_components/components/previous-and-next-navigation'; @import 'govuk_publishing_components/components/search'; +@import 'govuk_publishing_components/components/secondary-navigation'; @import 'govuk_publishing_components/components/select'; @import 'govuk_publishing_components/components/skip-link'; @import 'govuk_publishing_components/components/success-alert'; diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb index 9dca5cede..ddbb55dd5 100644 --- a/app/controllers/editions_controller.rb +++ b/app/controllers/editions_controller.rb @@ -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 diff --git a/app/helpers/tabbed_nav_helper.rb b/app/helpers/tabbed_nav_helper.rb new file mode 100644 index 000000000..e733afd7d --- /dev/null +++ b/app/helpers/tabbed_nav_helper.rb @@ -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 diff --git a/app/views/editions/_secondary_navigation.html.erb b/app/views/editions/_secondary_navigation.html.erb new file mode 100644 index 000000000..0a456c29a --- /dev/null +++ b/app/views/editions/_secondary_navigation.html.erb @@ -0,0 +1,4 @@ +<%= render "govuk_publishing_components/components/secondary_navigation", { + aria_label: "Document navigation", + items: edition_nav_items(@edition), +} %> diff --git a/app/views/editions/show.html.erb b/app/views/editions/show.html.erb index e395fcdd9..2f0c0fedb 100644 --- a/app/views/editions/show.html.erb +++ b/app/views/editions/show.html.erb @@ -22,4 +22,8 @@ ], } %> + +
+ <%= render partial: "secondary_navigation" %> +
diff --git a/config/routes.rb b/config/routes.rb index 342a257a5..7e286645a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/test/integration/edition_edit_test.rb b/test/integration/edition_edit_test.rb index 7036763c3..ee5a529dc 100644 --- a/test/integration/edition_edit_test.rb +++ b/test/integration/edition_edit_test.rb @@ -22,4 +22,17 @@ class EditionEditTest < IntegrationTest assert row[2].has_text?("1") assert row[2].has_text?("Draft") end + + should "show all the tabs for the edit" do + edition = FactoryBot.create(:guide_edition, title: "Edit page title", state: "draft") + visit edition_path(edition) + + assert page.has_text?("Edit") + assert page.has_text?("Tagging") + assert page.has_text?("Metadata") + assert page.has_text?("History and notes") + assert page.has_text?("Admin") + assert page.has_text?("Related external links") + assert page.has_text?("Unpublish") + end end diff --git a/test/unit/helpers/admin/tabbed_nav_helper_test.rb b/test/unit/helpers/admin/tabbed_nav_helper_test.rb new file mode 100644 index 000000000..36381bd57 --- /dev/null +++ b/test/unit/helpers/admin/tabbed_nav_helper_test.rb @@ -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