From c23889b3440c0b8eb664d6122156b7ec02af1016 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Dec 2024 20:12:00 +0100 Subject: [PATCH 1/2] add missing .html extension to flash_component --- .../op_primer/{flash_component.erb => flash_component.html.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/components/op_primer/{flash_component.erb => flash_component.html.erb} (100%) diff --git a/app/components/op_primer/flash_component.erb b/app/components/op_primer/flash_component.html.erb similarity index 100% rename from app/components/op_primer/flash_component.erb rename to app/components/op_primer/flash_component.html.erb From 1316b43b06a621a584ecde4a787386155ade6aeb Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Tue, 17 Dec 2024 12:34:46 +0100 Subject: [PATCH 2/2] remove container of flash message after it is closed, so that it doesn't become visible with next flash message --- app/components/op_primer/flash_component.rb | 2 ++ frontend/src/stimulus/controllers/flash.controller.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/components/op_primer/flash_component.rb b/app/components/op_primer/flash_component.rb index fed84bf511f7..15a445c03316 100644 --- a/app/components/op_primer/flash_component.rb +++ b/app/components/op_primer/flash_component.rb @@ -38,6 +38,8 @@ def initialize(**system_arguments) system_arguments[:test_selector] ||= "op-primer-flash-message" system_arguments[:dismiss_scheme] ||= :remove system_arguments[:dismiss_label] ||= I18n.t(:button_close) + system_arguments[:data] ||= {} + system_arguments[:data]["flash-target"] = "flash" @autohide = system_arguments[:scheme] == :success && system_arguments[:dismiss_scheme] != :none diff --git a/frontend/src/stimulus/controllers/flash.controller.ts b/frontend/src/stimulus/controllers/flash.controller.ts index d09aad6d196d..f97ad77f4d3c 100644 --- a/frontend/src/stimulus/controllers/flash.controller.ts +++ b/frontend/src/stimulus/controllers/flash.controller.ts @@ -11,9 +11,10 @@ export default class FlashController extends ApplicationController { static targets = [ 'item', + 'flash', // only to detect removal ]; - declare readonly itemTargets:HTMLElement; + declare readonly itemTargets:HTMLElement[]; reloadPage() { window.location.reload(); @@ -25,4 +26,12 @@ export default class FlashController extends ApplicationController { setTimeout(() => element.remove(), SUCCESS_AUTOHIDE_TIMEOUT); } } + + flashTargetDisconnected() { + this.itemTargets.forEach((target:HTMLElement) => { + if (target.innerHTML === '') { + target.remove(); + } + }); + } }