Skip to content

Commit

Permalink
move to react-router v7
Browse files Browse the repository at this point in the history
Move to node 20, react-router 7

split splat routes

Set global.TextEncoder for react-scripts test
  • Loading branch information
mshriver committed Dec 18, 2024
1 parent cf19201 commit 5a231d8
Show file tree
Hide file tree
Showing 35 changed files with 763 additions and 408 deletions.
2 changes: 1 addition & 1 deletion frontend/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v20
2 changes: 1 addition & 1 deletion frontend/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
framework: "create-react-app",
bundler: "webpack",
},
specPattern: "src/**/*.cy.{js,jsx,ts,tsx}",
specPattern: "src/**/*.cy.{js,jsx,cjs,mjs,ts,tsx}",
excludeSpecPattern: "**/node_modules/**",
viewportHeight: 660,
viewportWidth: 1000
Expand Down
2 changes: 2 additions & 0 deletions frontend/jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// jest.polyfills.js
global.TextEncoder = require('util').TextEncoder;
21 changes: 10 additions & 11 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"@babel/core": "^7.24.7",
"@babel/eslint-parser": "7.25.9",
"@babel/helper-call-delegate": "^7.12.13",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/plugin-syntax-flow": "^7.14.5",
"@babel/plugin-transform-class-properties": "^7.24.7",
"@babel/plugin-transform-private-methods": "^7.24.7",
Expand All @@ -17,36 +16,36 @@
"@greatsumini/react-facebook-login": "^3.3.3",
"@monaco-editor/react": "^4.6.0",
"@patternfly/patternfly": "^5.2.1",
"@patternfly/react-charts": "^8.0.0",
"@patternfly/react-core": "^6.0.0",
"@patternfly/react-icons": "^6.0.0",
"@patternfly/react-styles": "^6.0.0",
"@patternfly/react-table": "^6.0.0",
"@patternfly/react-charts": "^7.4.7",
"@patternfly/react-icons": "^5.4.2",
"@patternfly/react-styles": "^5.4.1",
"@patternfly/react-table": "5.4.12",
"@react-oauth/google": "^0.12.1",
"@testing-library/dom": "^10.0.0",
"@testing-library/react": "^16.1.0",
"@types/react": "18",
"cypress": "^13.16.1",
"@types/react": "^18.3.12",
"enzyme": "^3.11.0",
"fs-extra": "^11.2.0",
"globals": "^15.13.0",
"keycloak-js": "^26.0.7",
"monaco-editor": "^0.47.0",
"prop-types": "^15.8.1",
"react": "18",
"react-dom": "18",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-heatmap-grid": "^0.9.0",
"react-json-tree": "^0.19.0",
"react-linkify": "^1.0.0-alpha",
"react-password-strength-bar": "^0.4.1",
"react-router": "5.3.4",
"react-router": "^7.0.2",
"react-scripts": "^5.0.1",
"react-simple-oauth2-login": "^0.5.4",
"serve": "^12.0.1",
"typescript": "^4.9.5",
"wolfy87-eventemitter": "^5.2.9"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"cypress": "^13.17.0",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-cypress": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Navigate, Route, Routes } from 'react-router-dom';
import { Navigate, Route, Routes } from 'react-router';
import EventEmitter from 'wolfy87-eventemitter';
import ElementWrapper from './components/elementWrapper';

Expand Down
41 changes: 21 additions & 20 deletions frontend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import EventEmitter from 'wolfy87-eventemitter';
import ElementWrapper from './components/elementWrapper';

import { Navigate, Route, Routes } from 'react-router-dom';
import {Route, Routes } from 'react-router';

