Skip to content

Commit

Permalink
Merge pull request #2388 from alphagov/407_Design-System_Edit_Answer-…
Browse files Browse the repository at this point in the history
…Help-content-types

407 | Update the edit tab to the Design System for "Answer" and "Help" content types
  • Loading branch information
davidtrussler authored Nov 7, 2024
2 parents 31da1fa + 98ca3b0 commit dc493ea
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $govuk-page-width: 1140px;
@import 'govuk_publishing_components/components/button';
@import 'govuk_publishing_components/components/checkboxes';
@import 'govuk_publishing_components/components/date-input';
@import 'govuk_publishing_components/components/details';
@import 'govuk_publishing_components/components/document-list';
@import 'govuk_publishing_components/components/error-alert';
@import 'govuk_publishing_components/components/error-message';
Expand Down Expand Up @@ -37,6 +38,6 @@ $govuk-page-width: 1140px;
@import 'govuk_publishing_components/components/title';
@import "tags";
@import "downtimes";
@import "options_sidebar";
@import "publications";
@import "popular_links";
@import "editions";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.popular-links__sidebar {
.options-sidebar {
.govuk-button {
width: 100%;
}
Expand Down
22 changes: 21 additions & 1 deletion app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EditionsController < InheritedResources::Base
before_action only: %i[unpublish confirm_unpublish process_unpublish] do
require_govuk_editor(redirect_path: edition_path(resource))
end
before_action only: %i[progress admin] do
before_action only: %i[progress admin update] do
require_editor_permissions
end

Expand All @@ -31,6 +31,22 @@ def show
alias_method :unpublish, :show
alias_method :admin, :show

def update
@resource.assign_attributes(permitted_params)

if @resource.save
UpdateWorker.perform_async(resource.id.to_s)
flash.now[:success] = "Edition updated successfully."
else
@artefact = @resource.artefact
end
rescue StandardError => e
Rails.logger.error "Error #{e.class} #{e.message}"
@resource.errors.add(:show, "Due to a service problem, the edition couldn't be updated")
ensure
render "show"
end

def history
render action: "show"
end
Expand Down Expand Up @@ -133,4 +149,8 @@ def progress_action_param
rescue StandardError
nil
end

def permitted_params
params.require(:edition).permit(%i[title overview in_beta body major_change change_note])
end
end
2 changes: 1 addition & 1 deletion app/helpers/editions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def activity_forms_required?
params[:action] == "diff"
end

def resource_form(resource, &form_definition)
def legacy_resource_form(resource, &form_definition)
html_options = { id: "edition-form" }
unless resource.locked_for_edits? || resource.archived?
if resource.is_a?(Parted) || resource.is_a?(Varianted)
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/tabbed_nav_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def current_tab_name
current_tab = (request.path.split("/") & all_tab_names).first

case current_tab
when nil
"edit"
when "metadata"
"metadata"
when "unpublish"
Expand Down
128 changes: 128 additions & 0 deletions app/views/editions/secondary_nav_tabs/_edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/heading", {
text: "Edit",
heading_level: 2,
margin_bottom: 5,
} %>
</div>
</div>

<%= form_for @resource, as: :edition, url: edition_path(@resource) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Title",
},
id: "title",
name: "edition[title]",
value: @resource.title,
heading_size: "m",
error_items: errors_for(@edition.errors, "title".to_sym, use_full_message: false),
} %>

<%= render "govuk_publishing_components/components/textarea", {
label: {
heading_size: "m",
text: "Meta tag description",
},
name: "edition[overview]",
hint: "Some search engines will display this if they cannot find what they need in the main text",
value: @resource.overview,
} %>

<%= render "govuk_publishing_components/components/radio", {
heading: "Is this beta content?",
name: "edition[in_beta]",
inline: true,
heading_size: "m",
items: [
{
value: 1,
text: "Yes",
checked: @resource.in_beta,
},
{
value: 0,
text: "No",
checked: !@resource.in_beta,
},
],
} %>

