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 #979

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/scenes-app/.config/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const config = (env): Configuration => ({
'react-redux',
'redux',
'rxjs',
'react-router-dom',
'react-router',
'd3',
'angular',
'@grafana/ui',
Expand Down
3 changes: 1 addition & 2 deletions packages/scenes-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@testing-library/react": "^12.1.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.30",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"copy-webpack-plugin": "^10.0.0",
Expand Down Expand Up @@ -70,7 +69,7 @@
"@types/lodash": "latest",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-router-dom": "^5.2.0"
"react-router-dom": "^6.28.0"
},
"lint-staged": {
"*.{js,ts,tsx}": [
Expand Down
4 changes: 2 additions & 2 deletions packages/scenes-app/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import { AppRootProps } from '@grafana/data';
import { PluginPropsContext } from '../../utils/utils.plugin';
import { Routes } from '../Routes';
import { AppRoutes } from '../Routes';

export class App extends React.PureComponent<AppRootProps> {
render() {
return (
<PluginPropsContext.Provider value={this.props}>
<Routes />
<AppRoutes />
</PluginPropsContext.Provider>
);
}
Expand Down
20 changes: 9 additions & 11 deletions packages/scenes-app/src/components/Routes/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import * as React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import { prefixRoute } from '../../utils/utils.routing';
import { Route, Routes } from 'react-router-dom';
import { ROUTES } from '../../constants';
import { DemoListPage } from '../../pages/DemoListPage';
import GrafanaMonitoringApp from '../../monitoring-app/GrafanaMonitoringApp';
import { ReactDemoPage } from '../../react-demo/Home';

export const Routes = () => {
export function AppRoutes() {
return (
<Switch>
{/* Default page */}
<Route path={prefixRoute(`${ROUTES.Demos}`)} component={DemoListPage} />
<Route path={prefixRoute(`${ROUTES.GrafanaMonitoring}`)} component={GrafanaMonitoringApp} />
<Route path={prefixRoute(`${ROUTES.ReactDemo}`)} component={ReactDemoPage} />
<Redirect to={prefixRoute(ROUTES.Demos)} />
</Switch>
<Routes>
<Route path={`${ROUTES.Demos}/*`} Component={DemoListPage} />
<Route path={`${ROUTES.GrafanaMonitoring}/*`} Component={GrafanaMonitoringApp} />
<Route path={`${ROUTES.ReactDemo}/*`} Component={ReactDemoPage} />
{/* <Redirect to={prefixRoute(ROUTES.Demos)} /> */}
Copy link
Member

Choose a reason for hiding this comment

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

Need to add a v6 redirect here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can just make DemoListPage a fallback page instead?

<Route path="*" Component={DemoListPage} />

</Routes>
);
};
}
4 changes: 4 additions & 0 deletions packages/scenes-app/src/demos/adhocFiltersDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function getAdhocFiltersDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Apply mode auto',
url: `${defaults.url}/auto`,
routePath: `auto`,
getScene: () => {
return new EmbeddedScene({
...getEmbeddedSceneDefaults(),
Expand Down Expand Up @@ -73,6 +74,7 @@ export function getAdhocFiltersDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Apply mode manual',
url: `${defaults.url}/manual`,
routePath: `manual`,
getScene: () => {
const filtersVar = new AdHocFiltersVariable({
applyMode: 'manual',
Expand Down Expand Up @@ -128,6 +130,7 @@ export function getAdhocFiltersDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Vertical Variants',
url: `${defaults.url}/vertical`,
routePath: `vertical`,
getScene: () => {
return new EmbeddedScene({
...getEmbeddedSceneDefaults(),
Expand Down Expand Up @@ -201,6 +204,7 @@ export function getAdhocFiltersDemo(defaults: SceneAppPageState) {
}),
new SceneAppPage({
title: 'New Filters UI',
routePath: `new-filters`,
url: `${defaults.url}/new-filters`,
getScene: () => {
return new EmbeddedScene({
Expand Down
1 change: 1 addition & 0 deletions packages/scenes-app/src/demos/cursorSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function scoped() {
return new SceneAppPage({
title: 'Cursor sync test',
url: demoUrl('cursor-sync/scoped'),
routePath: 'scoped',
getScene: () => {
return new EmbeddedScene({
...getEmbeddedSceneDefaults(),
Expand Down
1 change: 1 addition & 0 deletions packages/scenes-app/src/demos/docs-examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function getDocsExamples(defaults: SceneAppPageState) {
function getDocsExample(getScene: () => EmbeddedScene, url: string, title: string) {
return new SceneAppPage({
title,
routePath: url,
url: demoUrl(`docs-examples/${url}`),
getScene,
});
Expand Down
1 change: 1 addition & 0 deletions packages/scenes-app/src/demos/dynamicPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function getDynamicPageDemo(defaults: SceneAppPageState): SceneAppPage {
function getSceneAppPage(url: string, name: string) {
return new SceneAppPage({
title: name,
routePath: url,
url: `${demoUrl('dynamic-page')}${url}`,
getScene: () => {
return new EmbeddedScene({
Expand Down
1 change: 1 addition & 0 deletions packages/scenes-app/src/demos/split.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const dynamicSplitDemo = () =>
new SceneAppPage({
title: 'Dynamic split layout test',
url: demoUrl('split-layout/dynamic'),
routePath: 'dynamic',
getScene: getDynamicSplitScene,
});

Expand Down
2 changes: 2 additions & 0 deletions packages/scenes-app/src/demos/urlSyncTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getUrlSyncTest(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'First',
url: `${defaults.url}/first`,
routePath: 'first',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand All @@ -57,6 +58,7 @@ export function getUrlSyncTest(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Second',
url: `${defaults.url}/manual`,
routePath: 'manual',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down
5 changes: 5 additions & 0 deletions packages/scenes-app/src/demos/variables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getVariablesDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Async and chained',
url: `${defaults.url}/query`,
routePath: 'query',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down Expand Up @@ -116,6 +117,7 @@ export function getVariablesDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Data source and textbox',
url: `${defaults.url}/ds`,
routePath: 'ds',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down Expand Up @@ -158,6 +160,7 @@ export function getVariablesDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Search filter',
url: `${defaults.url}/search`,
routePath: 'search',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down Expand Up @@ -191,6 +194,7 @@ export function getVariablesDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Many variable options',
url: `${defaults.url}/many-values`,
routePath: 'many-values',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down Expand Up @@ -224,6 +228,7 @@ export function getVariablesDemo(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Many adhoc variable values',
url: `${defaults.url}/many-adhoc-values`,
routePath: 'many-adhoc-values',
getScene: () => {
return new EmbeddedScene({
controls: [new VariableValueSelectors({})],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function getDrilldownsAppPageScene(defaults: SceneAppPageState) {
getScene,
drilldowns: [
{
routePath: `${defaults.url}/room/:roomName`,
routePath: `room/:roomName/*`,
getPage(routeMatch, parent) {
const roomName = routeMatch.params.roomName;

Expand All @@ -66,13 +66,15 @@ export function getDrilldownsAppPageScene(defaults: SceneAppPageState) {
new SceneAppPage({
title: 'Temperature',
titleIcon: 'dashboard',
routePath: 'temperature',
tabSuffix: () => <Counter value={1} />,
url: `${defaults.url}/room/${roomName}/temperature`,
getScene: () => getRoomDrilldownScene(roomName),
}),
new SceneAppPage({
title: 'Humidity',
titleIcon: 'chart-line',
routePath: 'humidity',
url: `${defaults.url}/room/${roomName}/humidity`,
getScene: () => getHumidityOverviewScene(roomName),
}),
Expand Down
8 changes: 5 additions & 3 deletions packages/scenes-app/src/pages/DemoListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function getDemoSceneApp() {
new SceneAppPage({
title: 'Demos',
key: 'SceneAppPage Demos',
url: prefixRoute(ROUTES.Demos),
url: `${prefixRoute(ROUTES.Demos)}`,
routePath: '*',
preserveUrlKeys: [],
getScene: () => {
return new EmbeddedScene({
Expand All @@ -42,7 +43,7 @@ function getDemoSceneApp() {
},
drilldowns: [
{
routePath: `${demoUrl(':demo')}`,
routePath: `:demo/*`,
getPage: (routeMatch, parent) => {
const demos = getDemos();
const demoSlug = decodeURIComponent(routeMatch.params.demo);
Expand All @@ -54,7 +55,8 @@ function getDemoSceneApp() {

return demoInfo.getPage({
title: demoInfo.title,
url: `${demoUrl(slugify(demoInfo.title))}`,
url: `${prefixRoute(ROUTES.Demos)}/${demoSlug}`,
routePath: `${slugify(demoInfo.title)}/*`,
getParentPage: () => parent,
});
},
Expand Down
10 changes: 5 additions & 5 deletions packages/scenes-app/src/react-demo/DrilldownDemoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { DATASOURCE_REF } from '../constants';
import { PageWrapper } from './PageWrapper';
import { DemoVizLayout, urlBase } from './utils';
import { Route, Switch, useParams } from 'react-router-dom';
import { Route, Routes, useParams } from 'react-router-dom';
import { PlainGraphWithRandomWalk } from './PlainGraphWithRandomWalk';

export function DrilldownDemoPage() {
Expand All @@ -15,10 +15,10 @@ export function DrilldownDemoPage() {
return (
<BreadcrumbProvider>
<Breadcrumb text="Drilldown demo" path={`${urlBase}/drilldown`} />
<Switch>
<Route path={`${urlBase}/drilldown`} component={DrilldownHome} exact />
<Route path={`${urlBase}/drilldown/lib/:lib`} component={DrilldownLibraryPage} />
</Switch>
<Routes>
<Route path="*" element={<DrilldownHome />} />
<Route path="lib/:lib" element={<DrilldownLibraryPage />} />
</Routes>
</BreadcrumbProvider>
);
}
Expand Down
30 changes: 15 additions & 15 deletions packages/scenes-app/src/react-demo/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SceneContextProvider, CustomVariable } from '@grafana/scenes-react';
import { Stack, TextLink } from '@grafana/ui';
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { Route, Routes } from 'react-router-dom';
import { PlainGraphWithRandomWalk } from './PlainGraphWithRandomWalk';
import { PageWrapper } from './PageWrapper';
import { DynamicQueriesPage } from './DynamicQueriesPage';
Expand All @@ -21,20 +21,20 @@ export function ReactDemoPage() {
return (
<SceneContextProvider timeRange={{ from: 'now-1h', to: 'now' }} withQueryController>
<CustomVariable name="env" query="dev, test, prod" initialValue="dev">
<Switch>
<Route path={`${urlBase}`} component={HomePage} exact />
<Route path={`${urlBase}/repeat-by-variable`} component={RepeatByVariablePage} />
<Route path={`${urlBase}/repeat-by-series`} component={RepeatBySeriesPage} />
<Route path={`${urlBase}/dynamic-queries`} component={DynamicQueriesPage} />
<Route path={`${urlBase}/dynamic-viz`} component={DynamicVisualiationPage} />
<Route path={`${urlBase}/dynamic-vars`} component={DynamicVariablesPage} />
<Route path={`${urlBase}/nested-context`} component={NestedContextsPage} />
<Route path={`${urlBase}/interpolation-hook`} component={InterpolationHookPage} />
<Route path={`${urlBase}/query-var-hook`} component={UseQueryVariableHookPage} />
<Route path={`${urlBase}/drilldown`} component={DrilldownDemoPage} />
<Route path={`${urlBase}/annotations`} component={AnnotationDemoPage} />
<Route path={`${urlBase}/transformations`} component={TransformationsDemoPage} />
</Switch>
<Routes>
<Route path="" Component={HomePage} />
<Route path={`/repeat-by-variable`} Component={RepeatByVariablePage} />
<Route path={`/repeat-by-series`} Component={RepeatBySeriesPage} />
<Route path={`/dynamic-queries`} Component={DynamicQueriesPage} />
<Route path={`/dynamic-viz`} Component={DynamicVisualiationPage} />
<Route path={`/dynamic-vars`} Component={DynamicVariablesPage} />
<Route path={`/nested-context`} Component={NestedContextsPage} />
<Route path={`/interpolation-hook`} Component={InterpolationHookPage} />
<Route path={`/query-var-hook`} Component={UseQueryVariableHookPage} />
<Route path={`/drilldown/*`} Component={DrilldownDemoPage} />
<Route path={`/annotations`} Component={AnnotationDemoPage} />
<Route path={`/transformations`} Component={TransformationsDemoPage} />
</Routes>
</CustomVariable>
</SceneContextProvider>
);
Expand Down
5 changes: 2 additions & 3 deletions packages/scenes-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"@grafana/schema": "^11.0.0",
"@grafana/ui": "^11.0.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react-dom": "^18.0.0",
"react-router-dom": "^6.28.0"
},
"devDependencies": {
"@emotion/css": "11.10.5",
Expand All @@ -71,7 +72,6 @@
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"@types/react-grid-layout": "1.3.2",
"@types/react-router-dom": "5.3.3",
"@types/react-virtualized-auto-sizer": "1.0.1",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -89,7 +89,6 @@
"jest-matcher-utils": "29.7.0",
"lodash": "4.17.21",
"prettier": "2.5.1",
"react-router-dom": "^5.2.0",
"react-select-event": "^5.5.1",
"rimraf": "^3.0.2",
"rollup": "2.79.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ interface SetupProps extends Partial<SceneContextProviderProps> {}

function setup(props: SetupProps) {
const result: SetupResult = {} as SetupResult;
const history = locationService.getHistory();

result.renderResult = render(
<LocationServiceProvider service={locationService}>
<Router history={locationService.getHistory()}>
<Router navigator={history} location={history.location}>
<SceneContextProvider {...props}>
<ChildTest setCtx={(c) => (result.context = c)}></ChildTest>
<SceneContextProvider>
Expand Down
3 changes: 2 additions & 1 deletion packages/scenes/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
'\\.css$': '<rootDir>/utils/test/__mocks__/style.ts',
},
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./utils/setupTests.ts'],
setupFiles: ['./utils/setupTests.ts'],
setupFilesAfterEnv: ['./utils/setupTestsAfterEnv.ts'],
testMatch: ['<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}'],
transform: {
'^.+\\.(t|j)sx?$': [
Expand Down
9 changes: 4 additions & 5 deletions packages/scenes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
"@floating-ui/react": "^0.26.16",
"@leeoniya/ufuzzy": "^1.0.16",
"@tanstack/react-virtual": "^3.9.0",
"react-grid-layout": "^1.3.4",
"react-use": "^17.5.0",
"react-virtualized-auto-sizer": "^1.0.24",
"react-grid-layout": "1.3.4",
"react-router-dom": "^6.28.0",
"react-use": "17.5.0",
"react-virtualized-auto-sizer": "1.0.24",
"uuid": "^9.0.0"
},
"peerDependencies": {
Expand Down Expand Up @@ -73,7 +74,6 @@
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"@types/react-grid-layout": "1.3.2",
"@types/react-router-dom": "5.3.3",
"@types/react-virtualized-auto-sizer": "1.0.1",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -91,7 +91,6 @@
"jest-matcher-utils": "29.7.0",
"lodash": "4.17.21",
"prettier": "2.5.1",
"react-router-dom": "^5.2.0",
"react-select-event": "^5.5.1",
"rimraf": "^3.0.2",
"rollup": "2.79.1",
Expand Down
Loading
Loading