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: add MenuConfiguration #20138

Merged
merged 7 commits into from
Oct 4, 2024
Merged

feat: add MenuConfiguration #20138

merged 7 commits into from
Oct 4, 2024

Conversation

tltv
Copy link
Member

@tltv tltv commented Oct 3, 2024

New public API for building application menu: adds MenuConfiguration, MenuOptions and MenuOption where MenuConfiguration is the main entry point to access menu data to build main menu.

Fixes: #20063

@tltv tltv force-pushed the feat/20063-menu-configuration branch from 0042e6b to 42cc7ce Compare October 3, 2024 14:31
Copy link

github-actions bot commented Oct 3, 2024

Test Results

1 140 files  + 1  1 140 suites  +1   1h 8m 39s ⏱️ -23s
7 422 tests + 3  7 372 ✅ + 3  50 💤 ±0  0 ❌ ±0 
7 706 runs   - 15  7 648 ✅  - 16  58 💤 +1  0 ❌ ±0 

Results for commit 95ac4a7. ± Comparison against base commit aa83939.

♻️ This comment has been updated with latest results.

@tltv tltv force-pushed the feat/20063-menu-configuration branch from 42cc7ce to 4ff26d4 Compare October 4, 2024 07:05
@mshabarov mshabarov self-requested a review October 4, 2024 07:15
@tltv
Copy link
Member Author

tltv commented Oct 4, 2024

@Artur- do you have any feedback regarding this new public Menu API called MenuConfiguration. You updated Start app with MenuRegisty, so this new API would be a replacement for MenuRegistry. E.g. instead of calling MenuRegistry.collectMenuItemsList() you would call MenuConfiguration.getMenuOptions().get() which returns List<MenuOption>.

@Artur-
Copy link
Member

Artur- commented Oct 4, 2024

Is there a reason I should call MenuConfiguration.getMenuOptions().get() instead of MenuConfiguration.getMenuOptions() to get the menu options?

@tltv
Copy link
Member Author

tltv commented Oct 4, 2024

Is there a reason I should call MenuConfiguration.getMenuOptions().get() instead of MenuConfiguration.getMenuOptions() to get the menu options?

If you don't see reason, we might not need to do it this way. What do you think if MenuConfiguration.getMenuOptions() would just return List<MenuOption> directly? And especially what do you think of MenuOptions class in general, does it look like useful for developers or could we just go with a List instead?

I'm not so sure how useful MenuOptions would be. Also pinging @caalador for more input.

@caalador
Copy link
Contributor

caalador commented Oct 4, 2024

From the writing of the ticket the target was to get List<MenuOptions> which would be in the implemented case the same as List<MenuOption> (Options was noting that it contains multiple parameters instead of only being an Option)

@tltv
Copy link
Member Author

tltv commented Oct 4, 2024

From the writing of the ticket the target was to get List<MenuOptions> which would be in the implemented case the same as List<MenuOption> (Options was noting that it contains multiple parameters instead of only being an Option)

And MenuOption name was picked because MenuItem was already reserved by components. Let's wait if @mshabarov had some idea with splitting in MenuOptions and MenuOption in ticket requirements. Maybe we can remove MenuOptions. Naming properly is still a bit challenging here.

@mshabarov
Copy link
Contributor

I was thinking that MenuOptions class could have List<MenuOption> and some other fields that are common to menu. However, I don't know what would this be and, if we need to expose it, we can add a new method in MenuConfiguration.
Additionally, the code that renders menu should be as simple as

MenuConfiguration.getMenuOptions().forEach(option -> new SideNavItem(option.getTitle(), option.getRoute()));

Thus, I agree that we could simplify it to have just a collection of MenuOption.

@mshabarov
Copy link
Contributor

Possible alternatives are MenuEntry, MenuAction, MenuChoice, MenuNode,MenuCommand, MenuLinkData.

How about MenuEntry ?

@tltv
Copy link
Member Author

