Skip to content

Commit

Permalink
Merge pull request #4275 from DFE-Digital/1734-bug-copy-content-drop-…
Browse files Browse the repository at this point in the history
…down-disappears-after-validation

[1734] bug copy content drop down disappears after validation, broken links in copy content warning
  • Loading branch information
elceebee authored Jun 14, 2024
2 parents a646e15 + c09b556 commit ea3f4e3
Show file tree
Hide file tree
Showing 25 changed files with 482 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if field_links.present? %>
<%= govuk_notification_banner(
title_text: t("notification_banner.warning"),
classes: "govuk-notification-banner--warning",
html_attributes: {
data: { qa: "copy-course-warning" },
role: "alert"
}
) do |notification_banner| %>
<% notification_banner.with_heading(
text: t("components.providers.copy_course_content_warning_component.changes_not_saved")
) %>
<p class="govuk-body">
<%= copied_fields_from %>
</p>
<ul class="govuk-list">
<% field_links.each do |name, target| %>
<li><%= govuk_link_to name, target, class: "govuk-notification-banner__link" %></li>
<% end %>
</ul>
<p class="govuk-body"><%= please_check_changes %></p>
<% end %>
<% end %>
35 changes: 35 additions & 0 deletions app/components/providers/copy_course_content_warning_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Providers
class CopyCourseContentWarningComponent < ApplicationComponent
def initialize(copied_fields, form_identifier, source_course, **)
super(**)
@copied_fields = copied_fields
@form_identifier = form_identifier
@source_course = source_course
end

def field_links
@copied_fields.map do |name, field|
[name, "##{@form_identifier}-#{field.gsub('_', '-')}-field"]
end
end

def please_check_changes
translation_base = 'components.providers.copy_course_content_warning_component.please_check_changes'
I18n.t("#{translation_base}.#{plural? ? 'plural' : 'singular'}")
end

def copied_fields_from
translation_base = 'components.providers.copy_course_content_warning_component.copied_fields_from'
I18n.t(
"#{translation_base}.#{plural? ? 'plural' : 'singular'}",
name_and_code: "#{@source_course.name} (#{@source_course.course_code})"
)
end

def plural?
@copied_fields.length > 1
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def update

redirect_to redirect_path
else
fetch_course_list_to_copy_from
render :edit
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update
redirect_to preview_publish_provider_recruitment_cycle_course_path(provider.provider_code, course.recruitment_cycle_year, course.course_code)
else
set_backlink
fetch_course_list_to_copy_from
@errors = @subject_requirements_form.errors.messages
render :edit
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def update
@gcse_requirements_form.save(course)
redirect_to publish_provider_recruitment_cycle_course_path
else
fetch_course_list_to_copy_from
@errors = @gcse_requirements_form.errors.messages
render :edit
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def update

redirect_to redirect_path
else
fetch_course_list_to_copy_from
render :edit
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def update

redirect_to preview_or_course_description
else
fetch_course_list_to_copy_from
render :edit
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/services/courses/copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module Courses
class Copy
GCSE_FIELDS = [
['Accept pending GCSE', 'accept_pending_gcse'],
['Accept GCSE equivalency', 'accept_gcse_equivalency'],
['Accept English GCSE equivalency', 'accept_english_gcse_equivalency'],
['Accept Maths GCSE equivalency', 'accept_maths_gcse_equivalency'],
['Additional GCSE equivalencies', 'additional_gcse_equivalencies']
['Accept pending GCSE', 'accept_pending_gcse', 'accept-pending-gcse-true'],
['Accept GCSE equivalency', 'accept_gcse_equivalency', 'accept-gcse-equivalency-true'],
['Accept English GCSE equivalency', 'accept_english_gcse_equivalency', 'accept-english-gcse-equivalency-english'],
['Accept Maths GCSE equivalency', 'accept_maths_gcse_equivalency', 'accept-maths-gcse-equivalency-maths'],
['Additional GCSE equivalencies', 'additional_gcse_equivalencies', 'additional-gcse-equivalencies']
].freeze

