Skip to content

Commit 459a3dd

Browse files
authored
feat: prepare for react-router 6, lazy load routes (#980)
1 parent 191ac71 commit 459a3dd

File tree

22 files changed

+48
-48
lines changed

22 files changed

+48
-48
lines changed

src/containers/App/Content.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@ import {getUser} from '../../store/reducers/authentication/authentication';
1313
import {nodesListApi} from '../../store/reducers/nodesList';
1414
import {cn} from '../../utils/cn';
1515
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
16+
import {lazyComponent} from '../../utils/lazyComponent';
1617
import Authentication from '../Authentication/Authentication';
17-
import Cluster from '../Cluster/Cluster';
1818
import {getClusterPath} from '../Cluster/utils';
19-
import {Clusters} from '../Clusters/Clusters';
2019
import Header from '../Header/Header';
2120
import type {RawBreadcrumbItem} from '../Header/breadcrumbs';
22-
import Node from '../Node/Node';
23-
import {PDiskPage} from '../PDiskPage/PDiskPage';
24-
import {Tablet} from '../Tablet';
25-
import {TabletsFilters} from '../TabletsFilters/TabletsFilters';
26-
import Tenant from '../Tenant/Tenant';
27-
import {VDiskPage} from '../VDiskPage/VDiskPage';
2821

2922
import {
3023
ClusterSlot,
@@ -54,40 +47,45 @@ const routesSlots: RouteSlot[] = [
5447
{
5548
path: routes.cluster,
5649
slot: ClusterSlot,
57-
component: Cluster,
50+
component: lazyComponent(() => import('../Cluster/Cluster'), 'Cluster'),
5851
},
5952
{
6053
path: routes.tenant,
6154
slot: TenantSlot,
62-
component: Tenant,
55+
component: lazyComponent(() => import('../Tenant/Tenant'), 'Tenant'),
6356
},
6457
{
6558
path: routes.node,
6659
slot: NodeSlot,
67-
component: Node,
60+
component: lazyComponent(() => import('../Node/Node'), 'Node'),
6861
},
6962
{
7063
path: routes.pDisk,
7164
slot: PDiskPageSlot,
72-
component: PDiskPage,
65+
component: lazyComponent(() => import('../PDiskPage/PDiskPage'), 'PDiskPage'),
7366
},
7467
{
7568
path: routes.vDisk,
7669
slot: VDiskPageSlot,
77-
component: VDiskPage,
70+
component: lazyComponent(() => import('../VDiskPage/VDiskPage'), 'VDiskPage'),
7871
},
7972
{
8073
path: routes.tablet,
8174
slot: TabletSlot,
82-
component: Tablet,
75+
component: lazyComponent(() => import('../Tablet'), 'Tablet'),
8376
},
8477
{
8578
path: routes.tabletsFilters,
8679
slot: TabletsFiltersSlot,
87-
component: TabletsFilters,
80+
component: lazyComponent(
81+
() => import('../TabletsFilters/TabletsFilters'),
82+
'TabletsFilters',
83+
),
8884
},
8985
];
9086

87+
const Clusters = lazyComponent(() => import('../Clusters/Clusters'), 'Clusters');
88+
9189
function renderRouteSlot(slots: SlotMap, route: RouteSlot) {
9290
return (
9391
<Route
@@ -151,7 +149,12 @@ export function Content(props: ContentProps) {
151149
{routesSlots.map((route) => {
152150
return renderRouteSlot(slots, route);
153151
})}
154-
<Redirect {...redirectProps} />
152+
<Route
153+
path={redirectProps.from || redirectProps.path}
154+
exact={redirectProps.exact}
155+
strict={redirectProps.strict}
156+
render={() => <Redirect to={redirectProps.to} push={redirectProps.push} />}
157+
/>
155158
</Switch>
156159
</Route>
157160
</Switch>

src/containers/App/Providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {Store} from '@reduxjs/toolkit';
55
import type {History} from 'history';
66
import {HelmetProvider} from 'react-helmet-async';
77
import {Provider} from 'react-redux';
8-
import {Router} from 'react-router';
8+
import {Router} from 'react-router-dom';
99
import {QueryParamProvider} from 'use-query-params';
1010
import {ReactRouter5Adapter} from 'use-query-params/adapters/react-router-5';
1111

src/containers/App/appSlots.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type {RedirectProps, RouteComponentProps} from 'react-router';
1+
import type {RedirectProps, RouteComponentProps} from 'react-router-dom';
22

33
import {createSlot} from '../../components/slots';
4-
import type Cluster from '../Cluster/Cluster';
4+
import type {Cluster} from '../Cluster/Cluster';
55
import type {Clusters} from '../Clusters/Clusters';
6-
import type Node from '../Node/Node';
6+
import type {Node} from '../Node/Node';
77
import type {PDiskPage} from '../PDiskPage/PDiskPage';
88
import type {Tablet} from '../Tablet';
99
import type {TabletsFilters} from '../TabletsFilters/TabletsFilters';
10-
import type Tenant from '../Tenant/Tenant';
10+
import type {Tenant} from '../Tenant/Tenant';
1111
import type {VDiskPage} from '../VDiskPage/VDiskPage';
1212

1313
export const ClustersSlot = createSlot<{

src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {cn} from '../../../utils/cn';
1313
import type {GetMonitoringClusterLink, GetMonitoringLink} from '../../../utils/monitoring';
1414
import {getCleanBalancerValue, removeViewerPathname} from '../../../utils/parseBalancer';
1515
import {getBackendFromNodeHost} from '../../../utils/prepareBackend';
16-
import type Cluster from '../../Cluster/Cluster';
16+
import type {Cluster} from '../../Cluster/Cluster';
1717
import {useClusterData} from '../useClusterData';
1818

1919
import './ExtendedCluster.scss';

src/containers/AppWithClusters/ExtendedNode/ExtendedNode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type Node from '../../Node/Node';
1+
import type {Node} from '../../Node/Node';
22
import {useClusterData} from '../useClusterData';
33

44
export function ExtendedNode({component: NodeComponent}: {component: typeof Node}) {

src/containers/AppWithClusters/ExtendedTenant/ExtendedTenant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {MonitoringButton} from '../../../components/MonitoringButton/MonitoringButton';
22
import type {ETenantType} from '../../../types/api/tenant';
33
import type {GetMonitoringLink} from '../../../utils/monitoring';
4-
import type Tenant from '../../Tenant/Tenant';
4+
import type {Tenant} from '../../Tenant/Tenant';
55
import {useClusterData} from '../useClusterData';
66

77
export interface ExtendedTenantProps {

src/containers/AppWithClusters/useClusterData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import {useLocation} from 'react-router';
3+
import {useLocation} from 'react-router-dom';
44

55
import {parseQuery} from '../../routes';
66
import {clustersApi} from '../../store/reducers/clusters/clusters';

src/containers/AsideNavigation/YdbInternalUser/YdbInternalUser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ArrowRightFromSquare, ArrowRightToSquare} from '@gravity-ui/icons';
22
import {Button, Icon} from '@gravity-ui/uikit';
3-
import {useHistory} from 'react-router';
3+
import {useHistory} from 'react-router-dom';
44

55
import routes, {createHref} from '../../../routes';
66
import {logout} from '../../../store/reducers/authentication/authentication';

src/containers/Authentication/Authentication.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import {Eye, EyeSlash, Xmark} from '@gravity-ui/icons';
44
import {Button, Link as ExternalLink, Icon, TextInput} from '@gravity-ui/uikit';
5-
import {useHistory, useLocation} from 'react-router';
5+
import {useHistory, useLocation} from 'react-router-dom';
66

77
import {parseQuery} from '../../routes';
88
import {authenticate} from '../../store/reducers/authentication/authentication';

src/containers/Cluster/Cluster.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface ClusterProps {
4141
additionalVersionsProps?: AdditionalVersionsProps;
4242
}
4343

44-
function Cluster({
44+
export function Cluster({
4545
additionalClusterProps,
4646
additionalTenantsProps,
4747
additionalNodesProps,
@@ -198,7 +198,11 @@ function Cluster({
198198
>
199199
<Versions versionToColor={versionToColor} />
200200
</Route>
201-
<Redirect to={getLocationObjectFromHref(getClusterPath(activeTabId))} />
201+
<Route
202+
render={() => (
203+
<Redirect to={getLocationObjectFromHref(getClusterPath(activeTabId))} />
204+
)}
205+
/>
202206
</Switch>
203207
</div>
204208
</div>
@@ -228,5 +232,3 @@ function useClusterTab() {
228232

229233
return activeTab;
230234
}
231-
232-
export default Cluster;

0 commit comments

Comments
 (0)