Skip to content

Commit 281b929

Browse files
feat: upgrading react-router
1 parent 9612642 commit 281b929

76 files changed

Lines changed: 223 additions & 364 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

__mocks__/textEncoderDecoder.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// See https://github.com/jsdom/jsdom/issues/2524
2+
3+
import { TextEncoder, TextDecoder } from 'util';
4+
5+
if (
6+
typeof global.TextEncoder !== 'undefined' ||
7+
typeof global.TextDecoder !== 'undefined'
8+
) {
9+
throw new Error(
10+
'Hello future me. Remove __mocks__/textEncoderDecoder.ts now please',
11+
);
12+
}
13+
14+
Object.assign(global, { TextDecoder, TextEncoder });

jest.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ const config: Config.InitialOptions = {
129129
// runner: "jest-runner",
130130

131131
// The paths to modules that run some code to configure or set up the testing environment before each test
132-
setupFiles: ['./__mocks__/serverFlags.js', 'jest-canvas-mock'],
132+
setupFiles: [
133+
'./__mocks__/textEncoderDecoder.ts',
134+
'./__mocks__/serverFlags.js',
135+
'jest-canvas-mock',
136+
],
133137

134138
// A list of paths to modules that run some code to configure or set up the testing framework before each test
135139
// setupFilesAfterEnv: [],
@@ -174,7 +178,7 @@ const config: Config.InitialOptions = {
174178

175179
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
176180
transformIgnorePatterns: [
177-
'<rootDir>/node_modules/(?!(@patternfly(-\\S+)?|d3(-\\S+)?|delaunator|robust-predicates|internmap|cheerio|lodash-es|@openshift-console|@novnc|@spice-project|@popperjs|i18next(-\\S+)?|@babel/runtime)/.*)',
181+
'<rootDir>/node_modules/(?!(@patternfly(-\\S+)?|d3(-\\S+)?|delaunator|robust-predicates|internmap|cheerio|lodash-es|@openshift-console|@novnc|@spice-project|@popperjs|i18next(-\\S+)?|@babel/runtime|react-router|cookie|set-cookie-parser)/.*)',
178182
],
179183

180184
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@
104104
"react-redux": "~9.2.0",
105105
"react-rnd": "^10.3.4",
106106
"react-router": "~7.13.1",
107-
"react-router-dom": "5.3.x",
108-
"react-router-dom-v5-compat": "^6.11.2",
109107
"react-transition-group": "2.3.x",
110108
"react-virtualized": "9.x",
111109
"resolve-url-loader": "5.0.0",

src/components/approval-tasks/ApprovalTasksList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../utils/pipeline-approval-utils';
1616
import { ApprovalStatus } from '../../types';
1717
import { useApprovalTasks, usePipelineRuns } from '../hooks/useTaskRuns';
18-
import { useParams } from 'react-router-dom-v5-compat';
18+
import { useParams } from 'react-router';
1919
import useApprovalsColumns from './useApprovalsColumns';
2020
import ApprovalRow from './ApprovalRow';
2121
import { ListPageFilter } from '../list-pages/ListPageFilter';

src/components/approval-tasks/modal/Approval.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useTranslation } from 'react-i18next';
22
import { Formik, FormikValues, FormikHelpers } from 'formik';
3-
import { Link } from 'react-router-dom-v5-compat';
3+
import { Link } from 'react-router';
44
import {
55
Modal,
66
ModalHeader,

src/components/approval-tasks/modal/__tests__/Approval.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jest.mock('react-i18next', () => ({
2828
}),
2929
}));
3030

31-
// Mock react-router-dom-v5-compat
32-
jest.mock('react-router-dom-v5-compat', () => ({
31+
// Mock react-router
32+
jest.mock('react-router', () => ({
3333
Link: ({ children, to }: { children: ReactNode; to: string }) => (
3434
<a href={to}>{children}</a>
3535
),

src/components/common/LinkTo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Link, LinkProps } from 'react-router-dom-v5-compat';
1+
import { Link, LinkProps } from 'react-router';
22

33
/**
44
* A helper which creates a `Link` component that **only**
55
* links to a specific location in the console.
66
*
77
* This is needed to bypass PatternFly `DropdownItem`
88
* forcing the `to` prop to pass as `href`, which breaks
9-
* `react-router-dom` routing and causes a hard reload.
9+
* `react-router` routing and causes a hard reload.
1010
*
1111
* @param href - The location to link to.
1212
* @param extraLinkProps - Any additional props to pass to the `Link` component.

src/components/details-page/breadcrumbs/BreadCrumbs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ReactElement, PropsWithChildren, FC } from 'react';
22
import { isValidElement, Fragment } from 'react';
3-
import { Link } from 'react-router-dom-v5-compat';
3+
import { Link } from 'react-router';
44
import { Breadcrumb, BreadcrumbItem } from '@patternfly/react-core';
55

66
type BreadCrumbsProps = {

src/components/details-page/label-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { FC } from 'react';
22
import { Component } from 'react';
33
import { withTranslation, WithTranslation } from 'react-i18next';
4-
import { Link } from 'react-router-dom-v5-compat';
4+
import { Link } from 'react-router';
55
import classNames from 'classnames';
66
import * as _ from 'lodash-es';
77
import {
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
import { createBrowserHistory, createMemoryHistory, History } from 'history';
3-
4-
let createHistory;
5-
6-
try {
7-
if (process.env.NODE_ENV === 'test') {
8-
// Running in node. Can't use browser history
9-
createHistory = createMemoryHistory;
10-
} else {
11-
createHistory = createBrowserHistory;
12-
}
13-
} catch (unused) {
14-
createHistory = createBrowserHistory;
15-
}
16-
17-
export const history: History = createHistory({
18-
basename: (window as any).SERVER_FLAGS.basePath,
19-
});
2+
export const history = {
3+
push: (url: string) => {
4+
window.history.pushState(window.history.state, '', url);
5+
},
6+
replace: (url: string) => {
7+
window.history.replaceState(window.history.state, '', url);
8+
},
9+
back: () => window.history.back(),
10+
};

0 commit comments

Comments
 (0)