SUBJECT_REQUIREMENTS_FIELDS = [
Expand Down

This file was deleted.

6 changes: 5 additions & 1 deletion app/views/publish/courses/about_this_course/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
) %>
<% if params[:copy_from].present? && @copied_fields.any? %>
<%= render partial: "copy_about_course_content_warning" %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields,
"publish-course-about-this-course-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<% end %>
<% if params[:copy_from].present? %>
<%= render partial: "publish/courses/copy_content_warning", locals: { copied_fields: @copied_fields } %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields,
"publish-subject-requirement-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
6 changes: 5 additions & 1 deletion app/views/publish/courses/fees/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<% content_for :page_title, title_with_error_prefix("#{page_title} – #{@course.name_and_code}", @course_fee_form.errors.any?) %>
<% if params[:copy_from].present? %>
<%= render partial: "publish/courses/copy_content_warning", locals: { copied_fields: @copied_fields } %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields,
"publish-course-information-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
6 changes: 5 additions & 1 deletion app/views/publish/courses/gcse_requirements/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<% content_for :page_title, title_with_error_prefix(page_title, @errors && @errors.any?) %>
<% if params[:copy_from].present? %>
<%= render partial: "publish/courses/copy_content_warning", locals: { copied_fields: @copied_fields } %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields.map { |name, _field, target| [name, target] },
"publish-gcse-requirements-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down

This file was deleted.

8 changes: 6 additions & 2 deletions app/views/publish/courses/interview_process/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
@interview_process_form.errors.any?
) %>
<% if params[:copy_from].present? && @copied_fields.any? %>
<%= render partial: "copy_interview_process_content_warning" %>
<% if params[:copy_from].present? %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields,
"publish-course-interview-process-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down

This file was deleted.

6 changes: 5 additions & 1 deletion app/views/publish/courses/school_placements/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
) %>
<% if params[:copy_from].present? && @copied_fields.any? %>
<%= render partial: "copy_school_placements_content_warning", locals: { copied_fields: @copied_fields } %>
<%= render Providers::CopyCourseContentWarningComponent.new(
@copied_fields,
"publish-course-school-placements-form",
@source_course
) %>
<% end %>

<div class="govuk-grid-row">
Expand Down
18 changes: 9 additions & 9 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ en:
school_direct_salaried_training_programme:
label: "Salaried"
components:
providers:
copy_course_content_warning_component:
copied_fields_from:
plural: "We have copied these fields from %{name_and_code}:"
singular: "We have copied this field from %{name_and_code}:"
please_check_changes:
plural: Please check them and make your changes before saving
singular: Please check it and make your changes before saving
changes_not_saved: Your changes are not yet saved
page_titles:
sign_in:
index: "Sign in"
Expand Down Expand Up @@ -384,9 +393,6 @@ en:
interview_process_success: Interview process
page_title: Interview process (optional) - %{course_name_and_code}
submit_button: Update interview process
changes_not_saved: Your changes are not yet saved
copied_fields_from: We have copied this field from %{name_and_code}.
please_check_changes: Please check it and make your changes before saving.
include_information_about_html:
<p class="govuk-body">Include information about:</p>
<ul class="govuk-list govuk-list--bullet">
Expand Down Expand Up @@ -427,9 +433,6 @@ en:
You will be placed in different schools during your training. You cannott pick which schools you want to
be in, but your training provider will place you in schools you can travel to.
</p>
changes_not_saved: Your changes are not yet saved
copied_fields_from: We have copied this field from %{name_and_code}.
please_check_changes: Please check it and make your changes before saving.
about_course:
edit:
about_this_course: About this course
Expand All @@ -455,9 +458,6 @@ en:
<li>link to your organisation's website for people who want more detail about who you are and what you do</li>
</ul>
view_examples: View examples of great course summaries
changes_not_saved: Your changes are not yet saved
copied_fields_from: We have copied this field from %{name_and_code}.
please_check_changes: Please check it and make your changes before saving.
study_mode:
form:
select_all_that_apply: Select all that apply
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module Providers
class CopyCourseContentWarningComponentPreview < ViewComponent::Preview
def with_many_fields
source_course = Course.new(name: 'Course name', course_code: 'AFGT')
copied_fields = [
['About this course', 'about_this_course'],
['How placements work', 'how_placements_work']
]
render(
CopyCourseContentWarningComponent.new(
copied_fields,
'form-identifier',
source_course
)
)
end

def with_one_field
source_course = Course.new(name: 'Course name', course_code: 'AFGT')
copied_fields = [['How placements work', 'how_placements_work']]
render(
CopyCourseContentWarningComponent.new(
copied_fields,
'form-identifier',
source_course
)
)
end
end
end
Loading

0 comments on commit ea3f4e3

Please sign in to comment.