Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

561 new document sub navigation page #8402

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/controllers/admin/new_document_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class Admin::NewDocumentController < Admin::BaseController
before_action :check_new_design_system_permissions, only: %i[index]

layout :get_layout

def index; end

def new_document_options_redirect
redirect_options = {
"call-for-evidence": new_admin_call_for_evidence_path,
"case-study": new_admin_case_study_path,
"consultation": new_admin_consultation_path,
"detailed-guide": new_admin_detailed_guide_path,
"document-collection": new_admin_document_collection_path,
"fatality-notice": new_admin_fatality_notice_path,
"news-article": new_admin_news_article_path,
"publication": new_admin_publication_path,
"speech": new_admin_speech_path,
"statistical-data-set": new_admin_statistical_data_set_path,
}

if params[:new_document_options].present?
selected_option = params.require(:new_document_options).to_sym
redirect_to redirect_options[selected_option]
else
redirect_to admin_new_document_path, alert: "Please select a new document option"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using the alert here we should be using the error component, which is more consistent with what we have done elsewhere and more closely follows the design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback David! As discussed we will pick up how we handle errors across the codebase as a separate user story. For the time being, we'll keep implementation as is.

end
end

private

def check_new_design_system_permissions
forbidden! unless new_design_system?
end

def get_layout
design_system_actions = %w[index new_document_options_redirect] if preview_design_system?(next_release: false)

if design_system_actions&.include?(action_name)
"design_system"
else
"admin"
end
end
end
99 changes: 99 additions & 0 deletions app/views/admin/new_document/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<% content_for :page_title, "New document" %>

<%
new_document_radio_items = [
{
value: "call-for-evidence",
text: "Call for evidence",
bold: true,
hint_text: "Use this to request people's views when it is not a consultation.",
},
{
value: "case-study",
text: "Case study",
bold: true,
hint_text: "Use this to share real examples that help users understand a process or an important" +
" aspect of government policy covered on GOV.UK.",
},
{
value: "consultation",
text: "Consultation",
bold: true,
hint_text: "Use this for documents requiring a collective agreement across government, and requests for people's view on a question with an outcome.",
},
{
value: "detailed-guide",
text: "Detailed guide",
bold: true,
hint_text: "Use this to tell users the steps they need to take to complete a clearly defined task. They are usually aimed at specialist or professional audiences.",
},
{
value: "document-collection",
text: "Document collection",
bold: true,
hint_text: "Use this to group related documents on a single page for a specific audience or around a specific theme.",
},
{
value: "fatality-notice",
text: "Fatality notice",
bold: true,
hint_text: "Use this to provide official confirmation of the death of a member of the armed forces while on deployment. Ministry of Defence only.",
},
{
value: "news-article",
text: "News article",
bold: true,
hint_text: "Use this for news story, press release, government response, and world news story.",
},
{
value: "publication",
text: "Publication",
bold: true,
hint_text: "Use this for standalone government documents, white papers, strategy documents, and reports.",
},
{
value: "speech",
text: "Speech",
bold: true,
hint_text: "Use this for speeches by ministers or other named spokespeople, and ministerial statements to Parliament.",
},
{
value: "statistical-data-set",
text: "Statistical data set",
bold: true,
hint_text: "Use this for data that you publish monthly or more often without analysis.",
},
]
%>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with url: admin_new_document_options_path do %>
<%= render "govuk_publishing_components/components/radio", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where we have a bunch of radio controls we should also have a <legend> element inside the <fieldset> which is created as part of the Form radio button component. This could be flagged as an accessibility failure/warning. It can be set via the heading parameter in the component and should ideally use the page title as its value, removing the page title itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessibility is important - well spotted! Done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RodneyJohnsonGDS - the <legend> change is perfect, ta! Only thing is that we still need the <% content_for :page_title, "New document" %> line that has been removed so that the page title appears in the browser tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

heading: "New document",
heading_level: 1,
name: "new_document_options",
id: "new_document_options",
items: new_document_radio_items,
} %>
<%= render "govuk_publishing_components/components/inset_text", {
text: sanitize("Check the #{link_to("content types guidance", admin_whats_new_path, {class: "govuk-link"})}" +
" if you need more help in choosing a content type."),
} %>

<div class="govuk-button-group">
<%= render "govuk_publishing_components/components/button", {
text: "Next",
data_attributes: {
module: "gem-track-click",
"track-category": "form-button",
"track-action": "new-document-radio-options-next-button",
"track-label": "Next",
},
} %>

<%= link_to("Cancel", root_path, class: "govuk-link govuk-link--no-visited-state") %>
</div>
<% end %>
</div>
</div>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ def redirect(path, options = { prefix: Whitehall.router_prefix })

get "/whats-new" => "whats_new#index", as: :whats_new

get "/new-document" => "new_document#index", as: :new_document
get :new_document_options, to: "new_document#new_document_options_redirect"
post :new_document_options, to: "new_document#new_document_options_redirect"

resources :statistics_announcements, except: [:destroy] do
member do
get :cancel
Expand Down
72 changes: 72 additions & 0 deletions test/functional/admin/new_document_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require "test_helper"
mtaylorgds marked this conversation as resolved.
Show resolved Hide resolved

class Admin::NewDocumentControllerTest < ActionController::TestCase
setup do
login_as_preview_design_system_user :writer
end

view_test "GET #index renders the 'New Document' page with the header, all relevant radio selection options and inset text" do
get :index

assert_response :success
assert_select "h1.gem-c-radio__heading-text", text: "New document"
radio_button_values.each do |value|
assert_select_radio_button(value)
end
assert_select ".govuk-inset-text", text: "Check the content types guidance if you need more help in choosing a content type."
end

test "access to the New document index page is forbidden for users without design system permissions" do
login_as :writer
get :index
assert_response :forbidden
end

test "POST #new_document_options_redirect redirects each radio buttons to their expected paths" do
redirect_options.each do |selected_option, expected_path|
request_params = {
"new_document_options": selected_option,
}

post :new_document_options_redirect, params: request_params

assert_redirected_to expected_path
end
end

test "when no radio buttons are selected a flash notice is shown and the user remains on the index page" do
request_params = {
new_document_options: "",
}

post :new_document_options_redirect, params: request_params

assert_redirected_to admin_new_document_path
assert_equal flash[:alert], "Please select a new document option"
end

private

def radio_button_values
%w[call-for-evidence case-study consultation detailed-guide document-collection fatality-notice news-article publication speech statistical-data-set]
end

def assert_select_radio_button(value)
assert_select ".govuk-radios__item input[type=radio][name=new_document_options][value=#{value}]", count: 1
end

def redirect_options
{
"call-for-evidence": new_admin_call_for_evidence_path,
"case-study": new_admin_case_study_path,
"consultation": new_admin_consultation_path,
"detailed-guide": new_admin_detailed_guide_path,
"document-collection": new_admin_document_collection_path,
"fatality-notice": new_admin_fatality_notice_path,
"news-article": new_admin_news_article_path,
"publication": new_admin_publication_path,
"speech": new_admin_speech_path,
"statistical-data-set": new_admin_statistical_data_set_path,
}
end
end