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

fix: resolve route parameters when rerouting and forwarding with query parameters (#20210) (CP: 24.3) #20223

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

public enum Country {

FINLAND("Finland"), SWEDEN("Sweden"), USA("USA"), RUSSIA(
"Russia"), NETHERLANDS("Netherlands"), SOUTH_AFRICA("South Africa");
FINLAND("Finland"),
SWEDEN("Sweden"),
USA("USA"),
RUSSIA("Russia"),
NETHERLANDS("Netherlands"),
SOUTH_AFRICA("South Africa");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ private static Optional<ImportanceType> fromAttributeValue(
* Sandbox types.
*/
public enum SandboxType {
RESTRICT_ALL(""), ALLOW_FORMS("allow-forms"), ALLOW_MODALS(
"allow-modals"), ALLOW_ORIENTATION_LOCK(
"allow-orientation-lock"), ALLOW_POINTER_LOCK(
"allow-pointer-lock"), ALLOW_POPUPS(
"allow-popups"), ALLOW_POPUPS_TO_ESCAPE_SANDBOX(
"allow-popups-to-escape-sandbox"), ALLOW_PRESENTATION(
"allow-presentation"), ALLOW_SAME_ORIGIN(
"allow-same-origin"), ALLOW_SCRIPTS(
"allow-scripts"), ALLOW_STORAGE_ACCESS_BY_USER_ACTIVATION(
"allow-storage-access-by-user-activation"), ALLOW_TOP_NAVIGATION(
"allow-top-navigation"), ALLOW_TOP_NAVIGATION_BY_USER_ACTIVATION(
"allow-top-navigation-by-user-activation");
RESTRICT_ALL(""),
ALLOW_FORMS("allow-forms"),
ALLOW_MODALS("allow-modals"),
ALLOW_ORIENTATION_LOCK("allow-orientation-lock"),
ALLOW_POINTER_LOCK("allow-pointer-lock"),
ALLOW_POPUPS("allow-popups"),
ALLOW_POPUPS_TO_ESCAPE_SANDBOX("allow-popups-to-escape-sandbox"),
ALLOW_PRESENTATION("allow-presentation"),
ALLOW_SAME_ORIGIN("allow-same-origin"),
ALLOW_SCRIPTS("allow-scripts"),
ALLOW_STORAGE_ACCESS_BY_USER_ACTIVATION(
"allow-storage-access-by-user-activation"),
ALLOW_TOP_NAVIGATION("allow-top-navigation"),
ALLOW_TOP_NAVIGATION_BY_USER_ACTIVATION(
"allow-top-navigation-by-user-activation");

private final String value;

Expand Down
69 changes: 65 additions & 4 deletions flow-server/src/main/java/com/vaadin/flow/dom/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,29 @@ default Style setColor(String value) {
}

public enum Display {
INLINE, BLOCK, CONTENTS, FLEX, GRID, INLINE_BLOCK, INLINE_FLEX, INLINE_GRID, INLINE_TABLE, LIST_ITEM, RUN_IN, TABLE, TABLE_CAPTION, TABLE_COLUMN_GROUP, TABLE_HEADER_GROUP, TABLE_FOOTER_GROUP, TABLE_ROW_GROUP, TABLE_CELL, TABLE_COLUMN, TABLE_ROW, NONE, INITIAL, INHERIT
INLINE,
BLOCK,
CONTENTS,
FLEX,
GRID,
INLINE_BLOCK,
INLINE_FLEX,
INLINE_GRID,
INLINE_TABLE,
LIST_ITEM,
RUN_IN,
TABLE,
TABLE_CAPTION,
TABLE_COLUMN_GROUP,
TABLE_HEADER_GROUP,
TABLE_FOOTER_GROUP,
TABLE_ROW_GROUP,
TABLE_CELL,
TABLE_COLUMN,
TABLE_ROW,
NONE,
INITIAL,
INHERIT
}

/**
Expand Down Expand Up @@ -825,7 +847,19 @@ default Style setLineHeight(String value) {
* Css values for the <code>align-items</code> property.
*/
public enum AlignItems {
NORMAL, STRETCH, CENTER, UNSAFE, SAFE, START, END, FLEX_START, FLEX_END, SELF_START, SELF_END, BASELINE, INITIAL;
NORMAL,
STRETCH,
CENTER,
UNSAFE,
SAFE,
START,
END,
FLEX_START,
FLEX_END,
SELF_START,
SELF_END,
BASELINE,
INITIAL;
}

/**
Expand All @@ -844,7 +878,20 @@ default Style setAlignItems(AlignItems value) {
* Css values for the <code>align-self</code> property.
*/
public enum AlignSelf {
AUTO, NORMAL, STRETCH, UNSAFE, SAFE, CENTER, START, END, FLEX_START, FLEX_END, SELF_START, SELF_END, BASELINE, INITIAL;
AUTO,
NORMAL,
STRETCH,
UNSAFE,
SAFE,
CENTER,
START,
END,
FLEX_START,
FLEX_END,
SELF_START,
SELF_END,
BASELINE,
INITIAL;
}

/**
Expand Down Expand Up @@ -906,7 +953,21 @@ default Style setFlexShrink(String value) {
* Css values for the <code>justify-content</code> property.
*/
public enum JustifyContent {
CENTER, START, END, FLEX_START, FLEX_END, LEFT, RIGHT, NORMAL, SPACE_BETWEEN, SPACE_AROUND, SPACE_EVENLY, STRETCH, SAFE, UNSAFE, INITIAL
CENTER,
START,
END,
FLEX_START,
FLEX_END,
LEFT,
RIGHT,
NORMAL,
SPACE_BETWEEN,
SPACE_AROUND,
SPACE_EVENLY,
STRETCH,
SAFE,
UNSAFE,
INITIAL
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public final class StringUtil {
* Comment parser state enumeration.
*/
private enum State {
NORMAL, IN_LINE_COMMENT, IN_BLOCK_COMMENT, IN_STRING, IN_STRING_APOSTROPHE
NORMAL,
IN_LINE_COMMENT,
IN_BLOCK_COMMENT,
IN_STRING,
IN_STRING_APOSTROPHE
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ public <T> void forwardTo(String location, List<T> locationParams) {
*/
public void forwardTo(String locationString,
QueryParameters queryParameters) {
final Optional<Class<? extends Component>> target = getSource()
.getRegistry().getNavigationTarget(locationString);
final Optional<NavigationState> navigationState = getSource()
.resolveNavigationTarget(new Location(locationString));
this.redirectQueryParameters = queryParameters;
if (target.isPresent()) {
forwardTo(getNavigationState(locationString, List.of()));
if (navigationState.isPresent()) {
forwardTo(navigationState.get());
} else {
// Inform that forward target location is not known.
unknownForward = PathUtil.trimPath(locationString);
Expand Down Expand Up @@ -885,12 +885,11 @@ public <T> void rerouteTo(String route, List<T> routeParams) {
* query parameters for the target
*/
public void rerouteTo(String route, QueryParameters queryParameters) {
final Optional<Class<? extends Component>> target = getSource()
.getRegistry().getNavigationTarget(route);

final Optional<NavigationState> navigationState = getSource()
.resolveNavigationTarget(new Location(route));
this.redirectQueryParameters = queryParameters;
if (target.isPresent()) {
rerouteTo(getNavigationState(route, List.of()));
if (navigationState.isPresent()) {
rerouteTo(navigationState.get());
} else {
// Inform that reroute target location is not known.
unknownReroute = PathUtil.trimPath(route);
Expand Down
7 changes: 4 additions & 3 deletions flow-server/src/main/java/com/vaadin/flow/server/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
* One of production, development using livereload or development using bundle
*/
public enum Mode {
PRODUCTION_CUSTOM("production", true), PRODUCTION_PRECOMPILED_BUNDLE(
"production", true), DEVELOPMENT_FRONTEND_LIVERELOAD("development",
false), DEVELOPMENT_BUNDLE("development", false);
PRODUCTION_CUSTOM("production", true),
PRODUCTION_PRECOMPILED_BUNDLE("production", true),
DEVELOPMENT_FRONTEND_LIVERELOAD("development", false),
DEVELOPMENT_BUNDLE("development", false);

private final String name;
private final boolean production;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ public class FrontendTools {
1, 0, 6); // Bun 1.0.6 is the first version with "overrides" support

private enum BuildTool {
NPM("npm", "npm-cli.js"), NPX("npx", "npx-cli.js"), PNPM("pnpm",
null), BUN("bun", null);
NPM("npm", "npm-cli.js"),
NPX("npx", "npx-cli.js"),
PNPM("pnpm", null),
BUN("bun", null);

private final String name;
private final String script;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.vaadin.flow.uitest.ui;

import java.util.List;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.OptionalParameter;
import com.vaadin.flow.router.QueryParameters;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.uitest.servlet.ViewTestLayout;

Expand All @@ -14,27 +17,50 @@ public class SetParameterForwardToView extends Div
implements HasUrlParameter<String>, AfterNavigationObserver {

static final String LOCATION_ID = "location";
static final String PARAMETER_ID = "parameter";

private final Div location;
private final Div param;

public SetParameterForwardToView() {
location = new Div();
location.setId(LOCATION_ID);
param = new Div();
param.setId(PARAMETER_ID);
}

@Override
public void setParameter(BeforeEvent event,
@OptionalParameter String parameter) {
if (parameter != null && parameter.equals("one")) {
event.forwardTo(
"com.vaadin.flow.uitest.ui.SetParameterForwardToView",
"two");
if (parameter != null) {
switch (parameter) {
case "location":
event.forwardTo(
"com.vaadin.flow.uitest.ui.SetParameterForwardToView/locationTwo");
break;
case "locationRouteParameter":
event.forwardTo(
"com.vaadin.flow.uitest.ui.SetParameterForwardToView",
"locationRouteParameterTwo");
break;
case "locationRouteParameterList":
event.forwardTo(
"com.vaadin.flow.uitest.ui.SetParameterForwardToView",
List.of("locationRouteParameterListTwo"));
break;
case "locationQueryParams":
event.forwardTo(
"com.vaadin.flow.uitest.ui.SetParameterForwardToView/locationQueryParamsTwo",
QueryParameters.empty());
break;
}
}
param.setText(parameter);
}

@Override
public void afterNavigation(AfterNavigationEvent event) {
location.setText(event.getLocation().getPath());
add(location);
add(location, param);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.vaadin.flow.uitest.ui;

import java.util.List;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.OptionalParameter;
import com.vaadin.flow.router.QueryParameters;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.uitest.servlet.ViewTestLayout;

@Route(value = "com.vaadin.flow.uitest.ui.SetParameterRerouteToView", layout = ViewTestLayout.class)
public class SetParameterRerouteToView extends Div
implements HasUrlParameter<String>, AfterNavigationObserver {

static final String LOCATION_ID = "location";
static final String PARAMETER_ID = "parameter";

private final Div location;
private final Div param;

public SetParameterRerouteToView() {
location = new Div();
location.setId(LOCATION_ID);
param = new Div();
param.setId(PARAMETER_ID);
}

@Override
public void setParameter(BeforeEvent event,
@OptionalParameter String parameter) {
if (parameter != null) {
switch (parameter) {
case "location":
event.rerouteTo(
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView/locationTwo");
break;
case "locationRouteParameter":
event.rerouteTo(
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView",
"locationRouteParameterTwo");
break;
case "locationRouteParameterList":
event.rerouteTo(
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView",
List.of("locationRouteParameterListTwo"));
break;
case "locationQueryParams":
event.rerouteTo(
"com.vaadin.flow.uitest.ui.SetParameterRerouteToView/locationQueryParamsTwo",
QueryParameters.empty());
break;
}
}
param.setText(parameter);
}

@Override
public void afterNavigation(AfterNavigationEvent event) {
location.setText(event.getLocation().getPath());
add(location, param);
}

}
Loading
Loading