Skip to content

Commit

Permalink
Move metadata functionality to new design system
Browse files Browse the repository at this point in the history
Add success message on update
  • Loading branch information
syed-ali-tw committed Sep 23, 2024
1 parent 87c2595 commit fa994b5
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ $govuk-page-width: 1140px;
@import 'govuk_publishing_components/components/lead-paragraph';
@import 'govuk_publishing_components/components/notice';
@import 'govuk_publishing_components/components/previous-and-next-navigation';
@import 'govuk_publishing_components/components/radio';
@import 'govuk_publishing_components/components/search';
@import 'govuk_publishing_components/components/secondary-navigation';
@import 'govuk_publishing_components/components/select';
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/artefacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,26 @@ def update
artefact = Artefact.find(updatable_params[:id])
if artefact.update_as(current_user, updatable_params)
UpdateWorker.perform_async(artefact.latest_edition_id)
flash[:notice] = "Metadata updated"
show_success_message
else
flash[:danger] = artefact.errors.full_messages.join("\n")
end

redirect_to metadata_artefact_path(artefact)
end

helper_method :formats

private

def show_success_message
if FeatureConstraint.new("design_system_edit")
flash[:success] = "Metadata has successfully updated".html_safe
else
flash[:notice] = "Metadata updated"
end
end

def formats
Artefact::FORMATS_BY_DEFAULT_OWNING_APP["publisher"] - Artefact::RETIRED_FORMATS
end
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/editions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "edition_duplicator"
require "edition_progressor"

class EditionsController < InheritedResources::Base
include TabbedNavHelper
layout "design_system"

defaults resource_class: Edition, collection_name: "editions", instance_name: "resource"
Expand All @@ -13,13 +11,12 @@ def index

def show
@artefact = @resource.artefact
render action: "show"
end

def metadata
render action: "show"
end

alias_method :metadata, :show

def history
render action: "show"
end
Expand Down
12 changes: 11 additions & 1 deletion app/helpers/tabbed_nav_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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)
Expand Down Expand Up @@ -29,4 +28,15 @@ def edit_nav_item(label, href, current)
},
]
end

def current_tab
tab = request.path.split("/") & items
tab.first == "metadata" ? "metadata" : "temp_nav_text"
end

private

def items
%w[edit tagging metadata history admin related_external_links unpublish]
end
end
44 changes: 44 additions & 0 deletions app/views/editions/secondary_nav_tabs/_metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%= render "govuk_publishing_components/components/heading", {
text: "Metadata",
heading_level: 2,
margin_bottom: 5,
} %>
<% if Edition::PUBLISHING_API_DRAFT_STATES.include? publication.state %>
<%= form_for(@artefact, :html => { :class => "artefact", :id => "edit_artefact" }) do |f| %>
<%= f.hidden_field :id, value: @artefact.id %>
<%= render "govuk_publishing_components/components/input", {
label: {
text: "Slug",
},
hint: "If you change the slug of a published page, the old slug will automatically redirect to the new one.",
name: "artefact[slug]",
value: publication.slug,
heading_level: 2,
heading_size: "m",
} %>
<%= render "govuk_publishing_components/components/radio", {
heading: "Language",
name: "artefact[language]",
inline: true,
items: [
{
value: "en",
text: "English",
checked: publication.artefact.language == "en" ? true : false,
},
{
value: "cy",
text: "Welsh",
checked: publication.artefact.language == "cy" ? true : false,
},
],
} %>
<%= render "govuk_publishing_components/components/button", {
text: "Update",
} %>
<% end %>
<% else %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h3>Work in progress</h3>
4 changes: 4 additions & 0 deletions app/views/editions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
<div class="govuk-grid-column-full">
<%= render partial: "secondary_navigation" %>
</div>

<div class="govuk-grid-column-two-thirds">
<%= render partial: "secondary_nav_tabs/#{current_tab}", :locals => { :publication => @resource } %>
</div>
</div>
21 changes: 19 additions & 2 deletions test/functional/editions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class EditionsControllerTest < ActionController::TestCase

context "#show" do
setup do
artefact2 = FactoryBot.create(
artefact = FactoryBot.create(
:artefact,
slug: "test2",
kind: "guide",
name: "test",
owning_app: "publisher",
)
@guide = GuideEdition.create!(title: "test", slug: "test2", panopticon_id: artefact2.id)
@guide = GuideEdition.create!(title: "test", slug: "test2", panopticon_id: artefact.id)
end

should "requesting a publication that doesn't exist returns a 404" do
Expand All @@ -47,4 +47,21 @@ class EditionsControllerTest < ActionController::TestCase
assert_not_nil assigns(:resource)
end
end

context "#metadata" do
setup do
artefact = FactoryBot.create(
:artefact,
slug: "test2",
kind: "guide",
name: "test",
owning_app: "publisher",
)
@guide = GuideEdition.create!(title: "test", slug: "test2", panopticon_id: artefact.id)
end

should "alias to show method" do
EditionsController.new.method(:show) == EditionsController.new.method(:metadata)
end
end
end
37 changes: 31 additions & 6 deletions test/integration/edition_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ class EditionEditTest < IntegrationTest
test_strategy = Flipflop::FeatureSet.current.test!
test_strategy.switch!(:design_system_edit, true)
stub_linkables
end

should "show document summary and title" do
edition = FactoryBot.create(:guide_edition, title: "Edit page title", state: "draft")
visit edition_path(edition)
end

should "show document summary and title" do
assert page.has_title?("Edit page title")

row = find_all(".govuk-summary-list__row")
Expand All @@ -24,9 +23,6 @@ class EditionEditTest < IntegrationTest
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")
Expand All @@ -35,4 +31,33 @@ class EditionEditTest < IntegrationTest
assert page.has_text?("Related external links")
assert page.has_text?("Unpublish")
end

context "#metadata" do
setup do
click_link("Metadata")
end

should "'Metadata' header and an update button" do
within :css, ".gem-c-heading" do
assert page.has_text?("Metadata")
end
assert page.has_button?("Update")
end

should "show slug input box prefilled" do
assert page.has_text?("Slug")
assert page.has_text?("If you change the slug of a published page, the old slug will automatically redirect to the new one.")
assert page.has_field?("artefact[slug]", with: /slug/)
end

should "update and show success message" do
fill_in "artefact[slug]", with: "changed-slug"
choose("Welsh")
click_button("Update")

assert find(".gem-c-radio input[value='cy']").checked?
assert page.has_text?("Metadata has successfully updated")
assert page.has_field?("artefact[slug]", with: "changed-slug")
end
end
end

0 comments on commit fa994b5

Please sign in to comment.