Skip to content

Commit

Permalink
Merge branch 'main' into signall-babel
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Jun 27, 2024
2 parents b9cb338 + 5a060a9 commit 0d7779f
Show file tree
Hide file tree
Showing 34 changed files with 2,721 additions and 2,396 deletions.
4,164 changes: 2,073 additions & 2,091 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public RouteUnifyingIndexHtmlRequestListener(
public void modifyIndexHtmlResponse(IndexHtmlResponse response) {
final Map<String, AvailableViewInfo> availableViews = new HashMap<>(
collectClientViews(response.getVaadinRequest()));
final boolean hasMainMenuRoute = hasMainMenu(
MenuRegistry.collectClientMenuItems(true,
deploymentConfiguration, response.getVaadinRequest()));
if (exposeServerRoutesToClient) {
LOGGER.debug(
"Exposing server-side views to the client based on user configuration");
availableViews
.putAll(collectServerViews(hasMainMenu(availableViews)));
availableViews.putAll(collectServerViews(hasMainMenuRoute));
}

if (availableViews.isEmpty()) {
Expand All @@ -122,20 +124,51 @@ public void modifyIndexHtmlResponse(IndexHtmlResponse response) {
protected Map<String, AvailableViewInfo> collectClientViews(
VaadinRequest request) {

return MenuRegistry
.collectClientMenuItems(true, deploymentConfiguration, request)
.entrySet().stream()
.filter(view -> !hasRequiredParameter(
view.getValue().routeParameters()))
.collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue));
final Map<String, AvailableViewInfo> viewInfoMap = MenuRegistry
.collectClientMenuItems(true, deploymentConfiguration, request);

final Set<String> clientViewEntries = new HashSet<>(
viewInfoMap.keySet());
for (var path : clientViewEntries) {
if (!viewInfoMap.containsKey(path)) {
continue;
}

var viewInfo = viewInfoMap.get(path);
// Remove routes with required parameters, including nested ones
if (hasRequiredParameter(viewInfo)) {
viewInfoMap.remove(path);
if (viewInfo.children() != null) {
RouteUtil.removeChildren(viewInfoMap, viewInfo, path);
}
continue;
}

// Remove layouts
if (viewInfo.children() != null) {
viewInfoMap.remove(path);
}
}

return viewInfoMap;
}

private boolean hasRequiredParameter(
Map<String, RouteParamType> routeParameters) {
return routeParameters != null && !routeParameters.isEmpty()
private boolean hasRequiredParameter(AvailableViewInfo viewInfo) {
final Map<String, RouteParamType> routeParameters = viewInfo
.routeParameters();
if (routeParameters != null && !routeParameters.isEmpty()
&& routeParameters.values().stream().anyMatch(
paramType -> paramType == RouteParamType.REQUIRED);
paramType -> paramType == RouteParamType.REQUIRED)) {
return true;
}

// Nested routes could have parameters on the parent, check them also
final AvailableViewInfo parentViewInfo = null;
if (parentViewInfo != null) {
return hasRequiredParameter(parentViewInfo);
}

return false;
}

protected Map<String, AvailableViewInfo> collectServerViews(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
{
"": {
"params": {},
"title": "Layout",
"rolesAllowed": null,
"loginRequired": false,
"route": "",
"lazy": false,
"register": false,
"menu": null
},
"/foo": {
"params": {},
"title": "RouteTarget",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{
"route": "/home",
"params": {},
"title": "Home",
"children": []
"title": "Home"
},

{
Expand Down Expand Up @@ -39,6 +38,33 @@
"lazy": false,
"register": false,
"menu": null
}
},
{
"route": "/products",
"params": {},
"title": "Products",
"lazy": false,
"loginRequired": true,
"rolesAllowed": ["ROLE_ADMIN"],
"children": [
{
"route": "/:id",
"loginRequired": false,
"rolesAllowed": null,
"lazy": false,
"params": { ":id": "req"},
"title": "Product Page",
"children": [
{
"route": "/edit",
"loginRequired": false,
"rolesAllowed": null,
"lazy": false,
"title": "Edit Product"
}
]
}
]
}
]

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
{
"route": "/home",
"params": {},
"title": "Home",
"children": []
"title": "Home"
},
{
"route": "/profile",
Expand Down
Loading

0 comments on commit 0d7779f

Please sign in to comment.