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

CUMULUS-3862: Upgrade React Router to v6 #1148

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a66abd6
init PR
jjmccoy Sep 25, 2024
739d0f4
upgrade react router to v6.26.2
jjmccoy Sep 25, 2024
2c0ed05
update App.js routing syntax
jjmccoy Sep 26, 2024
293cc57
establish withRouter wrapper
jjmccoy Sep 26, 2024
53d8d78
replace switch with routes syntax
jjmccoy Sep 26, 2024
610f753
upgrade history dependency
jjmccoy Sep 27, 2024
5d44d14
correct root reference for router
jjmccoy Sep 27, 2024
3d1d72d
create search query params wrapper for React hook
jjmccoy Oct 4, 2024
34b8594
establish new queryparams and useselector hooks
jjmccoy Oct 7, 2024
e4ce414
rework nested routes with login and auth to react router v6
jjmccoy Oct 9, 2024
2eb453f
establish new UrlHelper HOC for query params
jjmccoy Oct 17, 2024
cc6b48d
fix router and location for auth to home page
jjmccoy Oct 17, 2024
f9cfced
consolidate HOC wrappers into one
jjmccoy Oct 17, 2024
271d4dc
parent pages params to state routed
jjmccoy Oct 18, 2024
a5e31c3
initial routing updates for child pages
jjmccoy Oct 22, 2024
e232f64
link parent and child page routes for top navigation
jjmccoy Oct 25, 2024
7a2b8f8
initial table config link and button params
jjmccoy Oct 31, 2024
689dffe
refactor SortableTable and select table-configs
jjmccoy Nov 1, 2024
aa7e3ed
more table routing for links and buttons
jjmccoy Nov 26, 2024
0ddab3f
addtl routing updates
jjmccoy Dec 4, 2024
c43285c
more routing updates and console error fixes
jjmccoy Dec 6, 2024
34f4bfa
Merge branch 'develop' into CUMULUS-3862
jjmccoy Dec 9, 2024
3010f1d
update changelog
jjmccoy Dec 9, 2024
77ce9ab
update packages with --legacy-peer-deps for react router work
jjmccoy Dec 9, 2024
1f39ea4
finalize routes
jjmccoy Dec 11, 2024
538f684
fix rendering issues
jjmccoy Dec 13, 2024
8d769d8
fix render routing for edit collection
jjmccoy Dec 18, 2024
df34d89
clean up notes and comment outs
jjmccoy Dec 19, 2024
212fe1d
fix code to show stats in sidebar
jjmccoy Dec 23, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ This version of the dashboard requires Cumulus API >= v19.2.0-alpha.1 (TBD API r
`@cumulus/[email protected]`
- Updated the integration tests to work with updated API
- Updated packages to address [CVE-2024-21538] (https://github.com/advisories/GHSA-3xgq-45jj-v275)
- **CUMULUS-3862**
- Upgraded React Router to v6.26.2
- Updated routes for navigation for menus, pagination, sections, and parent-child pages
- Established new router with withRouter.js HOC
- Replaced URL params utility with withUrlHelper.js HOC
- **CUMULUS-3870**
- Remove launchpad security key information from cypress fixture for `valid-execution.json`
- Add placeholders for security information with `fakePassword` and `userName`
Expand Down
2 changes: 1 addition & 1 deletion app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ import App from './js/App';
});
} */

ReactDOM.render(<App />, document.getElementById('site-canvas'));
ReactDOM.render(<App />, document.getElementById('root'));
84 changes: 47 additions & 37 deletions app/src/js/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, { useState } from 'react';
import { Provider } from 'react-redux';
import { Route, Redirect, Switch } from 'react-router-dom';
import { ConnectedRouter } from 'connected-react-router';

import ourConfigureStore, { history } from './store/configureStore';
import { Provider, useSelector } from 'react-redux';
import {
Routes,
Route,
Navigate,
BrowserRouter,
} from 'react-router-dom';
import ourConfigureStore from './store/configureStore';

// Authorization & Error Handling
// import ErrorBoundary from './components/Errors/ErrorBoundary';
import ErrorBoundary from './components/Errors/ErrorBoundary';
import NotFound from './components/404';
import OAuth from './components/oauth';

Expand All @@ -27,44 +30,51 @@ import config from './config';

console.log('Environment', config.environment);

// Wrapper for Main component to include routing
const MainRoutes = () => (
<Main path='/'>
<Switch>
<Route exact path='/' component={Home} />
<Route path='/404' component={NotFound} />
<Route path='/collections' component={Collections} />
<Route path='/granules' component={Granules} />
<Route path='/pdrs' component={Pdrs} />
<Route path='/providers' component={Providers} />
<Route path='/workflows' component={Workflows} />
<Route path='/executions' component={Executions} />
<Route path='/operations' component={Operations} />
<Route path='/rules' component={Rules} />
<Route path='/reconciliation-reports' component={ReconciliationReports} />
</Switch>
</Main>
);
// Establish auth and login rules if user is or is not authenticated via Launchpad
const AuthenicatedRoute = () => {
const isAuthenticated = useSelector((state) => state.api.authenticated);
console.log('Authentication status:', isAuthenticated);
return isAuthenticated ? <Main /> : <Navigate to='auth' replace />;
};

