Skip to content

Commit

Permalink
fix: change type of Menu order to double (#19332) (#19357)
Browse files Browse the repository at this point in the history
Changing `Menu#order` type double and `MenuData#order` type to Double to match it with Hilla's `ViewConfig` type `number`.

Fixes: #19320

Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
  • Loading branch information
vaadin-bot and tltv committed May 13, 2024
1 parent e09dd4f commit 83ccb0c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions flow-server/src/main/java/com/vaadin/flow/router/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
/**
* Used to determine the order in the menu. Ties are resolved based on the
* used title. Entries without explicitly defined ordering are put below
* entries with an order. {@link Long#MIN_VALUE} is the default value and
* entries with an order. {@link Double#MIN_VALUE} is the default value and
* considered as undefined.
*
* @return the order of the item in the menu. {@link Long#MIN_VALUE} by
* @return the order of the item in the menu. {@link Double#MIN_VALUE} by
* default.
*/
long order() default Long.MIN_VALUE;
double order() default Double.MIN_VALUE;

/**
* Icon to use in the menu. Value can go inside a {@code <vaadin-icon>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class MenuData implements Serializable {

private final String title;
private final Long order;
private final Double order;
private final boolean exclude;
private final String icon;

Expand All @@ -43,7 +43,7 @@ public class MenuData implements Serializable {
* @param icon
* the icon of the menu item
*/
public MenuData(String title, Long order, boolean exclude, String icon) {
public MenuData(String title, Double order, boolean exclude, String icon) {
this.title = title;
this.order = order;
this.exclude = exclude;
Expand All @@ -64,7 +64,7 @@ public String getTitle() {
*
* @return the order of the menu item
*/
public Long getOrder() {
public Double getOrder() {
return order;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ private void populateRegisteredRoutes(ConfiguredRoutes configuration,
MenuData menuData = AnnotationReader
.getAnnotationFor(target, Menu.class)
.map(menu -> new MenuData(menu.title(),
(menu.order() == Long.MIN_VALUE) ? null : menu.order(),
(Objects.equals(menu.order(), Double.MIN_VALUE)) ? null
: menu.order(),
false, menu.icon()))
.orElse(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Route(value = "admin", layout = MainView.class)
@RouteAlias(value = "alias-for-admin", layout = MainView.class)
@PageTitle("Admin View")
@Menu(order = 3)
@Menu(order = 1.10001)
public class AdminView extends VerticalLayout {

public AdminView(SecurityUtils securityUtils) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@Route(value = "private", layout = MainView.class)
@RouteAlias(value = "privateAndForbiddenForAll")
@PageTitle("Private View")
@Menu(order = 2)
@Menu(order = 1.1)
public class PrivateView extends VerticalLayout {

private BankService bankService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ public void client_menu_routes_correct_for_admin() {
private void assertMenuListContains(String expected) {
TestBenchElement menuList = waitUntil(driver -> $("*").id("menu-list"));
String menuListText = menuList.getText();
Assert.assertTrue(menuListText.contains(expected));
Assert.assertTrue(
"Expected " + expected + " but actual is " + menuListText,
menuListText.contains(expected));
}

private void navigateToClientMenuList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@Route(value = "private", layout = MainView.class)
@PageTitle("Private View")
@PermitAll
@Menu(order = 2)
@Menu(order = 1.5)
public class PrivateView extends VerticalLayout {

private BankService bankService;
Expand Down

0 comments on commit 83ccb0c

Please sign in to comment.