import { Dashboard } from './dashboard';
import { ReportBuilder } from './report-builder';
Expand Down Expand Up @@ -38,23 +38,19 @@ export class App extends React.Component {
path=""
element={<ElementWrapper routeElement={IbutsuPage} eventEmitter={this.eventEmitter} />}
/>
<Route
path=":project_id/*"
element={<ElementWrapper routeElement={IbutsuPage} eventEmitter={this.eventEmitter} />}
>

{/* Nested project routes */}
<Route
path="dashboard/:dashboard_id"
element={
<ElementWrapper routeElement={Dashboard} eventEmitter={this.eventEmitter} />
}
/>
<Route
path="dashboard/*"
element={<ElementWrapper routeElement={Dashboard} eventEmitter={this.eventEmitter} />}
/>

<Route path=":project_id">
<Route path="dashboard">
<Route path=':dashboard_id' element={
<ElementWrapper routeElement={Dashboard}
eventEmitter={this.eventEmitter} />}>
</Route>
<Route
path="*"
element={
<ElementWrapper routeElement={Dashboard}
eventEmitter={this.eventEmitter} />}>
</Route>
</Route>

<Route
path="runs"
Expand All @@ -66,7 +62,6 @@ export class App extends React.Component {
path="runs/:run_id"
element={<ElementWrapper routeElement={Run} />}
/>

<Route
path="results"
element={<ElementWrapper routeElement={ResultList} eventEmitter={this.eventEmitter} />}
Expand All @@ -85,7 +80,13 @@ export class App extends React.Component {
path="view/:view_id"
element={<ElementWrapper routeElement={View} />}
/>
<Route path="*" element={<Navigate to="dashboard" replace />} />

<Route
path="*"
element={<ElementWrapper routeElement={IbutsuPage}
eventEmitter={this.eventEmitter} />}
>
</Route>
</Route>
</Routes>
);
Expand Down
28 changes: 15 additions & 13 deletions frontend/src/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { BrowserRouter, Route, Routes, Navigate } from 'react-router';
import { App } from './app';
import { Admin } from './admin';
import Profile from './profile';
Expand All @@ -14,26 +14,28 @@ import { IbutsuContextProvider } from './services/context';

export const Base = () => (
<IbutsuContextProvider>
<Router>
<BrowserRouter future={{v7_relativeSplatPath: true}}>
<Routes>
<Route path="login" element={<ElementWrapper routeElement={Login} />} />
<Route path="sign-up" element={<ElementWrapper routeElement={SignUp} />} />
<Route path="forgot-password" element={<ElementWrapper routeElement={ForgotPassword} />} />
<Route path="reset-password/:activationCode" element={<ElementWrapper routeElement={ResetPassword} />} />
<Route
path="profile/*"
element={AuthService.isLoggedIn() ? <Profile /> : <Navigate to="/login" />}
/>
<Route
path="admin/*"
<Route path="profile">
<Route path="*"
element={AuthService.isLoggedIn() ? <Profile /> : <Navigate to="/login" />}
/>
</Route>
<Route path="admin">
<Route path="*"
element={AuthService.isLoggedIn() && AuthService.isSuperAdmin() ? <Admin /> : <Navigate to="/login" />}
/>
<Route
path="project/*"
element={AuthService.isLoggedIn() ? <App /> : <Navigate to="/login" />}
/>
</Route>

<Route path="project"
element={AuthService.isLoggedIn() ? <App /> : <Navigate to="/login" />}/>

<Route path="*" element={<Navigate to="project" replace />} />
</Routes>
</Router>
</BrowserRouter>
</IbutsuContextProvider>
);
2 changes: 1 addition & 1 deletion frontend/src/components/admin-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PageSidebarBody
} from '@patternfly/react-core';

import { Link, Outlet } from 'react-router-dom';
import { Link, Outlet } from 'react-router';
import ElementWrapper from './elementWrapper';

import { IbutsuHeader } from './ibutsu-header';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/elementWrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Wrapper
import React from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router';
import PropTypes from 'prop-types';


Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/empty-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SearchIcon
} from '@patternfly/react-icons';

import { NavLink } from 'react-router-dom';
import { NavLink } from 'react-router';

export class EmptyObject extends React.Component {
static propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ibutsu-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import { Outlet } from 'react-router-dom';
import { Outlet } from 'react-router';

import {
Alert,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/profile-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PageSidebarBody
} from '@patternfly/react-core';

import { NavLink, Outlet} from 'react-router-dom';
import { NavLink, Outlet} from 'react-router';


import ElementWrapper from './elementWrapper';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Tab
} from '@patternfly/react-core';
import { FileAltIcon, FileImageIcon, InfoCircleIcon, CodeIcon, SearchIcon } from '@patternfly/react-icons';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import Linkify from 'react-linkify';
import { JSONTree } from 'react-json-tree';
import Editor from '@monaco-editor/react';
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';

