From e963572972bcb57346b78274df84d50984230699 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:26:59 +0100 Subject: [PATCH] CLDC-2100++ Add success notification after delete (#2589) --- app/controllers/merge_requests_controller.rb | 3 +- app/frontend/controllers/index.js | 4 +++ app/frontend/controllers/tabs_controller.js | 35 +++++++++++++++++++ app/helpers/merge_requests_helper.rb | 2 +- app/views/layouts/application.html.erb | 3 +- .../_notification_banners.html.erb | 4 +-- .../absorbing_organisation.html.erb | 2 +- .../delete_confirmation.html.erb | 2 +- .../merge_requests/helpdesk_ticket.html.erb | 2 +- .../merging_organisations.html.erb | 2 +- app/views/merge_requests/show.html.erb | 2 +- app/views/organisations/index.html.erb | 2 +- spec/requests/merge_request_spec.rb | 2 +- .../merge_requests_controller_spec.rb | 2 +- 14 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 app/frontend/controllers/tabs_controller.js diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index f19224a92..c0fc40092 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -54,7 +54,8 @@ class MergeRequestsController < ApplicationController def delete @merge_request.discard! - redirect_to organisations_path(anchor: "merge-requests") + flash[:notice] = "The merge request has been deleted." + redirect_to organisations_path(tab: "merge-requests") end def merging_organisations diff --git a/app/frontend/controllers/index.js b/app/frontend/controllers/index.js index ef29b99ca..944e32e2d 100644 --- a/app/frontend/controllers/index.js +++ b/app/frontend/controllers/index.js @@ -16,6 +16,9 @@ import NumericQuestionController from './numeric_question_controller.js' import SearchController from './search_controller.js' import FilterLayoutController from './filter_layout_controller.js' + +import TabsController from './tabs_controller.js' + application.register('accessible-autocomplete', AccessibleAutocompleteController) application.register('conditional-filter', ConditionalFilterController) application.register('conditional-question', ConditionalQuestionController) @@ -23,3 +26,4 @@ application.register('govukfrontend', GovukfrontendController) application.register('numeric-question', NumericQuestionController) application.register('filter-layout', FilterLayoutController) application.register('search', SearchController) +application.register('tabs', TabsController) diff --git a/app/frontend/controllers/tabs_controller.js b/app/frontend/controllers/tabs_controller.js new file mode 100644 index 000000000..7cfd65bbb --- /dev/null +++ b/app/frontend/controllers/tabs_controller.js @@ -0,0 +1,35 @@ +document.addEventListener('DOMContentLoaded', function () { + const urlParams = new URLSearchParams(window.location.search) + let tab = urlParams.get('tab') + + if (!tab && window.location.hash) { + tab = window.location.hash.substring(1) + urlParams.set('tab', tab) + window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) + } + function activateTab (tabId) { + const tabElement = document.getElementById(tabId) + if (tabElement) { + tabElement.click() + } + window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) + } + + function handleTabClick (event) { + event.preventDefault() + const targetId = this.getAttribute('href').substring(1) + activateTab(targetId) + urlParams.set('tab', targetId) + window.history.replaceState(null, null, `${window.location.pathname}?${urlParams.toString()}`) + } + + if (tab) { + activateTab(`tab_${tab}`) + } + + window.scrollTo(0, 0) + + document.querySelectorAll('.govuk-tabs__tab').forEach(tabElement => { + tabElement.addEventListener('click', handleTabClick) + }) +}) diff --git a/app/helpers/merge_requests_helper.rb b/app/helpers/merge_requests_helper.rb index 4d7408349..c018a99df 100644 --- a/app/helpers/merge_requests_helper.rb +++ b/app/helpers/merge_requests_helper.rb @@ -59,7 +59,7 @@ module MergeRequestsHelper case page when "absorbing_organisation" - organisations_path(anchor: "merge-requests") + organisations_path(tab: "merge-requests") when "merging_organisations" absorbing_organisation_merge_request_path(merge_request) when "merge_date" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1ed5014c3..9e68fa7b4 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -126,7 +126,8 @@ <%= govuk_notification_banner( title_text: "Success", success: true, title_heading_level: 3, - title_id: "flash-notice" + title_id: "flash-notice", + role: "alert" ) do |notification_banner| notification_banner.with_heading(text: flash.notice.html_safe) if flash[:notification_banner_body] diff --git a/app/views/merge_requests/_notification_banners.html.erb b/app/views/merge_requests/_notification_banners.html.erb index 7674773ab..38c05dbcd 100644 --- a/app/views/merge_requests/_notification_banners.html.erb +++ b/app/views/merge_requests/_notification_banners.html.erb @@ -2,7 +2,7 @@ <%= govuk_notification_banner(title_text: "Important") do %>

The absorbing organisation must accept the Data Sharing Agreement before merging. -

+

<% if @merge_request.dpo_user %> Contact the Data Protection Officer: <%= link_to @merge_request.dpo_user.name, user_path(@merge_request.dpo_user.id) %> <% else %> @@ -15,7 +15,7 @@ <%= govuk_notification_banner(title_text: "Important") do %>

An error occurred while processing the merge. -

+

No changes have been made. Try beginning the merge again. <% end %> <% end %> diff --git a/app/views/merge_requests/absorbing_organisation.html.erb b/app/views/merge_requests/absorbing_organisation.html.erb index 40faa88f5..f50bfe943 100644 --- a/app/views/merge_requests/absorbing_organisation.html.erb +++ b/app/views/merge_requests/absorbing_organisation.html.erb @@ -11,7 +11,7 @@

If organisations are merging into a new organisation, <%= govuk_link_to "create the new organisation", new_organisation_path %> first and then select it here.

- +
<%= f.govuk_select(:absorbing_organisation_id, label: { text: "Select organisation name", class: "govuk-label--m" }, "data-controller": "accessible-autocomplete") do %> diff --git a/app/views/merge_requests/delete_confirmation.html.erb b/app/views/merge_requests/delete_confirmation.html.erb index c874946b2..d95ebba63 100644 --- a/app/views/merge_requests/delete_confirmation.html.erb +++ b/app/views/merge_requests/delete_confirmation.html.erb @@ -9,7 +9,7 @@ <%= content_for(:title) %> - <%= govuk_warning_text(text: "You cannot undo this.") %> + <%= govuk_warning_text(text: "You will not be able to undo this action.") %>
<%= govuk_button_to( diff --git a/app/views/merge_requests/helpdesk_ticket.html.erb b/app/views/merge_requests/helpdesk_ticket.html.erb index 18e06121b..e2a47653d 100644 --- a/app/views/merge_requests/helpdesk_ticket.html.erb +++ b/app/views/merge_requests/helpdesk_ticket.html.erb @@ -14,7 +14,7 @@
- <%= f.govuk_text_field :helpdesk_ticket, caption: { text: "Ticket number", class: "govuk-label--m" }, label: { text: "For example, MSD-12345" } %> + <%= f.govuk_text_field :helpdesk_ticket, caption: { text: "Ticket number", class: "govuk-label govuk-label--s" }, label: { text: "For example, MSD-12345", class: "app-!-colour-muted" } %> <%= f.hidden_field :page, value: "helpdesk_ticket" %>
<%= f.govuk_submit submit_merge_request_button_text(request.query_parameters["referrer"]) %> diff --git a/app/views/merge_requests/merging_organisations.html.erb b/app/views/merge_requests/merging_organisations.html.erb index 76a03e16e..02df05032 100644 --- a/app/views/merge_requests/merging_organisations.html.erb +++ b/app/views/merge_requests/merging_organisations.html.erb @@ -11,7 +11,7 @@

Add all organisations that are merging.

- +
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: { label: { text: "Select an organisation", class: "govuk-label--m" }, field: :merging_organisation, diff --git a/app/views/merge_requests/show.html.erb b/app/views/merge_requests/show.html.erb index c93e99738..a211da034 100644 --- a/app/views/merge_requests/show.html.erb +++ b/app/views/merge_requests/show.html.erb @@ -1,7 +1,7 @@ <% content_for :before_content do %> <% title = "Merge details: #{@merge_request.absorbing_organisation_name}" %> <% content_for :title, title %> - <%= govuk_back_link href: organisations_path(anchor: "merge-requests") %> + <%= govuk_back_link href: organisations_path(tab: "merge-requests") %> <% end %> <%= render partial: "notification_banners" %> diff --git a/app/views/organisations/index.html.erb b/app/views/organisations/index.html.erb index 64c311472..3b96288f1 100644 --- a/app/views/organisations/index.html.erb +++ b/app/views/organisations/index.html.erb @@ -5,7 +5,7 @@ <%= render partial: "organisations/headings", locals: request.path == organisations_path ? { main: "Organisations", sub: nil } : { main: @organisation.name, sub: "Organisations" } %> -
+
<%= govuk_tabs(title: "Collection resources", classes: %w[app-tab__large-headers]) do |c| %> <% c.with_tab(label: "All organisations") do %> <%= govuk_button_link_to "Create a new organisation", new_organisation_path, html: { method: :get } %> diff --git a/spec/requests/merge_request_spec.rb b/spec/requests/merge_request_spec.rb index 3666244dd..c7302b632 100644 --- a/spec/requests/merge_request_spec.rb +++ b/spec/requests/merge_request_spec.rb @@ -20,7 +20,7 @@ RSpec.describe MergeRequest, type: :request do it "redirects to the merge request list" do delete delete_merge_request_path(merge_request) - expect(response).to redirect_to(organisations_path(anchor: "merge-requests")) + expect(response).to redirect_to(organisations_path(tab: "merge-requests")) follow_redirect! expect(page).to have_content("Merge requests") end diff --git a/spec/requests/merge_requests_controller_spec.rb b/spec/requests/merge_requests_controller_spec.rb index 899def900..8b7a577a7 100644 --- a/spec/requests/merge_requests_controller_spec.rb +++ b/spec/requests/merge_requests_controller_spec.rb @@ -202,7 +202,7 @@ RSpec.describe MergeRequestsController, type: :request do end it "has the correct back button" do - expect(page).to have_link("Back", href: organisations_path(anchor: "merge-requests")) + expect(page).to have_link("Back", href: organisations_path(tab: "merge-requests")) end end