Skip to content

fix: close a notification on detach - #3154

Merged
tomivirkki merged 9 commits into
masterfrom
close-notification-on-detach
May 11, 2022
Merged

tomivirkki merged 9 commits into
masterfrom
close-notification-on-detach

Conversation

@tomivirkki

Copy link
Copy Markdown
Member

Fixes #3085

getElement().appendVirtualChild(container);

getElement().addEventListener("opened-changed", event -> {
addOpenedChangeListener(event -> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An "opened-changed" event only works if the Flow component doesn't get detached from its parent while the <vaadin-notification> Web Component is showing. Then we could rely on the DOM event to take care of getting this callback invoked.

But if the Flow component gets detached before the notification actually closes, the Web Component becomes an "orphan" without an active Flow counterpart and the following "opened-changed" event never reaches the callback.


// If the notificaiton gets detached, it needs to be marked as closed so
// it won't auto-open when reattached.
setOpened(false);

@vursen vursen May 10, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, this will trigger the openedChanged listener above bypassing the client-side, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intention but it seems there was some timing issue, so I needed to change the logic. Let's see if the newest revision passes.

Notification notification = Notification.show(
"This is a notification created with static convenience method");
notification.setId("static-notification");
addCard("Notification using static convenience method", notification);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test setup here was strange (yet supported): the notification was first auto-added to UI using Notification.show() but then the same instance got manually added to the card.

The assertion in the related test however was wrong. It assumed that the instance would automatically get removed from its parent on close even though it's manually re-added in the setup. This used to work because the order of checking the condition and beforeClientResponse was kind of backwards (this PR fixes the order & adds a related test).

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 109 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @tomivirkki and @tomivirkki, when i performed cherry-pick to this commit to 23.0, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick b2e88a6
error: could not apply b2e88a6... fix: close a notification on detach (#3154)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot

Copy link
Copy Markdown
Collaborator

Hi @tomivirkki and @tomivirkki, when i performed cherry-pick to this commit to 14.8, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick b2e88a6
error: could not apply b2e88a6... fix: close a notification on detach (#3154)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notification showing multiple times when auto-added to reused modal

4 participants