Skip to content

OU-192: replace react-router and react-router-dom with react-router-dom-compat-v5 #273

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 3 commits into from
Apr 22, 2025
Merged
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
87 changes: 31 additions & 56 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -65,8 +65,6 @@
"react": "17.0.2",
"react-dom": "17.0.2",
"react-helmet": "^6.1.0",
"react-router": "5.3.x",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include the compat package in our dependencies. Although it currently works since the @openshift-console/dynamic-plugin-sdk package requires it, it is better to be explicit with the packages we are using

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added react-router-dom-v5-compat in latest push.

"react-router-dom": "5.3.x",
"serve": "^14.2.3",
"style-loader": "^3.3.1",
"ts-jest": "^28.0.8",
@@ -108,7 +106,8 @@
"@patternfly/react-table": "^5.4.15",
"@patternfly/react-virtualized-extension": "^5.1.0",
"i18next": "^22.4.12",
"react-i18next": "^11.18.6"
"react-i18next": "^11.18.6",
"react-router-dom-v5-compat": "^6.30.0"
},
"nyc": {
"report-dir": "./coverage/cov-cypress"
2 changes: 1 addition & 1 deletion web/src/components/logs-table.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { ResourceLink, RowProps, TableColumn } from '@openshift-console/dynamic-
import { Split, SplitItem } from '@patternfly/react-core';
import { ISortBy, SortByDirection, Td, ThProps } from '@patternfly/react-table';
import React, { useCallback, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { Link } from 'react-router-dom-v5-compat';
import { DateFormat, dateToFormat } from '../date-utils';
import {
Direction,
44 changes: 25 additions & 19 deletions web/src/e2e-tests-app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import '@patternfly/patternfly/patternfly.css';
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Link, Route, useHistory, useParams } from 'react-router-dom';
import {
BrowserRouter,
Link,
Route,
Routes,
useNavigate,
useParams,
} from 'react-router-dom-v5-compat';
import LogsAlertMetrics from './components/alerts/logs-alerts-metrics';
import i18n from './i18n';
import './index.css';
@@ -19,15 +26,15 @@ import { TestIds } from './test-ids';

const DevConsole = () => {
const { ns: namespace } = useParams<{ ns: string }>();
const history = useHistory();
const navigate = useNavigate();
const [isOpen, setIsOpen] = React.useState(false);

const onToggle = () => {
setIsOpen(!isOpen);
};

const onSelectNamespace = (selectedNamespace: string) => () => {
history.push(`/dev-monitoring/ns/${selectedNamespace}/logs`);
navigate(`/dev-monitoring/ns/${selectedNamespace}/logs`);
setIsOpen(false);
};

@@ -119,23 +126,22 @@ const EndToEndTestsApp = () => {
</div>

<main className="pf-v5-c-page__main" tabIndex={-1}>
<Route path="/monitoring/logs">
<LogsPage />
</Route>
<Route path="/dev-monitoring/ns/:ns/logs">
<DevConsole />
</Route>
<Route path="/k8s/ns/:ns/pods/:name">
<LogsDetailPage />
</Route>
<Route path="/monitoring/alerts/:alertname">
<LogsAlertMetrics
rule={{
labels: { tenantId: 'application' },
query: `sum by(job)(rate({ job=~".+" }[5m])) > 0`,
}}
<Routes>
<Route path="/monitoring/logs" element={<LogsPage />} />
<Route path="/dev-monitoring/ns/:ns/logs" element={<DevConsole />} />
<Route path="/k8s/ns/:ns/pods/:name" element={<LogsDetailPage />} />
<Route
path="/monitoring/alerts/:alertname"
element={
<LogsAlertMetrics
rule={{
labels: { tenantId: 'application' },
query: `sum by(job)(rate({ job=~".+" }[5m])) > 0`,
}}
/>
}
/>
</Route>
</Routes>
</main>
</BrowserRouter>
</div>
2 changes: 1 addition & 1 deletion web/src/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router-dom-v5-compat';

export const useQueryParams = () => {
const location = useLocation();
Loading