-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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]>
- Loading branch information
1 parent
a310a43
commit f98f828
Showing
15 changed files
with
464 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
flow-server/src/main/java/com/vaadin/flow/server/menu/MenuConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.server.menu; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import com.vaadin.flow.internal.menu.MenuRegistry; | ||
|
||
/** | ||
* Menu configuration helper class to retrieve available menu entries for | ||
* application main menu. | ||
* | ||
* @since 24.5 | ||
*/ | ||
public final class MenuConfiguration { | ||
|
||
/** | ||
* Collect ordered list of menu entries for menu population. All client | ||
* views are collected and any accessible server views. | ||
* | ||
* @return ordered list of {@link MenuEntry} instances | ||
*/ | ||
public static List<MenuEntry> getMenuEntries() { | ||
return MenuRegistry.collectMenuItemsList().stream() | ||
.map(MenuConfiguration::createMenuEntry).toList(); | ||
} | ||
|
||
/** | ||
* Collect ordered list of menu entries for menu population. All client | ||
* views are collected and any accessible server views. | ||
* | ||
* @param locale | ||
* locale to use for ordering. null for default locale. | ||
* | ||
* @return ordered list of {@link MenuEntry} instances | ||
*/ | ||
public static List<MenuEntry> getMenuEntries(Locale locale) { | ||
return MenuRegistry.collectMenuItemsList(locale).stream() | ||
.map(MenuConfiguration::createMenuEntry).toList(); | ||
} | ||
|
||
private static MenuEntry createMenuEntry(AvailableViewInfo viewInfo) { | ||
if (viewInfo.menu() == null) { | ||
return new MenuEntry(viewInfo.route(), viewInfo.title(), null, | ||
false, null, null); | ||
} | ||
return new MenuEntry(viewInfo.route(), | ||
(viewInfo.menu().title() != null | ||
&& !viewInfo.menu().title().isBlank() | ||
? viewInfo.menu().title() | ||
: viewInfo.title()), | ||
viewInfo.menu().order(), viewInfo.menu().exclude(), | ||
viewInfo.menu().icon(), viewInfo.menu().menuClass()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
flow-server/src/main/java/com/vaadin/flow/server/menu/MenuEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.server.menu; | ||
|
||
import java.io.Serializable; | ||
|
||
import com.vaadin.flow.component.Component; | ||
|
||
/** | ||
* Menu entry for the main menu. | ||
* | ||
* @param path | ||
* the path to navigate to | ||
* @param title | ||
* the title to display | ||
* @param order | ||
* the order in the menu or null for default order | ||
* @param exclude | ||
* whether to exclude the menu entry | ||
* @param icon | ||
* Icon to use in the menu or null for no icon. Value can go inside a | ||
* {@code <vaadin-icon>} element's {@code icon} attribute which | ||
* accepts icon group and name like 'vaadin:file'. Or it can go to a | ||
* {@code <vaadin-icon>} element's {@code src} attribute which takes | ||
* 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. Always null for | ||
* Hilla/TypeScript client views. | ||
*/ | ||
public record MenuEntry(String path, String title, Double order, | ||
boolean exclude, String icon, Class<? extends Component> menuClass) implements Serializable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.