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

docs: document MenuConfiguration #3770

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions articles/flow/advanced/menu-configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Menu Configuration
description: Collecting menu annotated routes for menu generation.
order: 115
---


= Menu Configuration

To generate a custom menu there's the [classname]`MenuConfiguration` for collecting defined server and client routes. Client routes are collected from the FileSystem routes definition. Server routes are collected for routes annotated with [annotationname]`@Menu`.

The collected menu items are filtered by access control from the [classname]`UI` ([classname]`NavigationAccessControl` and [classname]`ViewAccessChecker`). If the application has login and route defined `Roles`, the returned list is filtered for only available routes.


== Creating Routes Menu

For a Flow application, any route annotated with [annotationname]`@Menu` is eligible for automatic collection.

To get the available menu routes, call the static method `MenuConfiguration.getMenuEntries()`. This returns a [classname]`List<MenuEntry>` sorted primarily by order, then by path alphabetically and locale-sensitively. It would make creating a simple menu using [classname]`Anchor` look like this:

[source,java]
----
List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
menuEntries.forEach(entry -> layout.add(new Anchor(entry.path(), entry.title())));
----

== Data Returned for Menu Entries

The [classname]`MenuEntry` for the route contains information on the route. Using this data, it's possible to populate a menu, automatically.

The data contained is as follows:

`path`::
Route path that should be used for navigation.

`title`::
Title set in the [annotationname]`@Menu` annotation or the [annotationname]`@PageTitle` if defined; else the class simple name. For the client, title is populated from the FS router data.

`order`::
Order number for the menu entry if defined.

`icon`::
Icon to use in the menu. The value can be entered inside a `<vaadin-icon>` element's `icon` attribute. This accepts icon group and a name like `vaadin:file`. Or the value can be given in `<vaadin-icon>` element's `src` attribute, which takes the path to the icon (e.g., `line-awesome/svg/lock-open-solid.svg`).

`menuClass`::
Source class of the [annotationname]`@Menu` annotation. Always null for client routes.

[discussion-id]`647922A8-D542-4FA7-AAF6-44D40FC6A33B`
102 changes: 0 additions & 102 deletions articles/flow/advanced/menu-registry.adoc

This file was deleted.

2 changes: 1 addition & 1 deletion articles/flow/integrations/hilla.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class MainView extends Div implements RouterLayout {

For more information on `RouterLayout`, see <<../routing/layout.adoc#,Router Layouts & Nested Router Targets>>.

Information on dynamic menu item generation, see <<../advanced/menu-registry#,Menu Registry>>.
Information on dynamic menu item generation, see <<../advanced/menu-configuration#,Menu Configuration>>.

[NOTE]
If the application is using access protection add [annotationname]`@AnonymousAllowed` on the `MainView` so that the request is not denied.
Expand Down
Loading