const LoginRoute = () => {
const isAuthenticated = useSelector((state) => state.api.authenticated);
return isAuthenticated ? <Navigate to='/' replace /> : <OAuth />;
};

// generate the root App Component
// Routes for the Cumulus Dashboard app
const App = () => {
const [store] = useState(ourConfigureStore({}));
const isLoggedIn = () => store.getState().api.authenticated;

return (
// <ErrorBoundary> // Add after troublshooting other errors
// Routes
<div className="routes">
// Router with Store
<div className='routes'>
<ErrorBoundary>
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Redirect exact from='/login' to='/auth' />
<Route path='/auth' render={() => (isLoggedIn() ? <Redirect to='/' /> : <OAuth />)} />
<Route path='/' render={() => (isLoggedIn() ? <MainRoutes /> : <Redirect to='/auth' />)} />
</Switch>
</ConnectedRouter>
<BrowserRouter>
<Routes>
<Route path={'/login'} element={<Navigate to='/auth' replace />} />
<Route path={'/auth'} element={<LoginRoute />} />
<Route element={<AuthenicatedRoute />}>
<Route path={'/'} index element={<Home />} />
<Route path={'/collections/*'} element={<Collections />} />
<Route path={'/providers/*'} element={<Providers />} />
<Route path={'/granules/*'} element={<Granules />} />
<Route path={'/workflows/*'} element={<Workflows />} />
<Route path={'/executions/*'} element={<Executions />} />
<Route path={'/operations/*'} element={<Operations />} />
<Route path={'/rules/*'} element={<Rules />} />
<Route path={'/pdrs/*'} element={<Pdrs />} />
<Route path={'/reconciliation-reports/*'} element={<ReconciliationReports />}/>
</Route>
<Route path={'/404'} element={<NotFound />} />
<Route path={'*'} element={<Navigate to='/404' replace />} />
<Route path={'*'} element={<Navigate to='/' replace />} />
</Routes>
</BrowserRouter>
</Provider>
</div>
</ErrorBoundary>
</div>
);
};

Expand Down
2 changes: 1 addition & 1 deletion app/src/js/components/404.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import withRouter from '../withRouter';

