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

Update to React Router 6 #3423

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions .storybook/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ limitations under the License.

import { StrictMode } from 'react';
import { IntlProvider } from 'react-intl';
import { createMemoryHistory } from 'history';
import { Router, Switch } from 'react-router-dom';
import { CompatRoute, CompatRouter } from 'react-router-dom-v5-compat';
import { Route, MemoryRouter as Router, Routes } from 'react-router-dom';

import messages from '../src/nls/messages_en.json';

Expand All @@ -31,16 +29,17 @@ export default function Container({
<IntlProvider locale="en" defaultLocale="en" messages={messages['en']}>
{notes && <p>{notes}</p>}
<div data-floating-menu-container role="main">
<Router history={createMemoryHistory({ initialEntries: [route] })}>
<CompatRouter>
<Switch>
<CompatRoute path={path}>
<Router initialEntries={[route]}>
<Routes>
<Route
path={path}
element={
<StrictMode>
<Story />
</StrictMode>
</CompatRoute>
</Switch>
</CompatRouter>
}
/>
</Routes>
</Router>
</div>
</IntlProvider>
Expand Down
148 changes: 21 additions & 127 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"react-dom": "^17.0.2",
"react-hot-loader": "^4.13.1",
"react-intl": "^6.6.6",
"react-router-dom": "^5.3.4",
"react-router-dom-v5-compat": "^6.23.0",
"react-router-dom": "^6.23.1",
"reconnecting-websocket": "^4.4.0"
},
"devDependencies": {
Expand Down Expand Up @@ -75,7 +74,6 @@
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.8.0",
"history": "^5.3.0",
"jsdom": "^24.0.0",
"lodash.difference": "^4.5.0",
"lodash.omit": "^4.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react": "^16.14.0 || ^17.0.1",
"react-dom": "^16.14.0 || ^17.0.1",
"react-intl": "^6.4.1",
"react-router-dom": "^5.0.0"
"react-router-dom": "^6.0.0"
},
"engines": {
"node": "^20.11.0",
Expand Down
32 changes: 29 additions & 3 deletions packages/components/src/components/Link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,34 @@ limitations under the License.
*/
/* istanbul ignore file */

import { forwardRef } from 'react';
import { useHref, useLinkClickHandler } from 'react-router-dom';
import { Link as CarbonLink } from 'carbon-components-react';

export default function Link({ navigate, ...rest }) {
return <CarbonLink {...rest} />;
}
const Link = forwardRef(
({ onClick, replace = false, state, target, to, ...rest }, ref) => {
const href = useHref(to);
const handleClick = useLinkClickHandler(to, {
replace,
state,
target
});

return (
<CarbonLink
{...rest}
href={href}
onClick={event => {
onClick?.(event);
if (!event.defaultPrevented) {
handleClick(event);
}
}}
ref={ref}
target={target}
/>
);
}
);

export default Link;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ limitations under the License.
*/

import { useIntl } from 'react-intl';
import { useLocation } from 'react-router-dom-v5-compat';
import { useLocation } from 'react-router-dom';

import ErrorBoundary from '../ErrorBoundary';

Expand Down
15 changes: 3 additions & 12 deletions packages/components/src/components/PipelineRuns/PipelineRuns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ limitations under the License.
*/

import { useIntl } from 'react-intl';
import { Link } from 'react-router-dom';
import { getStatus, urls } from '@tektoncd/dashboard-utils';
import {
Calendar16 as CalendarIcon,
Expand All @@ -22,9 +21,9 @@ import {
} from '@carbon/icons-react';

import Actions from '../Actions';
import CustomLink from '../Link';
import FormattedDate from '../FormattedDate';
import FormattedDuration from '../FormattedDuration';
import Link from '../Link';
import StatusIcon from '../StatusIcon';
import Table from '../Table';

Expand Down Expand Up @@ -196,11 +195,7 @@ const PipelineRuns = ({
<div>
<span>
{pipelineRunURL ? (
<Link
component={CustomLink}
to={pipelineRunURL}
title={pipelineRunNameTooltip}
>
<Link to={pipelineRunURL} title={pipelineRunNameTooltip}>
{pipelineRunName}
</Link>
) : (
Expand All @@ -220,11 +215,7 @@ const PipelineRuns = ({
<span>
{(pipelineRefName &&
(pipelineRunsByPipelineURL ? (
<Link
component={CustomLink}
to={pipelineRunsByPipelineURL}
title={pipelineRefName}
>
<Link to={pipelineRunsByPipelineURL} title={pipelineRefName}>
{pipelineRefName}
</Link>
) : (
Expand Down
Loading
Loading