|
1 |
| -import React from 'react' |
| 1 | +import React, { Suspense } from 'react' |
2 | 2 |
|
3 | 3 | import type { RouteMatch, RouteObject } from 'react-router'
|
4 | 4 | import { Navigate, Route, Routes } from 'react-router-dom'
|
5 | 5 |
|
| 6 | +// Needs to take import callback (as opposed to taking the path and passing it |
| 7 | +// to import()) because Rollup doesn't find the file properly otherwise. I tried |
| 8 | +// to follow the rules for dynamic import specified here but it didn't work: |
| 9 | +// |
| 10 | +// https://github.com/rollup/plugins/tree/02fb349d/packages/dynamic-import-vars#limitations |
| 11 | +// Rules imply () => import(`./{path}.tsx`) should work |
| 12 | +function lazyLoad(importFunc: () => Promise<{ default: React.ComponentType }>) { |
| 13 | + const Inner = React.lazy(importFunc) |
| 14 | + return () => ( |
| 15 | + // TODO: nicer fallback |
| 16 | + <Suspense fallback="loading"> |
| 17 | + <Inner /> |
| 18 | + </Suspense> |
| 19 | + ) |
| 20 | +} |
| 21 | + |
6 | 22 | import InstanceCreatePage from './pages/instances/create'
|
7 | 23 | import InstanceStorage from './pages/instances/Storage'
|
| 24 | +// Recharts is 350 KB |
| 25 | +const InstanceMetrics = lazyLoad(() => import('./pages/instances/Metrics')) |
8 | 26 | import OrgPage from './pages/OrgPage'
|
9 | 27 | import ProjectPage from './pages/project'
|
10 | 28 | import ProjectAccessPage from './pages/project/Access'
|
@@ -109,7 +127,11 @@ export const routes = (
|
109 | 127 | crumb={instanceCrumb}
|
110 | 128 | >
|
111 | 129 | <Route index />
|
112 |
| - <Route path="metrics" crumb="Metrics" /> |
| 130 | + <Route |
| 131 | + path="metrics" |
| 132 | + crumb="Metrics" |
| 133 | + element={<InstanceMetrics />} |
| 134 | + /> |
113 | 135 | <Route path="activity" crumb="Activity" />
|
114 | 136 | <Route path="access" crumb="Access" />
|
115 | 137 | <Route path="resize" crumb="Resize" />
|
|
0 commit comments