tltv commented Oct 4, 2024

How about MenuEntry ?

MenuEntry is also vacant. +1 from me.

*
* @return the {@link MenuOptions} instance
*/
public static MenuOptions getMenuOptions() {
Copy link
Contributor

@mshabarov mshabarov Oct 4, 2024

Choose a reason for hiding this comment

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

this probably should expose the same method, but with Locale (to allows alphabetical order based on exact translation)

*
* @return the {@link MenuOptions} instance
*/
public static MenuOptions getMenuOptions() {
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 see MenuRegistry javadocs update, these are needed to highlight it's internal use.

* path to the icon. E.g. 'line-awesome/svg/lock-open-solid.svg'.
* @param menuClass
* the source class with {@link com.vaadin.flow.router.Menu}
* annotation or null if not available
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth to mention that for menu entries pointing to Hilla/TypeScript views, this will be null

/**
* Data class for menu item information.
* <p>
* Only for read as data is immutable.
*/
public record MenuData(String title, Double order, boolean exclude, String icon) implements Serializable {
public record MenuData(String title, Double order, boolean exclude, String icon, Class<? extends Component> menuClass) implements Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be deprecated and marked for internal use. We can't delete it as it's already shipped with 24.4, but we either shouldn't encourage it to be used in public API.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Someone might use it already with 24.4 so need to keep and deprecate old. But it's also part of the public RouteData API which is not internal API and it's in 24.4. Marking it internal now is not possible afaik.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, okay, let's keep it as is then.


/**
* Menu configuration helper class to retrieve available menu entries for
* application main menu.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add "since 24.5" note

*
* @since 24.5
*/
public class MenuConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can be final class

mshabarov
mshabarov previously approved these changes Oct 4, 2024
New public API for building application menu: adds `MenuConfiguration`, `MenuOptions` and `MenuOption` where `MenuConfiguration` is the main entry point to access menu data to build main menu.

Fixes: #20063
Renamed MenuOption to MenuEntry.
Removed Serializable from MenuConfiguration.
Copy link

sonarcloud bot commented Oct 4, 2024

@tltv
Copy link
Member Author

tltv commented Oct 4, 2024

Drafted PR that updates imports in Hilla: vaadin/hilla#2794
After this one is merged, that one should be merged too.

@tltv tltv marked this pull request as ready for review October 4, 2024 11:05
@mshabarov mshabarov merged commit 4cf08cf into main Oct 4, 2024
26 checks passed
@mshabarov mshabarov deleted the feat/20063-menu-configuration branch October 4, 2024 11:29
vaadin-bot pushed a commit that referenced this pull request Oct 4, 2024
* feat: add MenuConfiguration

New public API for building application menu: adds `MenuConfiguration`, `MenuOptions` and `MenuOption` where `MenuConfiguration` is the main entry point to access menu data to build main menu.

Fixes: #20063

* chore: renamed classes and removed MenuOptions

Renamed MenuOption to MenuEntry.

* chore: updated javadocs

* chore: moved MenuRegistry to internal package

Removed Serializable from MenuConfiguration.

* chore: added javadoc and deprecated MenuData constructor

* chore: use new constructor

* chore: make MenuConfiguration final
mshabarov pushed a commit that referenced this pull request Oct 4, 2024
* feat: add MenuConfiguration

New public API for building application menu: adds `MenuConfiguration`, `MenuOptions` and `MenuOption` where `MenuConfiguration` is the main entry point to access menu data to build main menu.

Fixes: #20063

* chore: renamed classes and removed MenuOptions

Renamed MenuOption to MenuEntry.

* chore: updated javadocs

* chore: moved MenuRegistry to internal package

Removed Serializable from MenuConfiguration.

* chore: added javadoc and deprecated MenuData constructor

* chore: use new constructor

* chore: make MenuConfiguration final

Co-authored-by: Tomi Virtanen <[email protected]>
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.

Generate MenuItems api for application menu generation
5 participants