Skip to content

Commit

Permalink
fix: menu page header path check (#20228) (#20230)
Browse files Browse the repository at this point in the history
Fix the menu page header to
check the actual full path for the
view and not the view path.
For client entries the
AvailableViewInfo.path is only
the "route" for the file and
not the whole path from parents.

Co-authored-by: caalador <[email protected]>
  • Loading branch information
vaadin-bot and caalador authored Oct 11, 2024
1 parent 3c3367e commit 2f10fe0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -154,13 +155,14 @@ private static Optional<String> getPageHeaderFromMenuItems() {
String activeLocation = PathUtil.trimPath(
ui.getInternals().getActiveViewLocation().getPath());

List<AvailableViewInfo> menuItems = MenuRegistry.getMenuItems(false)
.values().stream().toList();
Map<String, AvailableViewInfo> menuItems = MenuRegistry
.getMenuItems(false);

return menuItems.stream()
.filter(menuItem -> PathUtil.trimPath(menuItem.route())
return menuItems.entrySet().stream()
.filter(menuEntry -> PathUtil.trimPath(menuEntry.getKey())
.equals(activeLocation))
.map(AvailableViewInfo::title).findFirst();
.map(Map.Entry::getValue).map(AvailableViewInfo::title)
.findFirst();
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ public void testGetPageHeader_clientViews_pageHeaderFromTitle()
// from ViewConfig.title, when flow layout is false
Assert.assertEquals("Hilla", header.get());

Mockito.when(location.getPath()).thenReturn("/flow/hello");
header = MenuConfiguration.getPageHeader();
Assert.assertTrue(header.isPresent());
// from ViewConfig.title, when flow layout is false
Assert.assertEquals("Hello", header.get());

Mockito.when(uiInternals.getActiveRouterTargetsChain())
.thenReturn(List.of(new RouteOrLayoutWithDynamicTitle()));
header = MenuConfiguration.getPageHeader();
Expand Down Expand Up @@ -551,6 +557,19 @@ public void setParameter(BeforeEvent event, String parameter) {
"flowLayout": false
}
]
},
{
"route": "flow",
"params": {},
"children": [
{
"route": "hello",
"menu": {
"title": "Hello For Flow Layout"
},
"title": "Hello"
}
]
}
]
""";
Expand Down

0 comments on commit 2f10fe0

Please sign in to comment.