<%= render "govuk_publishing_components/components/textarea", {
label: {
heading_size: "m",
text: "Body",
},
name: "edition[body]",
value: @resource.body,
hint: ("Refer to #{link_to("Refer to the Govspeak guidance (opens in new tab)", "https://govspeak-preview.publishing.service.gov.uk/guide", target: "_blank", rel: "noopener", class: "govuk-link")}").html_safe,
} %>

<% if @resource.published_edition %>
<%= render "govuk_publishing_components/components/details", {
title: "Add a public change note",
} do %>
<%= render "govuk_publishing_components/components/radio", {
heading: "Add a public change note",
heading_level: 3,
heading_size: "m",
name: "edition[major_change]",
hint: "Telling users when published information has changed is important for transparency.",
items: [
{
hint_text: "A change note will be published on the page and emailed to users subscribed to email alerts. The ‘last updated’ date will change.",
text: "Yes - information has been added, updated or removed.",
checked: @resource.major_change,
bold: true,
value: true,
conditional: render("govuk_publishing_components/components/textarea", {
label: {
text: "Describe the change for users",
bold: true,
},
name: "edition[change_note]",
value: @resource.change_note,
hint: ("<p class=\"govuk-!-margin-0\">Tell users what has changed, where and why. Write in full sentences, leading with the most important words. For example, \"College A has been removed from the registered sponsors list because its licence has been suspended.\"</p><a href=\"https://www.gov.uk/guidance/content-design/writing-for-gov-uk#change-notes\" target=\"_blank\">Guidance on change notes (opens in a new tab)</a>").html_safe,
}),
},
{
value: false,
text: "No",
bold: true,
checked: !@resource.major_change,
},
],
} %>
<% end %>
<% end %>
</div>

<div class="govuk-grid-column-one-third options-sidebar">
<% if @resource.locked_for_edits? %>
<p class="govuk-body"><%= @resource.error_description %> can't be changed.</p>
<% else %>
<div class="sidebar-components">
<%= render "govuk_publishing_components/components/heading", {
text: "Options",
heading_level: 3,
font_size: "s",
padding: true,
} %>

<%= render "govuk_publishing_components/components/list", {
items: [
(render "govuk_publishing_components/components/button", {
text: "Save",
margin_bottom: 3,
} if current_user.has_editor_permissions?(@resource) && !@resource.retired_format?),
link_to("Preview (opens in new tab)", preview_edition_path(@resource), target: "_blank", rel: "noopener", class: "govuk-link"),
],
} %>
</div>
<% end %>
</div>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/homepage/popular_links/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</section>
</div>

<div class = "govuk-grid-column-one-third popular-links__sidebar" >
<div class = "govuk-grid-column-one-third options-sidebar" >
<%= render "homepage/popular_links/sidebar" %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/legacy_editions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<% end %>
</div>

<%= resource_form(@resource) do |f| %>
<%= legacy_resource_form(@resource) do |f| %>
<div class="well">
<%= render resource_fields(@resource), f: f %>
</div>
Expand Down
51 changes: 51 additions & 0 deletions test/functional/editions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,55 @@ class EditionsControllerTest < ActionController::TestCase
end
end
end

context "#update" do
should "show update and success message and render show template when saved" do
post :update, params: {
id: @edition.id,
edition: {
title: "The changed title",
},
}

assert_template "show"
assert_equal "Edition updated successfully.", flash[:success]
assert_equal "The changed title", AnswerEdition.last.title
end

should "show error message and render show template when title field is blank" do
post :update, params: {
id: @edition.id,
edition: {
title: "",
},
}

assert_template "show"
assert_select ".gem-c-error-summary__list-item", "Enter a title"
end

should "show error message and render show template when the edition could not be updated" do
Edition.any_instance.stubs(:save).raises(StandardError)
post :update, params: {
id: @edition.id,
edition: {
title: "A title",
},
}

assert_template "show"
assert_select ".gem-c-error-summary__list-item", "Due to a service problem, the edition couldn't be updated"
end

should "call update worker with edition id when saved" do
UpdateWorker.expects(:perform_async).with(@edition.id.to_s)

post :update, params: {
id: @edition.id,
edition: {
title: "The changed title",
},
}
end
end
end
Loading

0 comments on commit dc493ea

Please sign in to comment.