Skip to content

refactor: upgrade React Router to v6 #1954

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
22a9d56
refactor: upgrade React Router to v6
visualfanatic Dec 9, 2021
eae0413
Start refactoring the route list
visualfanatic Dec 9, 2021
4348179
Get rid of another unnecessary div wrapper
visualfanatic Dec 9, 2021
69ac657
Merge branch 'alpha' into upgrade-to-react-router-v6
visualfanatic Jan 22, 2022
eb4f593
Update router to latest version
visualfanatic Jan 22, 2022
59584f9
Refactor AppData into functional component
visualfanatic Jan 22, 2022
352fe63
Convert all of the routes to the new convention
visualfanatic Jan 22, 2022
04373fa
Remote unused file
visualfanatic Jan 22, 2022
6bfef3d
Wrap Explorer with router HOC
visualfanatic Jan 22, 2022
d5d443f
Merge branch 'alpha' into upgrade-to-react-router-v6
visualfanatic Jan 24, 2022
46c41ae
Merge branch 'alpha' into upgrade-to-react-router-v6
visualfanatic May 8, 2022
44458b9
Update react-router-dom
visualfanatic May 8, 2022
e9daf47
Merge branch 'alpha' into upgrade-to-react-router-v6
visualfanatic May 8, 2022
2186f11
Merge remote-tracking branch 'upstream/alpha' into upgrade-to-react-r…
damianstasik Sep 25, 2022
dd05ba5
Update router to 6.4
damianstasik Sep 25, 2022
f69d4c1
Pass basename if available
damianstasik Sep 25, 2022
a0ebac0
Separate exports from decorated classes to make code a bit more clearer
damianstasik Sep 25, 2022
7488dd8
Spread outlet context as direct props
damianstasik Sep 25, 2022
485a1c9
Simplify link urls
damianstasik Sep 25, 2022
5bfbdf7
Avoid using global location, better to be safe and use one provided f…
damianstasik Sep 25, 2022
2a89cf7
Enable experimental decorators in js config to improve DX
damianstasik Sep 25, 2022
85cf108
Bring back old separation to see if PR diff would be easier to unders…
damianstasik Sep 25, 2022
308f987
Bring back old structure, plan is to refactor it to useRoutes in a se…
damianstasik Sep 25, 2022
83f731c
Merge branch 'alpha' into upgrade-to-react-router-v6
mtrezza Sep 27, 2022
d0e8f4b
Merge remote-tracking branch 'upstream/alpha' into upgrade-to-react-r…
damianstasik Oct 1, 2022
ec3145e
Merge remote-tracking branch 'upstream/alpha' into upgrade-to-react-r…
damianstasik Oct 1, 2022
1bead2d
Merge branch 'alpha' into upgrade-to-react-router-v6
mtrezza Oct 1, 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
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"compilerOptions": {
"experimentalDecorators": true
},
"typeAcquisition": {
"include": [
"jest"
Expand Down
163 changes: 48 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"express": "4.18.1",
"graphiql": "2.0.7",
"graphql": "16.6.0",
"history": "4.10.1",
"immutable": "4.1.0",
"immutable-devtools": "0.1.5",
"inquirer": "8.2.4",
Expand All @@ -68,8 +67,7 @@
"react-helmet": "6.1.0",
"react-json-view": "1.21.3",
"react-popper-tooltip": "4.4.2",
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
"react-router-dom": "6.4.1",
"regenerator-runtime": "0.13.9",
"semver": "7.3.7",
"typescript": "4.8.2"
Expand Down Expand Up @@ -103,7 +101,6 @@
"madge": "5.0.1",
"marked": "4.0.10",
"null-loader": "4.0.1",
"path-to-regexp": "3.2.0",
"puppeteer": "18.0.5",
"react-test-renderer": "16.13.1",
"request": "2.88.2",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Autocomplete/Autocomplete.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* the root directory of this source tree.
*/
import Position from 'lib/Position';
import PropTypes from 'prop-types'
import PropTypes from 'lib/PropTypes'
import React, { Component } from 'react';
import styles from 'components/Autocomplete/Autocomplete.scss';
import SuggestionsList from 'components/SuggestionsList/SuggestionsList.react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Chip/Chip.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import React from 'react';
import styles from 'components/Chip/Chip.scss';
import PropTypes from 'prop-types'
import PropTypes from 'lib/PropTypes'
import Icon from 'components/Icon/Icon.react'

let Chip = ({ value, onClose }) => (
Expand Down
9 changes: 6 additions & 3 deletions src/components/FourOhFour/FourOhFour.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
import history from 'dashboard/history';
import React from 'react';
import styles from 'components/FourOhFour/FourOhFour.scss';
import { withRouter } from 'lib/withRouter';

const EMOJI_COUNT = 30;

export default class FourOhFour extends React.Component {
@withRouter
class FourOhFour extends React.Component {
constructor() {
super();

Expand Down Expand Up @@ -51,10 +52,12 @@ export default class FourOhFour extends React.Component {
<div className={styles.message}>Oh no, we can't find that page!</div>

<div className={styles.back}>
<button type='button' onClick={() => history.goBack()}>Go back</button>
<button type='button' onClick={() => this.props.navigate(-1)}>Go back</button>
</div>
</div>
</div>
);
}
}

export default FourOhFour;
2 changes: 1 addition & 1 deletion src/components/Sidebar/AppsMenu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AppsMenu = ({ apps, current, height, onSelect, onPinClick }) => (
return null;
}
return (
<Link to={{ pathname: html`/apps/${app.slug}/browser` }} key={app.slug} className={styles.menuRow} onClick={onSelect.bind(null, current.slug)}>
<Link to={html`/apps/${app.slug}/browser`} key={app.slug} className={styles.menuRow} onClick={onSelect.bind(null, current.slug)}>
<span>{app.name}</span>
<AppBadge production={app.production} />
</Link>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Toolbar/Toolbar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import PropTypes from 'lib/PropTypes';
import React from 'react';
import Icon from 'components/Icon/Icon.react';
import styles from 'components/Toolbar/Toolbar.scss';
import history from 'dashboard/history';

const goBack = () => history.goBack();
import { useNavigate, useNavigationType, NavigationType } from 'react-router-dom';

let Toolbar = (props) => {
const action = useNavigationType();
const navigate = useNavigate();
let backButton;
if ((props.relation || (props.filters && props.filters.size)) && history.action !== 'POP') {
if ((props.relation || (props.filters && props.filters.size)) && action !== NavigationType.Pop) {
backButton = (
<a
className={styles.iconButton}
onClick={goBack}
onClick={() => navigate(-1)}
>
<Icon
width={32}
Expand Down
5 changes: 4 additions & 1 deletion src/dashboard/Analytics/Explorer/Explorer.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import stylesTable from 'components/Table/Table.scss';
import subscribeTo from 'lib/subscribeTo';
import Toolbar from 'components/Toolbar/Toolbar.react';
import baseStyles from 'stylesheets/base.scss';
import { withRouter } from 'lib/withRouter';

let buildFriendlyName = (query) => {
let name = [query.source];
Expand All @@ -38,8 +39,8 @@ let buildFriendlyName = (query) => {
return name.join(' ');
};

export default
@subscribeTo('AnalyticsQuery', 'customQueries')
@withRouter
class Explorer extends DashboardView {
constructor() {
super();
Expand Down Expand Up @@ -547,3 +548,5 @@ class Explorer extends DashboardView {
);
}
}

export default Explorer;
45 changes: 24 additions & 21 deletions src/dashboard/AppData.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@
import React from 'react';
import AppSelector from 'dashboard/AppSelector.react';
import AppsManager from 'lib/AppsManager';
import history from 'dashboard/history';
import { CurrentApp } from 'context/currentApp';
import { Outlet, useNavigate , useParams} from 'react-router-dom';

class AppData extends React.Component {
render() {
if (this.props.params.appId === '_') {
return <AppSelector />;
}
//Find by name to catch edge cases around escaping apostrophes in URLs
let current = AppsManager.findAppBySlugOrName(this.props.params.appId);
if (current) {
current.setParseKeys();
} else {
history.replace('/apps');
return <div />;
}
return (
<CurrentApp.Provider value={current}>
<div>
{this.props.children}
</div>
</CurrentApp.Provider>
);

function AppData() {
const navigate = useNavigate();
const params = useParams();

if (params.appId === '_') {
return <AppSelector />;
}

// Find by name to catch edge cases around escaping apostrophes in URLs
let current = AppsManager.findAppBySlugOrName(params.appId);

if (current) {
current.setParseKeys();
} else {
navigate('/apps', { replace: true });
return <div />;
}

return (
<CurrentApp.Provider value={current}>
<Outlet />
</CurrentApp.Provider>
);
}

export default AppData;
13 changes: 8 additions & 5 deletions src/dashboard/AppSelector.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import AppsManager from 'lib/AppsManager';
import Dropdown from 'components/Dropdown/Dropdown.react';
import Field from 'components/Field/Field.react';
import history from 'dashboard/history';
import Label from 'components/Label/Label.react';
import Modal from 'components/Modal/Modal.react';
import Option from 'components/Dropdown/Option.react';
import React from 'react';
import { withRouter } from 'lib/withRouter';

export default class AppSelector extends React.Component {
@withRouter
class AppSelector extends React.Component {
constructor(props) {
super(props);
let apps = AppsManager.apps();
Expand All @@ -25,12 +26,12 @@ export default class AppSelector extends React.Component {
}

handleConfirm() {
let newPath = location.pathname.replace(/\/_(\/|$)/, '/' + this.state.slug + '/');
history.push(newPath);
let newPath = this.location.pathname.replace(/\/_(\/|$)/, '/' + this.state.slug + '/');
this.props.navigate(newPath);
}

handleCancel() {
history.push('/apps');
this.props.navigate('/apps');
}

render() {
Expand Down Expand Up @@ -58,3 +59,5 @@ export default class AppSelector extends React.Component {
);
}
}

export default AppSelector;
13 changes: 9 additions & 4 deletions src/dashboard/Apps/AppsIndex.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
import AppsManager from 'lib/AppsManager';
import FlowFooter from 'components/FlowFooter/FlowFooter.react';
import history from 'dashboard/history';
import html from 'lib/htmlString';
import Icon from 'components/Icon/Icon.react';
import joinWithFinal from 'lib/joinWithFinal';
Expand All @@ -17,6 +16,8 @@ import React from 'react';
import styles from 'dashboard/Apps/AppsIndex.scss';
import baseStyles from 'stylesheets/base.scss';
import AppBadge from 'components/AppBadge/AppBadge.react';
import { withRouter } from 'lib/withRouter';
import { useNavigate } from 'react-router-dom';

function dash(value, content) {
if (value === undefined) {
Expand Down Expand Up @@ -64,7 +65,8 @@ let AppCard = ({
app,
icon,
}) => {
let canBrowse = app.serverInfo.error ? null : () => history.push(html`/apps/${app.slug}/browser`);
const navigate = useNavigate();
let canBrowse = app.serverInfo.error ? null : () => navigate(html`/apps/${app.slug}/browser`);
let versionMessage = app.serverInfo.error ?
<div className={styles.serverVersion}>Server not reachable: <span className={styles.ago}>{app.serverInfo.error.toString()}</span></div>:
<div className={styles.serverVersion}>
Expand All @@ -88,7 +90,8 @@ let AppCard = ({
</li>
}

export default class AppsIndex extends React.Component {
@withRouter
class AppsIndex extends React.Component {
constructor() {
super();
this.state = { search: '' };
Expand All @@ -99,7 +102,7 @@ export default class AppsIndex extends React.Component {
componentWillMount() {
if (AppsManager.apps().length === 1) {
const [app] = AppsManager.apps();
history.push(`/apps/${app.slug}/browser`);
this.props.navigate(`/apps/${app.slug}/browser`);
return;
}
document.body.addEventListener('keydown', this.focusField);
Expand Down Expand Up @@ -169,3 +172,5 @@ export default class AppsIndex extends React.Component {
);
}
}

export default AppsIndex;
Loading