Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HasHelper interface #8922

Merged
merged 5 commits into from Sep 2, 2020
Merged

Add HasHelper interface #8922

merged 5 commits into from Sep 2, 2020

Conversation

DiegoCardoso
Copy link
Contributor

On this PR:

  • Add HasHelper interface to be used for field components that have a "helper" feature (such as TextField)
  • The interface contains getters and setters with default implementation for text and component APIs
  • Tests for the methods

Fix #8871


/**
* <p>
* String used for the helper text.
Copy link
Contributor

Choose a reason for hiding this comment

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

One might wonder, "what is helper text" as it is not that universal concept (yet?) compared to e.g. placeholder. At least could be unfamiliar for Java developers. So I think it would be good to add a clarification on "how/when it might be shown on the component"

Copy link
Contributor

Choose a reason for hiding this comment

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

And same for setHelperComponent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added text describing the feature more for both setters.

default void setHelperComponent(Component component) {
getElement().getChildren()
.filter(child -> "helper".equals(child.getAttribute("slot")))
.collect(Collectors.toList())
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary collecting to a list since it seems like there can only ever be one child with the slot=helper, so could go with findAny().ifPresent(...) instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Optional<Element> element = getElement().getChildren()
.filter(child -> "helper".equals(child.getAttribute("slot")))
.findFirst();
if (element.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary for readability as it adds more lines, could just use mapping to the Stream with map(Element::get) before findFirst() and then return component.orElse(null);.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed as suggested, but then findFirst() returns an Optional<Optional<Component>> object, so I had to add a .orElse(Optional.empty()).

@pleku pleku merged commit 838acb8 into 2.4 Sep 2, 2020
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Iteration Reviews to Done - pending release Sep 2, 2020
@pleku pleku deleted the feat/hashelper branch September 2, 2020 05:48
pleku pushed a commit that referenced this pull request Sep 2, 2020
* Add HasHelper interface (#8532)
@pleku
Copy link
Contributor

pleku commented Sep 2, 2020

PR to master (5.0) open too.

caalador pushed a commit that referenced this pull request Sep 2, 2020
* Add HasHelper interface (#8532)
@pleku pleku added +0.1.0 and removed +1.0.0 labels Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

None yet

3 participants