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

feat: Find a parent component with a given type #14002

Merged
merged 7 commits into from Jun 23, 2022
Merged

Conversation

mstahv
Copy link
Member

@mstahv mstahv commented Jun 16, 2022

Description

Add a helper method to seek the parent component of given type from the component tree.

Fixes #13984

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@github-actions
Copy link

github-actions bot commented Jun 16, 2022

Unit Test Results

   980 files     980 suites   51m 8s ⏱️
6 316 tests 6 268 ✔️ 48 💤 0
6 578 runs  6 524 ✔️ 54 💤 0

Results for commit 7c24416.

♻️ This comment has been updated with latest results.

@mshabarov mshabarov added the Contribution PRs coming from the community or external to the team label Jun 20, 2022
@mcollovati
Copy link
Collaborator

Personally I don't like that much the idea of traversing the tree and directly interact with an ancestor component, but I can get the points expressed in the related issue.
In addition we do not prevent this in any way and I'm pretty sure many developer may have already implemented such a helper on their own projects.

Some cosiderations on the proposed implementation:

  • I would maybe move the implementation to ComponentUtil class since we already have some traversal helpers in that class.
  • If instead we want to have it in Component, I think the API should not be public. I see it more as an internal helper for the component, rather than a way to traverse tree from outside.
  • Do not restrict the component type to Component make sense to me; it is implicit that we will find a Component, but it may be useful to search it for example by a mixin or a custom interface.
  • I would maybe call the method findAncestor rather than findParent

@mstahv
Copy link
Member Author

mstahv commented Jun 21, 2022

ComponentUtil feels like a set of internal helpers to me and it is not documented at all (other than JavaDocs), so I think far less developers would find it from there.

Renamed. Much better!

Also make protected. This is bit controversial. I guess most often one uses that from component, so protected should be fine, but somehow I have a feeling that someday I find my self opening that method directly as public in some Vaadin view 🤷‍♂️

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.1.0 labels Jun 21, 2022
Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

I would still move the implementation to ComponentUtil and then have the method in Component that delegates to it.
But it is up to you.
Other than that, LGTM

Copy link
Contributor

@mshabarov mshabarov left a comment

Choose a reason for hiding this comment

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

I would still move the implementation to ComponentUtil and then have the method in Component that delegates to it.

This sounds better for me as well.
By the way, I don't get the idea why you made it protected? The use case is to get the layout/menu or other high level component to modify it somehow. This method is invoked for some child component, so should the application actually extend the component to use this API, since is a protected, not public.
I would make it public, but transfer the implementation to the utils.

@mcollovati
Copy link
Collaborator

I suggested to make the method protected

I see it more as an internal helper for the component, rather than a way to traverse tree from outside

But it seems that I'm the only one that do not see the usage from outside a component, so let it be public 😄

@mstahv
Copy link
Member Author

mstahv commented Jun 22, 2022

Reverted back to public.

Are we sure about having the actual implementation delegated to ComponentUtil 🤔 Then we would have basically the same method in two places. Would somebody want to have it in ComponentUtil if it is available as a public instance method 🤔

@mshabarov
Copy link
Contributor

Well, I would say it can be reused when moved to utils. But it can also be reused if placed to component directly.

mshabarov
mshabarov previously approved these changes Jun 22, 2022
@mstahv
Copy link
Member Author

mstahv commented Jun 22, 2022

👌 I'll write some basic unit test for this and convert to actual PR.

@mstahv mstahv marked this pull request as ready for review June 22, 2022 14:10
@mstahv
Copy link
Member Author

mstahv commented Jun 22, 2022

@mshabarov I'm ready with this!

@sonarcloud
Copy link

sonarcloud bot commented Jun 22, 2022

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 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Jun 22, 2022
@mshabarov mshabarov changed the title Feature/find parent feat: Find a parent component with a given type Jun 23, 2022
@mshabarov mshabarov merged commit 171ae45 into master Jun 23, 2022
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Iteration Reviews to Done - pending release Jun 23, 2022
@mshabarov mshabarov deleted the feature/find-parent branch June 23, 2022 05:41
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 23.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution PRs coming from the community or external to the team Released with Vaadin 23.2.0 +0.1.0
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

Add a method to find the active view (or parent view/layout)
4 participants