From fb3dfc98e47ecb442a6568c6b228afd8989a2c5e 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 ece539d15..7638f26a7 100644 --- a/app/frontend/controllers/index.js +++ b/app/frontend/controllers/index.js @@ -14,9 +14,13 @@ import GovukfrontendController from './govukfrontend_controller.js' import NumericQuestionController from './numeric_question_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) application.register('govukfrontend', GovukfrontendController) application.register('numeric-question', NumericQuestionController) application.register('filter-layout', FilterLayoutController) +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 %>
+
<% 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 %>+
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.
- +