Skip to content

feat: allow adding true modal dialogs to UI - #12434

Merged
joheriks merged 17 commits into
masterfrom
fix/10172
Dec 28, 2021
Merged

joheriks merged 17 commits into
masterfrom
fix/10172

Conversation

@pleku

@pleku pleku commented Nov 24, 2021 •

Copy link
Copy Markdown

Introduces the possibility to add a modal dialog to a UI in a way
that the server side will ignore interaction with all other components
(from client side) until the modal dialog is removed. Modal dialogs can
be stacked on top of each other. This is similar to setting a component disabled,
but is not the same and does not show in the UI in any way - it would be
up to the modal dialog to show a modalityy curtain on top of the outside
UI to the dialog. The feature is thus a server side security feature,
and makes the framework enforce
https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal guidelines.

The implementation relies on a new server side only state tree feature InertData, which
makes it possible to make a component/element/statenode and its children not accept any
updates from client side, but it not the same as disabled. The inert
state is by default inherited to child nodes, except that any child can declare
itself to ignore parent inert state which means that updates are allowed for
itself and its children, unless those are explicitly made inert.

WIP:

  • missing bunch of integration tests for trying to break inept UI,
    which are TODOs in InertComponentIT
  • this also disables all UI level listeners - like UI resize listener, which might not be desirable
  • IT for checking that when @PreserverOnRefresh is used, the inert state of UI is still intact

Resolves #10172

@knoobie

knoobie commented Nov 24, 2021

Copy link
Copy Markdown
Contributor

Just a note: this could be really awesome for other use cases as well, like blocking the UI while a long running task is enqueued - e.g. pressing a button and ignoring every other client action until the server is done.

@pleku

pleku commented Nov 25, 2021 •

Copy link
Copy Markdown
Author

Just a note: this could be really awesome for other use cases as well, like blocking the UI while a long running task is enqueued - e.g. pressing a button and ignoring every other client action until the server is done.

Ok, thanks for the suggestion. I think then I'll retain the API in the UI to keep it discoverable, but I have to think about the naming.
I would think that in those cases - when the UI is blocked - there would be a notification/dialog shown to the user that tells them to wait, and typically that would be something that has a modality-curtain shown too (like Dialog).

@knoobie

knoobie commented Nov 25, 2021

Copy link
Copy Markdown
Contributor

Having this API inside the UI would be really good way to discover it! I wanted to mention the other use case because they probably work a little bit different like the dialog use case, as e.g. buttons aren't removed - they just finish they job. I had the following pattern in mind where no additional overlay is added vaadin/web-components#842

Naming is probably the hardest part here - still awesome addition!

@pleku

pleku commented Nov 29, 2021 •

Copy link
Copy Markdown
Author

Having this API inside the UI would be really good way to discover it! I wanted to mention the other use case because they probably work a little bit different like the dialog use case, as e.g. buttons aren't removed - they just finish they job. I had the following pattern in mind where no additional overlay is added vaadin/web-components#842

I think for this case it would be simply enough to make the UI inert and set nothing modal to it - but currently the API design in the UI doesn't directly allow this. This API can be added quite easily later on. It is also just possible to just add an invisible modal component to the UI 😄 and it will be the same effect. Or by getting the root layout (under UI) and setting it as modal via the setter in UI.

Like the current API's javadocs says - the developer/component needs to just take care of showing a clear indication to the user that something is happening and the UI won't work - so the user won't try to do something while waiting.

*/
public void toggleChildModal(Component child) {
if (modalComponentStack == null) {
modalComponentStack = new Stack<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

JdkObsolete: Stack is a nonstandard class that predates the Java Collections Framework; prefer ArrayDeque. Note that the Stack methods push/pop/peek correspond to the Deque methods addFirst/removeFirst/peekFirst.
(at-me in a reply with help or ignore)

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.

Would make sense to use ArrayDeque.

// cascade update to all children unless those are ignoring parent
// value or have same value and thus don't need updating.
// (all explicitly updated nodes are visited separately)
LinkedList<StateNode> stack = new LinkedList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

JdkObsolete: It is very rare for LinkedList to out-perform ArrayList or ArrayDeque. Avoid it unless you're willing to invest a lot of time into benchmarking. Caveat: LinkedList supports null elements, but ArrayDeque does not.
(at-me in a reply with help or ignore)

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.

Would make sense to use ArrayDeque.

// cascade update to all children unless those are ignoring parent
// value or have same value and thus don't need updating.
// (all explicitly updated nodes are visited separately)
LinkedList<StateNode> stack = new LinkedList<>();

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.

Would make sense to use ArrayDeque.

*/
public void toggleChildModal(Component child) {
if (modalComponentStack == null) {
modalComponentStack = new Stack<>();

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.

Would make sense to use ArrayDeque.

Comment thread flow-client/src/main/frontend/Flow.ts Resolved
@joheriks joheriks changed the title WIP: feat: allow adding true modal dialogs to UI feat: allow adding true modal dialogs to UI Dec 22, 2021
@joheriks
joheriks marked this pull request as ready for review December 22, 2021 08:14
@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Dec 22, 2021
@github-actions

github-actions Bot commented Dec 22, 2021 •

Copy link
Copy Markdown
Contributor

Unit Test Results

   721 files     721 suites   19m 4s ⏱️
5 665 tests 5 616 ✔️ 49 💤 0 ❌
5 681 runs  5 632 ✔️ 49 💤 0 ❌

Results for commit 1657d53.

♻️ This comment has been updated with latest results.

+ "Add it first as a child of the UI with "
+ "ui.add(component) or just use addModal(component).");
childComponent.getParent().filter(parent -> parent == this)
.orElseThrow(illegalStateExceptionSupplier);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ReturnValueIgnored: Return value of 'orElseThrow' must be used (details)
(at-me in a reply with help or ignore)

@joheriks
joheriks force-pushed the fix/10172 branch 2 times, most recently from 3ceae7d to 940db66 Compare December 22, 2021 14:10
@joheriks
joheriks self-requested a review December 22, 2021 14:30
joheriks
joheriks previously approved these changes Dec 28, 2021
@vaadin-bot

Copy link
Copy Markdown
Collaborator

SonarQube analysis reported 10 issues

  1. MAJOR UI.java#L519: Reduce this anonymous class number of lines from 30 to at most 20, or make it a named class. rule
  2. MAJOR UI.java#L1030: Call "Optional#isPresent()" before accessing the value. rule
  3. MAJOR UIInternals.java#L1162: Merge this if statement with the enclosing one. rule
  4. MAJOR PublishedServerEventHandlerRpcHandler.java#L202: A "NullPointerException" could be thrown; "instance" is nullable here. rule
  5. MAJOR PublishedServerEventHandlerRpcHandler.java#L208: A "NullPointerException" could be thrown; "instance" is nullable here. rule
  6. MAJOR PublishedServerEventHandlerRpcHandler.java#L298: Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed. rule
  7. MINOR UI.java#L1019: Remove the declaration of thrown exception 'java.lang.IllegalArgumentException' which is a runtime exception. rule
  8. MINOR UIInternals.java#L723: This call to "contains()" may be a performance hot spot if the collection is large. rule
  9. MINOR PublishedServerEventHandlerRpcHandler.java#L166: Replace this lambda with a method reference. rule
  10. INFO UI.java#L1273: Complete the task associated to this TODO comment. rule

@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

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

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 23.0.0.alpha1 and is also targeting the upcoming stable 23.0.0 version.

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.

An opened Dialog component does not disable the UI to which it belongs.

6 participants