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

Update React Router to 6.3.0 #18722

Merged
merged 31 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
616fb71
Fix typo
emilpaw May 11, 2022
2a83e2d
Bump react router version to 6.3.0
emilpaw May 11, 2022
bd514b2
Remove confusing alias
emilpaw May 11, 2022
cff5a3c
Initial changes to use react router 6.3.0
emilpaw May 11, 2022
d7040e7
Adapt user management to react router 6.3.0
emilpaw May 18, 2022
99539cf
Remove @types/react-router-dom from generated package.json
emilpaw May 26, 2022
54873ff
Make entities work with react router 6.3.0
emilpaw May 27, 2022
c3ece42
Remove ErrorBoundaryRoute component
emilpaw May 27, 2022
ce3e22f
Change the AppRoutes paths from absolute to relative
emilpaw May 27, 2022
1c42951
Remove last usages of ErrorBoundaryRoute
emilpaw May 27, 2022
dfd29c5
Fix client generation tests
emilpaw May 27, 2022
e2ac826
Use constant for repeated value
emilpaw May 27, 2022
4d35505
Make pagination work with react router 6.3.0
emilpaw May 27, 2022
e9667f0
Move closing tag to the right position
emilpaw May 29, 2022
1e03195
Remove prop
emilpaw May 29, 2022
28e942d
Make microfrontends work with react router 6.3.0
emilpaw May 30, 2022
ea541a5
Fix remote microfrontend routes
emilpaw Jun 3, 2022
3013c18
Fix LoginRedirect component
emilpaw Jun 3, 2022
16ef7ec
Add missing import
emilpaw Jun 3, 2022
682d738
Add ErrorBoundaryRoutes component
emilpaw Jun 6, 2022
8184c19
Use ErrorBoundaryRoutes component
emilpaw Jun 6, 2022
5304158
Improve test description
emilpaw Jun 6, 2022
e342c99
Remove unused imports
emilpaw Jun 6, 2022
38ad4b7
Refactor PrivateRoute component
emilpaw Jun 6, 2022
a0eb86d
Fix redirect when not authenticated test
emilpaw Jun 6, 2022
bfb7020
Simplify expression
emilpaw Jun 6, 2022
964af56
Revert changing filename in cleanup
emilpaw Jun 7, 2022
42c70a2
Add error-boundary-route component to cleanup
emilpaw Jun 7, 2022
e1e58c7
Format
emilpaw Jun 7, 2022
75e1625
Move error-boundary-route cleanup
emilpaw Jun 7, 2022
8b933d3
Fix path
emilpaw Jun 7, 2022
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
8 changes: 6 additions & 2 deletions generators/client/files-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const files = {
// components
{ file: 'shared/auth/private-route.tsx', method: 'processJsx' },
{ file: 'shared/error/error-boundary.tsx', method: 'processJsx' },
{ file: 'shared/error/error-boundary-route.tsx', method: 'processJsx' },
{ file: 'shared/error/error-boundary-routes.tsx', method: 'processJsx' },
{ file: 'shared/error/page-not-found.tsx', method: 'processJsx' },
{ file: 'shared/DurationFormat.tsx', method: 'processJsx' },
// model
Expand Down Expand Up @@ -294,7 +294,7 @@ const files = {
'shared/util/entity-utils.spec.ts',
'shared/auth/private-route.spec.tsx',
'shared/error/error-boundary.spec.tsx',
'shared/error/error-boundary-route.spec.tsx',
'shared/error/error-boundary-routes.spec.tsx',
'shared/layout/header/header.spec.tsx',
'shared/layout/menus/account.spec.tsx',
'modules/administration/administration.reducer.spec.ts',
Expand Down Expand Up @@ -372,6 +372,10 @@ function cleanup() {
if (this.isJhipsterVersionLessThan('7.7.1')) {
this.removeFile(`${CLIENT_MAIN_SRC_DIR}app/entities/index.tsx`);
}
if (this.isJhipsterVersionLessThan('7.8.2')) {
this.removeFile(`${CLIENT_MAIN_SRC_DIR}app/shared/error/error-boundary-route.tsx`);
this.removeFile(`${CLIENT_MAIN_SRC_DIR}app/shared/error/error-boundary-route.spec.tsx`);
}
}

function writeFiles() {
Expand Down
4 changes: 2 additions & 2 deletions generators/client/needle-api/needle-client-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ module.exports = class extends needleClientBase {
indexModulePath,
'jhipster-needle-add-route-path',
this.generator.stripMargin(
`|<ErrorBoundaryRoute path={\`\${match.url}${
`|<Route path="${
this.generator.microfrontend && this.generator.applicationTypeMicroservice ? '/' : ''
}${entityFileName}\`} component={${entityName}} />`
}${entityFileName}/*" element={<${entityName} />} />`
)
);
this.addBlockContentToFile(indexAddRoutePathRewriteFileModel, errorMessage(indexModulePath));
Expand Down
5 changes: 2 additions & 3 deletions generators/client/templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react-loadable": "5.5.0",
"react-redux": "8.0.2",
"react-redux-loading-bar": "5.0.4",
"react-router-dom": "5.3.0",
"react-router-dom": "6.3.0",
"react-toastify": "9.0.3",
"react-transition-group": "4.4.2",
"reactstrap": "9.0.3",
Expand All @@ -34,7 +34,6 @@
"@types/react": "18.0.12",
"@types/react-dom": "18.0.5",
"@types/react-redux": "7.1.24",
"@types/react-router-dom": "5.3.3",
emilpaw marked this conversation as resolved.
Show resolved Hide resolved
"@types/redux": "3.6.31",
"@types/webpack-env": "1.17.0",
"@typescript-eslint/eslint-plugin": "5.27.0",
Expand Down Expand Up @@ -85,4 +84,4 @@
"webpack-notifier": "1.15.0",
"workbox-webpack-plugin": "6.5.3"
}
}
}
1 change: 0 additions & 1 deletion generators/client/templates/react/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@types/react": "<%= dependabotPackageJson.devDependencies['@types/react'] %>",
"@types/react-dom": "<%= dependabotPackageJson.devDependencies['@types/react-dom'] %>",
"@types/react-redux": "<%= dependabotPackageJson.devDependencies['@types/react-redux'] %>",
"@types/react-router-dom": "<%= dependabotPackageJson.devDependencies['@types/react-router-dom'] %>",
"@types/redux": "<%= dependabotPackageJson.devDependencies['@types/redux'] %>",
<%_ if (protractorTests) { _%>
"@types/selenium-webdriver": "4.0.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'app/config/dayjs.ts';

import React, { useEffect } from 'react';
import { Card } from 'reactstrap';
import { BrowserRouter as Router } from 'react-router-dom';
import { BrowserRouter } from 'react-router-dom';
import { ToastContainer, toast } from 'react-toastify';

import { useAppDispatch, useAppSelector } from 'app/config/store';
Expand Down Expand Up @@ -59,7 +59,7 @@ export const App = () => {

const paddingTop = '60px';
return (
<Router basename={baseHref}>
<BrowserRouter basename={baseHref}>
<div className="app-container" style={{ paddingTop }}>
<ToastContainer position={toast.POSITION.TOP_LEFT} className="toastify-container" toastClassName="toastify-toast"/>
<ErrorBoundary>
Expand All @@ -83,7 +83,7 @@ export const App = () => {
<Footer/>
</div>
</div>
</Router>
</BrowserRouter>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@
limitations under the License.
-%>
import React from 'react';
import { Switch } from 'react-router-dom';
import { Route } from 'react-router-dom';

import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';

<%_ if (microfrontend || applicationTypeGateway) { _%>
import { ReducersMapObject, combineReducers } from '@reduxjs/toolkit';

import getStore from 'app/config/store';
<%_ } _%>
import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route';
<%_ if (microfrontend || applicationTypeGateway) { _%>

import entitiesReducers from './reducers';
<%_ } _%>

/* jhipster-needle-add-route-import - JHipster will add routes here */

export default ({ match }) => {
export default () => {
<%_ if (microfrontend || applicationTypeGateway) { _%>
const store = getStore();
store.injectReducer('<%= lowercaseBaseName %>', combineReducers(entitiesReducers as ReducersMapObject));
<%_ } _%>
return (
<div>
<Switch>
<ErrorBoundaryRoutes>
{/* prettier-ignore */}
{/* jhipster-needle-add-route-path - JHipster will add routes here */}
</Switch>
</ErrorBoundaryRoutes>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
limitations under the License.
-%>
import React, { useEffect } from 'react';
import { Link, RouteComponentProps } from 'react-router-dom';
import { Link, useSearchParams } from 'react-router-dom';
import { Row, Col, Alert } from 'reactstrap';
import { Translate, getUrlParameter } from 'react-jhipster';
import { Translate } from 'react-jhipster';

import { useAppDispatch, useAppSelector } from 'app/config/store';
import { activateAction, reset } from './activate.reducer';
Expand All @@ -43,10 +43,14 @@ const failureAlert = (
</Alert>
);

export const ActivatePage = (props: RouteComponentProps<{ key: any }>) => {
export const ActivatePage = () => {
const dispatch = useAppDispatch();

const [searchParams] = useSearchParams();

useEffect(() => {
const key = getUrlParameter('key', props.location.search);
const key = searchParams.get("key");

dispatch(activateAction(key));
return () => {
dispatch(reset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@
limitations under the License.
-%>
import React from 'react';
import { Route } from 'react-router-dom';

import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route';
import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';

import Settings from './settings/settings';
import Password from './password/password';
<%_ if (authenticationTypeSession) { _%>
import Sessions from './sessions/sessions';
<%_ } _%>

const Routes = ({ match }) => (
const AccountRoutes = () => (
<div>
<ErrorBoundaryRoute path={`${match.url}/settings`} component={Settings} />
<ErrorBoundaryRoute path={`${match.url}/password`} component={Password} />
<ErrorBoundaryRoutes>
<Route path="settings" element={<Settings />} />
<Route path="password" element={<Password />} />
<%_ if (authenticationTypeSession) { _%>
<ErrorBoundaryRoute path={`${match.url}/sessions`} component={Sessions} />
<Route path="sessions" element={<Sessions />} />
<%_ } _%>
</ErrorBoundaryRoutes>
</div>
);

export default Routes;
export default AccountRoutes;
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
-%>
import React, { useState, useEffect } from 'react';
import { Col, Row, Button } from 'reactstrap';
import { Translate, translate, getUrlParameter, ValidatedField, ValidatedForm } from 'react-jhipster';
import { RouteComponentProps } from 'react-router-dom';
import { Translate, translate, ValidatedField, ValidatedForm } from 'react-jhipster';
import { useSearchParams } from 'react-router-dom';
import { toast } from 'react-toastify';

import { handlePasswordResetFinish, reset } from '../password-reset.reducer';
import PasswordStrengthBar from 'app/shared/layout/password/password-strength-bar';
import { useAppDispatch, useAppSelector } from 'app/config/store';

export const PasswordResetFinishPage = (props: RouteComponentProps<{ key: string }>) => {
const [password, setPassword] = useState('');
const [key] = useState(getUrlParameter('key', props.location.search));
export const PasswordResetFinishPage = () => {
const dispatch = useAppDispatch();

const [searchParams] = useSearchParams();
const key = searchParams.get('key');

const [password, setPassword] = useState('');

useEffect(
() => () => {
dispatch(reset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
-%>
import React from 'react';

import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route';
import { Route } from 'react-router-dom';
import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';
<%_ if (!skipUserManagement) { _%>
import UserManagement from './user-management';
<%_ } _%>
Expand All @@ -36,25 +37,27 @@ import Gateway from './gateway/gateway';
import Tracker from './tracker/tracker';
<%_ } _%>

const Routes = ({ match }) => (
const AdministrationRoutes = () => (
<div>
<ErrorBoundaryRoutes>
<%_ if (!skipUserManagement) { _%>
<ErrorBoundaryRoute path={`${match.url}/user-management`} component={UserManagement} />
<Route path="user-management/*" element={<UserManagement />} />
<%_ } _%>
<%_ if (communicationSpringWebsocket) { _%>
<ErrorBoundaryRoute exact path={`${match.url}/tracker`} component={Tracker} />
<Route path="tracker" element={<Tracker />} />
<%_ } _%>
<%_ if (applicationTypeGateway && serviceDiscoveryType) { _%>
<ErrorBoundaryRoute exact path={`${match.url}/gateway`} component={Gateway} />
<Route path="gateway" element={<Gateway />} />
<%_ } _%>
<%_ if (withAdminUi) { _%>
<ErrorBoundaryRoute exact path={`${match.url}/health`} component={Health} />
<ErrorBoundaryRoute exact path={`${match.url}/metrics`} component={Metrics} />
<ErrorBoundaryRoute exact path={`${match.url}/configuration`} component={Configuration} />
<ErrorBoundaryRoute exact path={`${match.url}/logs`} component={Logs} />
<Route path="health" element={<Health />} />
<Route path="metrics" element={<Metrics />} />
<Route path="configuration" element={<Configuration />} />
<Route path="logs" element={<Logs />} />
<%_ } _%>
<ErrorBoundaryRoute exact path={`${match.url}/docs`} component={Docs} />
<Route path="docs" element={<Docs />} />
</ErrorBoundaryRoutes>
</div>
);

export default Routes;
export default AdministrationRoutes;
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
limitations under the License.
-%>
import React from 'react';
import { Switch } from 'react-router-dom';
import { Route } from 'react-router-dom';

import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route';
import ErrorBoundaryRoutes from 'app/shared/error/error-boundary-routes';
import UserManagement from './user-management';
import UserManagementDetail from './user-management-detail';
import UserManagementUpdate from './user-management-update';
import UserManagementDeleteDialog from './user-management-delete-dialog';

const Routes = ({ match }) => (
<>
<Switch>
<ErrorBoundaryRoute exact path={`${match.url}/new`} component={UserManagementUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:login/edit`} component={UserManagementUpdate} />
<ErrorBoundaryRoute exact path={`${match.url}/:login`} component={UserManagementDetail} />
<ErrorBoundaryRoute path={match.url} component={UserManagement} />
</Switch>
<ErrorBoundaryRoute path={`${match.url}/:login/delete`} component={UserManagementDeleteDialog} />
</>
const UserManagementRoutes = () => (
<ErrorBoundaryRoutes>
<Route index element={<UserManagement />} />
<Route path="new" element={<UserManagementUpdate />} />
<Route path=":login">
<Route index element={<UserManagementDetail />} />
<Route path="edit" element={<UserManagementUpdate />} />
<Route path="delete" element={<UserManagementDeleteDialog />} />
</Route>
</ErrorBoundaryRoutes>
);

export default Routes;
export default UserManagementRoutes;
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@
limitations under the License.
-%>
import React, { useEffect } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
import { Translate } from 'react-jhipster';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { getUser, deleteUser } from './user-management.reducer';
import { useAppDispatch, useAppSelector } from 'app/config/store';

export const UserManagementDeleteDialog = (props: RouteComponentProps<{ login: string }>) => {
export const UserManagementDeleteDialog = () => {
const dispatch = useAppDispatch();

const navigate = useNavigate();
const { login } = useParams<'login'>();

useEffect(() => {
dispatch(getUser(props.match.params.login));
dispatch(getUser(login));
}, []);

const handleClose = event => {
event.stopPropagation();
props.history.push('/admin/user-management');
navigate('/admin/user-management');
};

const user = useAppSelector(state => state.userManagement.user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
limitations under the License.
-%>
import React, { useEffect } from 'react';
import { Link, RouteComponentProps } from 'react-router-dom';
import { Link, useParams } from 'react-router-dom';
import { Button, Row, Badge } from 'reactstrap';
import { Translate, TextFormat } from 'react-jhipster';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand All @@ -27,11 +27,13 @@ import { APP_DATE_FORMAT } from 'app/config/constants';
import { getUser } from './user-management.reducer';
import { useAppDispatch, useAppSelector } from 'app/config/store';

export const UserManagementDetail = (props: RouteComponentProps<{ login: string }>) => {
export const UserManagementDetail = () => {
const dispatch = useAppDispatch();

const { login } = useParams<'login'>();

useEffect(() => {
dispatch(getUser(props.match.params.login));
dispatch(getUser(login));
}, []);

const user = useAppSelector(state => state.userManagement.user);
Expand Down
Loading