import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import { IbutsuContext } from '../services/context';
import { PageSidebar,
PageSidebarBody,
Expand Down Expand Up @@ -58,21 +58,21 @@ const IbutsuSidebar = (props) => {
<Nav theme="dark" aria-label="Nav">
<NavList>
<li className="pf-v5-c-nav__item">
<Link to="dashboard" className="pf-v5-c-nav__link">Dashboard</Link>
<Link to="../dashboard" className="pf-v5-c-nav__link">Dashboard</Link>
</li>
<li className="pf-v5-c-nav__item">
<Link to="runs/" className="pf-v5-c-nav__link">Runs</Link>
<Link to="../runs/" className="pf-v5-c-nav__link">Runs</Link>
</li>
<li className="pf-v5-c-nav__item">
<Link to="results/" className="pf-v5-c-nav__link">Test Results</Link>
<Link to="../results/" className="pf-v5-c-nav__link">Test Results</Link>
</li>
<li className="pf-v5-c-nav__item">
<Link to="reports/" className="pf-v5-c-nav__link">Report Builder</Link>
<Link to="../reports/" className="pf-v5-c-nav__link">Report Builder</Link>
</li>
{views && views.map(view => (
view.widget !== 'jenkins-analysis-view' && (
<li className="pf-v5-c-nav__item" key={view.id}>
<Link to={`view/${view.id}`} className="pf-v5-c-nav__link">{view.title}</Link>
<Link to={`../view/${view.id}`} className="pf-v5-c-nav__link">{view.title}</Link>
</li>
)
))}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/test-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TableVariant,
expandable
} from '@patternfly/react-table';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { HttpClient } from '../services/http';
import { Settings } from '../settings';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/user-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MenuToggle
} from '@patternfly/react-core';
import { UserIcon } from '@patternfly/react-icons';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { AuthService } from '../services/auth';
import { IbutsuContext } from '../services/context';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/forgot-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
LoginPage,
TextInput
} from '@patternfly/react-core';
import { NavLink } from 'react-router-dom';
import { NavLink } from 'react-router';

import { AuthService } from './services/auth';

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TextInput
} from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon, GoogleIcon, FacebookIcon, GithubIcon, GitlabIcon, RedhatIcon, KeyIcon } from '@patternfly/react-icons';
import { NavLink } from 'react-router-dom';
import { NavLink } from 'react-router';
import { GoogleLogin } from '@react-oauth/google';
import OAuth2Login from 'react-simple-oauth2-login';
import FacebookLogin from '@greatsumini/react-facebook-login';
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/admin/project-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
TextInputGroupUtilities,
Title
} from '@patternfly/react-core';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { TimesIcon } from '@patternfly/react-icons';

Expand Down Expand Up @@ -464,7 +464,7 @@ export class ProjectEdit extends React.Component {
<Button
variant="secondary"
ouiaId="admin-project-edit-cancel"
component={(props: any) => <Link {...props} to="/admin/projects" />}
component={(props) => <Link {...props} to="/admin/projects" />}
>
Cancel
</Button>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/admin/project-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TextInput
} from '@patternfly/react-core';
import { PencilAltIcon, PlusCircleIcon, TrashIcon } from '@patternfly/react-icons';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { HttpClient } from '../../services/http';
import { Settings } from '../../settings';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/admin/user-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TextInput
} from '@patternfly/react-core';
import { PencilAltIcon, TrashIcon } from '@patternfly/react-icons';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { HttpClient } from '../../services/http';
import { Settings } from '../../settings';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/profile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';


import { Navigate, Route, Routes } from 'react-router-dom';
import { Navigate, Route, Routes } from 'react-router';
import EventEmitter from 'wolfy87-eventemitter';

import { UserProfile } from './pages/profile/user';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/reset-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TextInput
} from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';
import { NavLink } from 'react-router-dom';
import { NavLink } from 'react-router';

import { AuthService } from './services/auth';

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/run-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@patternfly/react-core';
import { ChevronRightIcon, TimesIcon } from '@patternfly/react-icons';

import { Link } from 'react-router-dom';
import { Link } from 'react-router';

import { HttpClient } from './services/http';
import { Settings } from './settings';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
TimesCircleIcon
} from '@patternfly/react-icons';

import { Link } from 'react-router-dom';
import { Link } from 'react-router';
import { JSONTree } from 'react-json-tree';
import Editor from '@monaco-editor/react';

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createContext, useState} from 'react';
import React, {createContext, useState} from 'react';
import PropTypes from 'prop-types';


Expand Down
Loading

0 comments on commit 5a231d8

Please sign in to comment.