Skip to content

Commit

Permalink
Merge branch 'main' into issues/18130_componenttracker_disable_parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollovati committed Dec 27, 2023
2 parents 453604d + de4f5ed commit 8a7b875
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ public class BuildFrontendMojo extends FlowModeAbstractMojo
@Parameter(property = InitParameters.FORCE_PRODUCTION_BUILD, defaultValue = "false")
private boolean forceProductionBuild;

/**
* Control cleaning of generated frontend files when executing
* 'build-frontend'.
*
* Mainly this is wanted to be true which it is by default.
*/
@Parameter(property = InitParameters.CLEAN_BUILD_FRONTEND_FILES, defaultValue = "true")
private boolean cleanFrontendFiles;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
long start = System.nanoTime();
Expand Down Expand Up @@ -167,7 +176,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* @return {@code true} to remove created files, {@code false} to keep files
*/
protected boolean cleanFrontendFiles() {
return true;
return cleanFrontendFiles;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ default Registration addSingleClickListener(
* used to make sure that value synchronization of input fields is not
* blocked for the shortcut key (e.g. Enter key). To change this behavior,
* call {@link ShortcutRegistration#setBrowserDefaultAllowed(boolean)}.
* <p>
* {@link ShortcutRegistration#resetFocusOnActiveElement()} resets focus on
* active element before triggering click event handler. It ensures that
* value synchronization of input fields with a ValueChangeMode.ON_CHANGE is
* done before click event handler is executed (e.g. when Enter key saves a
* form).
*
* @param key
* primary {@link Key} used to trigger the shortcut. Cannot be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public void proceed() {
// updated/added by router when we continue for a Router_link.
// If the server updates the url also we will get 2 history
// changes instead of 1.
if (NavigationTrigger.ROUTER_LINK.equals(event.getTrigger())) {
if (NavigationTrigger.ROUTER_LINK.equals(event.getTrigger())
&& !event.getUI().getSession().getConfiguration()
.isReactRouterEnabled()) {
event = new NavigationEvent(event.getSource(),
event.getLocation(), event.getUI(),
NavigationTrigger.PROGRAMMATIC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,9 @@ public class InitParameters implements Serializable {
* Configuration name for forcing optimized production bundle build.
*/
public static final String COMPRESS_BUNDLE = "vaadin.compress.bundle";

/**
* Configuration name for cleaning or leaving frontend files in build.
*/
public static final String CLEAN_BUILD_FRONTEND_FILES = "vaadin.clean.build.frontend.files";
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function vaadinRouterGlobalClickHandler(event) {
// We can't initiate useNavigate() from outside React component so we store it here for use in the navigateEvent.
let navigation: NavigateFunction | ((arg0: any, arg1: { replace: boolean; }) => void);
let mountedContainer: Awaited<ReturnType<typeof flow.serverSideRoutes[0]["action"]>> | undefined = undefined;
let lastNavigation: String;

// @ts-ignore
function navigateEventHandler(event) {
Expand Down Expand Up @@ -179,6 +180,7 @@ function navigateEventHandler(event) {
navigation(event.detail.pathname, {replace: false});
}
}
lastNavigation = event.detail.pathname;
}

export default function Flow() {
Expand All @@ -189,6 +191,9 @@ export default function Flow() {
useEffect(() => {
window.document.addEventListener('click', vaadinRouterGlobalClickHandler);
window.addEventListener('vaadin-router-go', navigateEventHandler);
if(lastNavigation === pathname) {
return;
}
flow.serverSideRoutes[0].action({pathname, search}).then((container) => {
const outlet = ref.current?.parentNode;
if (outlet && outlet !== container.parentNode) {
Expand Down
1 change: 1 addition & 0 deletions flow-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@

<module>vaadin-spring-tests</module>
<module>test-react-router</module>
<module>test-react-router/pom-production.xml</module>
</modules>
</profile>
<profile>
Expand Down
65 changes: 65 additions & 0 deletions flow-tests/test-react-router/pom-production.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>flow-tests</artifactId>
<groupId>com.vaadin</groupId>
<version>24.4-SNAPSHOT</version>
</parent>
<artifactId>flow-test-react-router-prod</artifactId>
<name>Flow tests for routing using react-router in production mode</name>

<packaging>war</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<surefire.reportNameSuffix>production</surefire.reportNameSuffix>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-resources</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components-testbench</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-common</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<cleanFrontendFiles>false</cleanFrontendFiles>
</configuration>
</plugin>
<!-- This module is mapped to default web context -->
<plugin>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow;

import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.router.Route;

@Route("com.vaadin.flow.AnchorView")
public class AnchorView extends Div {

public AnchorView() {
Anchor navigation = new Anchor("com.vaadin.flow.NavigationView",
"Navigation");
navigation.setId(NavigationView.ANCHOR_ID);
add(new Span("AnchorView"), new Div(), navigation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow;

import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLink;

@Route("com.vaadin.flow.NavigationView")
public class NavigationView extends Div {

public static final String SERVER_ID = "server-navigation";
public static final String ANCHOR_ID = "anchor-navigation";
public static final String ROUTER_LINK_ID = "router-link-navigation";
public static final String POSTPONE_ID = "postpone-view-link";

public NavigationView() {
Anchor anchorNavigation = new Anchor("com.vaadin.flow.AnchorView",
"Navigate to AnchorView");
anchorNavigation.setId(ANCHOR_ID);
NativeButton serverNavigation = new NativeButton(
"Navigate through Server", event -> {
event.getSource().getUI().get().navigate(ServerView.class);
});
serverNavigation.setId(SERVER_ID);
RouterLink link = new RouterLink("RouterView", RouterView.class);
link.setId(ROUTER_LINK_ID);

RouterLink postponeView = new RouterLink("PostponeView",
PostponeView.class);
postponeView.setId(POSTPONE_ID);

add(new Span("NavigationView"), new Div(), anchorNavigation, new Div(),
serverNavigation, new Div(), link, new Div(), postponeView);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow;

import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLink;

@Route("com.vaadin.flow.PostponeView")
public class PostponeView extends Div implements BeforeLeaveObserver {

public static String CONTINUE_ID = "continue-button";
public static String STAY_ID = "stay-button";
public static String NAVIGATION_ID = "to-navigation";
public static String NAVIGATION_ROUTER_LINK_ID = "to-navigation";

private NativeButton navigate, stay;

public PostponeView() {
Anchor link = new Anchor("com.vaadin.flow.NavigationView",
"Navigation");// NavigationView.class);
link.setId(NAVIGATION_ID);
RouterLink routerLink = new RouterLink("Navigation",
NavigationView.class);
routerLink.setId(NAVIGATION_ROUTER_LINK_ID);

add(new Span("PostponeView"), new Div(), link, new Div(), routerLink);
}

@Override
public void beforeLeave(BeforeLeaveEvent event) {
BeforeLeaveEvent.ContinueNavigationAction postpone = event.postpone();
navigate = new NativeButton("Continue", e -> {
postpone.proceed();
remove(navigate, stay);
});
navigate.setId(CONTINUE_ID);
stay = new NativeButton("Stay", e -> {
postpone.cancel();
remove(navigate, stay);
});
stay.setId(STAY_ID);

add(navigate, stay);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouterLink;

@Route("com.vaadin.flow.RouterView")
public class RouterView extends Div {

public RouterView() {
RouterLink link = new RouterLink("RouterLink", NavigationView.class);
link.setId(NavigationView.ROUTER_LINK_ID);

add(new Span("RouterView"), new Div(), link);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.vaadin.flow;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.NativeButton;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.router.Route;

@Route("com.vaadin.flow.ServerView")
public class ServerView extends Div {

public ServerView() {
NativeButton serverNavigation = new NativeButton(
"Navigate through Server", event -> {
event.getSource().getUI().get()
.navigate(NavigationView.class);
});
serverNavigation.setId(NavigationView.SERVER_ID);

add(new Span("ServerView"), new Div(), serverNavigation);
}
}
Loading

0 comments on commit 8a7b875

Please sign in to comment.