const NotFound = () => (
<div className='page__404'>
Expand Down
2 changes: 1 addition & 1 deletion app/src/js/components/Add/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { get } from 'object-path';
import { getSchema } from '../../actions';
import Schema from '../FormSchema/schema';
Expand All @@ -11,6 +10,7 @@ import _config from '../../config';
import { strings } from '../locale';
import { window } from '../../utils/browser';
import { historyPushWithQueryParams } from '../../utils/url-helper';
import withRouter from '../../withRouter';

const { updateDelay } = _config;

Expand Down
3 changes: 2 additions & 1 deletion app/src/js/components/AddRaw/add-raw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
// import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import { get } from 'object-path';
import { displayCase } from '../../utils/format';
Expand All @@ -9,6 +9,7 @@ import _config from '../../config';
import TextArea from '../TextAreaForm/text-area';
import DefaultModal from '../Modal/modal';
import { historyPushWithQueryParams } from '../../utils/url-helper';
import withRouter from '../../withRouter';

const { updateDelay } = _config;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
// import { withRouter } from 'react-router';
import queue from 'stubborn-queue';
import {
CircularProgressbar,
Expand All @@ -13,6 +13,7 @@ import isArray from 'lodash/isArray';
import AsyncCommand from '../AsyncCommands/AsyncCommands';
import DefaultModal from '../Modal/modal';
import ErrorReport from '../Errors/report';
import withRouter from '../../withRouter';

const CONCURRENCY = 3;

Expand Down
35 changes: 20 additions & 15 deletions app/src/js/components/Breadcrumbs/Breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Link, useLocation } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { Breadcrumb } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import { getPersistentQueryParams } from '../../utils/url-helper';
import PropTypes from 'prop-types';
import { withUrlHelper } from '../../withUrlHelper';

const Breadcrumbs = ({ config, locationQueryParams }) => (
const Breadcrumbs = ({ config, urlHelper }) => {
const location = useLocation();
const locationQueryParams = useSelector((state) => state.locationQueryParams);
const { getPersistentQueryParams } = urlHelper;

return (
<Breadcrumb>
{config.map((item, index) => {
const { href, label, active } = item || {};
Expand All @@ -17,24 +22,24 @@ const Breadcrumbs = ({ config, locationQueryParams }) => (
{active
? <span>{label}</span>
: <Link
to={(toLocation) => (
{
pathname: href,
search: locationQueryParams.search[href] || getPersistentQueryParams(toLocation)
})}>
to={{
pathname: href,
search: locationQueryParams.search[href] || getPersistentQueryParams(location)
}}>
{label}
</Link>}
</li>
);
})}
</Breadcrumb>
);
);
};

Breadcrumbs.propTypes = {
config: PropTypes.arrayOf(PropTypes.object),
locationQueryParams: PropTypes.object,
urlHelper: PropTypes.shape({
getPersistentQueryParams: PropTypes.func
}),
};

export default connect((state) => ({
locationQueryParams: state.locationQueryParams
}))(Breadcrumbs);
export default withUrlHelper(Breadcrumbs);
22 changes: 11 additions & 11 deletions app/src/js/components/Collections/add.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import React, { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { createCollection, getSchema } from '../../actions';
import { getCollectionId, collectionHrefFromId } from '../../utils/format';
import { removeReadOnly } from '../FormSchema/schema';
import AddRaw from '../AddRaw/add-raw';
import withRouter from '../../withRouter';

const AddCollection = () => {
const dispatch = useDispatch();
const location = useLocation();

const collections = useSelector((state) => state.collections);
const schema = useSelector((state) => state.schema);

const AddCollection = ({ location = {}, collections, dispatch, schema }) => {
const [defaultValue, setDefaultValue] = useState({});
const { state: locationState } = location;
const { name, version } = locationState || {};
Expand Down Expand Up @@ -52,15 +59,8 @@ const AddCollection = ({ location = {}, collections, dispatch, schema }) => {
};

AddCollection.propTypes = {
location: PropTypes.object,
collections: PropTypes.object,
dispatch: PropTypes.func,
schema: PropTypes.object,
};

export default withRouter(
connect((state) => ({
collections: state.collections,
schema: state.schema,
}))(AddCollection)
);
export default withRouter(AddCollection);
14 changes: 10 additions & 4 deletions app/src/js/components/Collections/edit.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import {
getCollection,
updateCollection,
clearUpdateCollection,
} from '../../actions';
import { getCollectionId, collectionHrefFromNameVersion } from '../../utils/format';
import EditRaw from '../EditRaw/edit-raw';
import { withRouter } from '../../withRouter';

const SCHEMA_KEY = 'collection';

Expand All @@ -20,6 +20,12 @@ const EditCollection = ({ match, collections }) => {
const decodedVersion = decodeURIComponent(version);
const collectionId = getCollectionId({ name, version: decodedVersion });

useEffect(() => {
if (name && version) {
getCollection(name, version);
}
}, [name, version, decodedVersion]);

return (
<div className = "edit_collections">
<Helmet>
Expand Down Expand Up @@ -47,6 +53,6 @@ EditCollection.propTypes = {

export default withRouter(
connect((state) => ({
collections: state.collections,
collections: state.collections
}))(EditCollection)
);
30 changes: 17 additions & 13 deletions app/src/js/components/Collections/granules.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState, useEffect } from 'react';
import { connect, useDispatch } from 'react-redux';
import { Helmet } from 'react-helmet';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { get } from 'object-path';
import {
getCollectionId,
Expand Down Expand Up @@ -33,16 +32,17 @@ import { granuleStatus as statusOptions } from '../../utils/status';
import { workflowOptionNames } from '../../selectors';
import ListFilters from '../ListActions/ListFilters';
import CollectionHeader from './collection-header';
import withRouter from '../../withRouter';

const CollectionGranules = ({
dispatch,
granules,
match,
queryParams,
workflowOptions,
providers,
router
}) => {
const { params } = match;
const dispatch = useDispatch();
const { params } = router;
const { name: collectionName, version: collectionVersion, status } = params;
const granuleStatus = status === 'processing' ? 'running' : status;
const { list } = granules;
Expand All @@ -52,9 +52,11 @@ const CollectionGranules = ({
name: collectionName,
version: decodedVersion,
});

const [workflow, setWorkflow] = useState(workflowOptions[0]);
const [workflowMeta, setWorkflowMeta] = useState(defaultWorkflowMeta);
const [selected, setSelected] = useState([]);

const query = generateQuery();
const { dropdowns } = providers;

Expand Down Expand Up @@ -213,16 +215,18 @@ const CollectionGranules = ({
CollectionGranules.propTypes = {
granules: PropTypes.object,
dispatch: PropTypes.func,
match: PropTypes.object,
queryParams: PropTypes.object,
workflowOptions: PropTypes.array,
providers: PropTypes.object,
router: PropTypes.shape({
params: PropTypes.object
}),
};

export default withRouter(
connect((state) => ({
granules: state.granules,
workflowOptions: workflowOptionNames(state),
providers: state.providers,
}))(CollectionGranules)
);
const mapStateToProps = (state) => ({
granules: state.granules,
workflowOptions: workflowOptionNames(state),
providers: state.providers,
});

export default withRouter(connect(mapStateToProps)(CollectionGranules));
Loading