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

Upgrade react-router from v3 to v4 #2294

Merged
merged 7 commits into from
Aug 2, 2023
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
5 changes: 5 additions & 0 deletions client/browserHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createBrowserHistory } from 'history';

const browserHistory = createBrowserHistory();

export default browserHistory;
2 changes: 1 addition & 1 deletion client/common/Button.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';

import { remSize, prop } from '../theme';

Expand Down
2 changes: 1 addition & 1 deletion client/common/ButtonOrLink.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';

/**
Expand Down
22 changes: 7 additions & 15 deletions client/components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { Link, withRouter } from 'react-router';
import { Link } from 'react-router-dom';
import { availableLanguages, languageKeyToLabel } from '../i18n';
import * as IDEActions from '../modules/IDE/actions/ide';
import * as toastActions from '../modules/IDE/actions/toast';
Expand Down Expand Up @@ -37,12 +37,12 @@ class Nav extends React.PureComponent {
}

handleNew() {
const { unsavedChanges, warnIfUnsavedChanges } = this.props;
const { unsavedChanges } = this.props;
if (!unsavedChanges) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
} else if (warnIfUnsavedChanges && warnIfUnsavedChanges()) {
} else if (window.confirm(this.props.t('Nav.WarningUnsavedChanges'))) {
this.props.showToast(1500);
this.props.setToastText('Toast.OpenedNewSketch');
this.props.newProject();
Expand Down Expand Up @@ -73,11 +73,10 @@ class Nav extends React.PureComponent {
}

handleShare() {
const { username } = this.props.params;
this.props.showShareModal(
this.props.project.id,
this.props.project.name,
username
this.props.project.owner.username
);
}

Expand Down Expand Up @@ -351,14 +350,14 @@ Nav.propTypes = {
id: PropTypes.string,
name: PropTypes.string,
owner: PropTypes.shape({
id: PropTypes.string
id: PropTypes.string,
username: PropTypes.string
})
}),
logoutUser: PropTypes.func.isRequired,
showShareModal: PropTypes.func.isRequired,
showErrorModal: PropTypes.func.isRequired,
unsavedChanges: PropTypes.bool.isRequired,
warnIfUnsavedChanges: PropTypes.func,
showKeyboardShortcutModal: PropTypes.func.isRequired,
cmController: PropTypes.shape({
tidyCode: PropTypes.func,
Expand All @@ -374,9 +373,6 @@ Nav.propTypes = {
rootFile: PropTypes.shape({
id: PropTypes.string.isRequired
}).isRequired,
params: PropTypes.shape({
username: PropTypes.string
}),
t: PropTypes.func.isRequired,
setLanguage: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
Expand All @@ -391,10 +387,6 @@ Nav.defaultProps = {
},
cmController: {},
layout: 'project',
warnIfUnsavedChanges: undefined,
params: {
username: undefined
},
editorLink: '/'
};

Expand All @@ -420,6 +412,6 @@ const mapDispatchToProps = {
};

export default withTranslation()(
withRouter(connect(mapStateToProps, mapDispatchToProps)(Nav))
connect(mapStateToProps, mapDispatchToProps)(Nav)
);
export { Nav as NavComponent };
2 changes: 1 addition & 1 deletion client/components/PreviewNav.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import LogoIcon from '../images/p5js-logo-small.svg';
Expand Down
13 changes: 10 additions & 3 deletions client/components/__snapshots__/Nav.unit.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ exports[`Nav renders correctly 1`] = `
<li
class="nav__dropdown-item"
>
<a />
<a
href="/new-user/sketches"
/>
</li>
</ul>
</li>
Expand Down Expand Up @@ -195,7 +197,9 @@ exports[`Nav renders correctly 1`] = `
<li
class="nav__dropdown-item"
>
<a />
<a
href="/about"
/>
</li>
</ul>
</li>
Expand Down Expand Up @@ -229,6 +233,7 @@ exports[`Nav renders dashboard version 1`] = `
>
<a
class="nav__back-link"
href="/"
>
<test-file-stub
aria-hidden="true"
Expand Down Expand Up @@ -447,7 +452,9 @@ exports[`Nav renders editor version 1`] = `
<li
class="nav__dropdown-item"
>
<a>
<a
href="/about"
>
About
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion client/components/createRedirectWithUsername.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import browserHistory from '../browserHistory';

const RedirectToUser = ({ username, url = '/:username/sketches' }) => {
React.useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/components/mobile/Tab.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { prop, remSize } from '../../theme';

export default styled(Link)`
Expand Down
7 changes: 2 additions & 5 deletions client/index.integration.test.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import React from 'react';
import { Router, browserHistory } from 'react-router';
import Routing from './routes';

import { reduxRender, act, waitFor, screen, within } from './test-utils';
import configureStore from './store';
import routes from './routes';
import * as Actions from './modules/User/actions';
import { userResponse } from './testData/testServerResponses';

// setup for the app
const history = browserHistory;
const initialState = window.__INITIAL_STATE__;
const store = configureStore(initialState);

Expand Down Expand Up @@ -56,8 +54,7 @@ document.createRange = () => {
// start testing
describe('index.jsx integration', () => {
// the subject under test
const subject = () =>
reduxRender(<Router history={history} routes={routes(store)} />, { store });
const subject = () => reduxRender(<Routing />, { store });

// spy on this function and wait for it to be called before making assertions
const spy = jest.spyOn(Actions, 'getUser');
Expand Down
10 changes: 6 additions & 4 deletions client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { Suspense } from 'react';
import { render } from 'react-dom';
import { hot } from 'react-hot-loader/root';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { Router } from 'react-router-dom';

import browserHistory from './browserHistory';
import configureStore from './store';
import routes from './routes';
import Routing from './routes';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import './i18n';
Expand All @@ -15,15 +16,16 @@ require('./styles/main.scss');
// Load the p5 png logo, so that webpack will use it
require('./images/p5js-square-logo.png');

const history = browserHistory;
const initialState = window.__INITIAL_STATE__;

const store = configureStore(initialState);

const App = () => (
<Provider store={store}>
<ThemeProvider>
<Router history={history} routes={routes(store)} />
<Router history={browserHistory}>
<Routing />
</Router>
</ThemeProvider>
</Provider>
);
Expand Down
3 changes: 2 additions & 1 deletion client/modules/App/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import getConfig from '../../utils/getConfig';
import DevTools from './components/DevTools';
import { setPreviousPath } from '../IDE/actions/ide';
Expand Down Expand Up @@ -87,4 +88,4 @@ const mapStateToProps = (state) => ({

const mapDispatchToProps = { setPreviousPath, setLanguage };

export default connect(mapStateToProps, mapDispatchToProps)(App);
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App));
2 changes: 1 addition & 1 deletion client/modules/App/components/Overlay.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PropTypes from 'prop-types';
import React from 'react';
import { browserHistory } from 'react-router';
import { withTranslation } from 'react-i18next';

import browserHistory from '../../../browserHistory';
import ExitIcon from '../../../images/exit.svg';

class Overlay extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/actions/collections.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browserHistory } from 'react-router';
import browserHistory from '../../../browserHistory';
import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/actions/project.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { browserHistory } from 'react-router';
import objectID from 'bson-objectid';
import each from 'async/each';
import isEqual from 'lodash/isEqual';
import browserHistory from '../../../browserHistory';
import apiClient from '../../../utils/apiClient';
import getConfig from '../../../utils/getConfig';
import * as ActionTypes from '../../../constants';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useSelector } from 'react-redux';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import SquareLogoIcon from '../../../images/p5js-square-logo.svg';
// import PlayIcon from '../../../images/play.svg';
import AsteriskIcon from '../../../images/p5-asterisk.svg';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/AssetList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import prettyBytes from 'pretty-bytes';
import { withTranslation } from 'react-i18next';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { withTranslation } from 'react-i18next';
import * as ProjectActions from '../../actions/project';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/ErrorModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

const ErrorModal = ({ type, service, closeModal }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';

import Icons from './Icons';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/SketchList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { Helmet } from 'react-helmet';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import classNames from 'classnames';
import slugify from 'slugify';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/Toolbar.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import { withTranslation } from 'react-i18next';
import * as IDEActions from '../actions/ide';
Expand Down
2 changes: 1 addition & 1 deletion client/modules/IDE/components/UploadFileModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import prettyBytes from 'pretty-bytes';
import getConfig from '../../../utils/getConfig';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ exports[`<Sketchlist /> snapshot testing 1`] = `
<th
scope="row"
>
<a>
<a
href="/happydog/sketches/testid1"
>
testsketch1
</a>
</th>
Expand Down Expand Up @@ -100,7 +102,9 @@ exports[`<Sketchlist /> snapshot testing 1`] = `
<th
scope="row"
>
<a>
<a
href="/happydog/sketches/testid2"
>
testsketch2
</a>
</th>
Expand Down
Loading
Loading