Skip to content

Commit a13d9e2

Browse files
leventebaloghgtk-grafanatskarhedL2D2Grafana
authored
Scenes: Updating to v6 (#1019)
* chore: (scenes6) - update to [email protected] --------- Co-authored-by: Galen <[email protected]> Co-authored-by: Galen Kistler <[email protected]> Co-authored-by: Tobias Skarhed <[email protected]> Co-authored-by: L2D2Grafana <[email protected]>
1 parent fad9538 commit a13d9e2

12 files changed

+232
-246
lines changed

.config/webpack/webpack.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const config = async (env): Promise<Configuration> => {
6868
'redux',
6969
'rxjs',
7070
'react-router',
71-
'react-router-dom',
7271
'd3',
7372
'angular',
7473
/^@grafana\/ui/i,

.cprc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"features": {
33
"bundleGrafanaUI": false,
4-
"useReactRouterV6": false
4+
"useReactRouterV6": true
55
}
66
}

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"@types/jest": "^29.5.0",
6666
"@types/lodash": "^4.14.194",
6767
"@types/node": "^20.8.7",
68-
"@types/react-router-dom": "^5.2.0",
6968
"@types/react-scroll-sync": "^0.9.0",
7069
"@types/react-table": "^7.7.20",
7170
"@types/testing-library__jest-dom": "5.14.8",
@@ -120,7 +119,7 @@
120119
"@grafana/data": "^11.6.0",
121120
"@grafana/lezer-logql": "^0.2.7",
122121
"@grafana/runtime": "^11.6.0",
123-
"@grafana/scenes": "5.41.1",
122+
"@grafana/scenes": "^6.9.0",
124123
"@grafana/ui": "^11.6.0",
125124
"@hello-pangea/dnd": "^16.6.0",
126125
"@lezer/common": "^1.2.1",
@@ -129,13 +128,13 @@
129128
"re2js": "^1.1.0",
130129
"react": "18.2.0",
131130
"react-dom": "18.2.0",
132-
"react-router-dom": "^5.2.0",
131+
"react-router-dom": "^6.22.0",
133132
"rxjs": "7.8.1",
134133
"tslib": "2.5.3",
135134
"uuid": "^10.0.0"
136135
},
137136
"resolutions": {
138-
"**/fast-loops": "^1.1.4"
137+
"react-router-dom": "^6.22.0"
139138
},
140139
"packageManager": "[email protected]"
141140
}

playwright.config.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PluginOptions } from '@grafana/plugin-e2e';
22
import { defineConfig, devices } from '@playwright/test';
33
import { dirname } from 'node:path';
4-
import {E2ESubPath} from "./tests/fixtures/explore";
4+
import { E2ESubPath } from './tests/fixtures/explore';
55

66
const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;
77

@@ -31,14 +31,12 @@ export default defineConfig<PluginOptions>({
3131
/* Base URL to use in actions like `await page.goto('/')`. */
3232
baseURL: `http://localhost:3001${E2ESubPath}`,
3333

34-
3534
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3635
trace: 'on-first-retry',
37-
3836
// Turn on when debugging local tests
3937
// video: {
4038
// mode: 'on',
41-
// }
39+
// },
4240
},
4341
expect: { timeout: 15000 },
4442

src/Components/LogExplorationPage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React, { useEffect } from 'react';
22

33
import { SceneApp, useSceneApp } from '@grafana/scenes';
44
import { config } from '@grafana/runtime';
5-
import { Redirect } from 'react-router-dom';
5+
import { Navigate } from 'react-router-dom';
66
import { makeIndexPage, makeRedirectPage } from './Pages';
77
import { initializeMetadataService } from '../services/metadata';
88

99
const getSceneApp = () =>
1010
new SceneApp({
1111
pages: [makeIndexPage(), makeRedirectPage()],
1212
urlSyncOptions: {
13-
createBrowserHistorySteps: false,
13+
createBrowserHistorySteps: true,
1414
updateUrlOnInit: true,
1515
},
1616
});
@@ -31,7 +31,7 @@ function LogExplorationView() {
3131
const userPermissions = config.bootData.user.permissions;
3232
const canUseApp = userPermissions?.['grafana-lokiexplore-app:read'] || userPermissions?.['datasources:explore'];
3333
if (!canUseApp) {
34-
return <Redirect to="/" />;
34+
return <Navigate to="/" replace />;
3535
}
3636

3737
if (!isInitialized) {

src/Components/Pages.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function makeIndexPage() {
5050
url: prefixRoute(PageSlugs.explore),
5151
layout: PageLayoutType.Custom,
5252
preserveUrlKeys: SERVICE_URL_KEYS,
53-
routePath: prefixRoute(PageSlugs.explore),
53+
routePath: `${PageSlugs.explore}/*`,
5454
getScene: (routeMatch) => getServicesScene(routeMatch),
5555
drilldowns: [
5656
{
@@ -122,6 +122,7 @@ export function makeBreakdownPage(
122122
title: capitalizeFirstLetter(slug),
123123
layout: PageLayoutType.Custom,
124124
url: ROUTES[slug](labelValue, labelName),
125+
routePath: ROUTE_DEFINITIONS[slug],
125126
preserveUrlKeys: DRILLDOWN_URL_KEYS,
126127
getParentPage: () => parent,
127128
getScene: (routeMatch) => getServicesScene(routeMatch),
@@ -150,6 +151,7 @@ export function makeBreakdownValuePage(
150151
title: capitalizeFirstLetter(breakdownLabel),
151152
layout: PageLayoutType.Custom,
152153
url: SUB_ROUTES[slug](labelValue, labelName, breakdownLabel),
154+
routePath: CHILD_ROUTE_DEFINITIONS[slug],
153155
preserveUrlKeys: DRILLDOWN_URL_KEYS,
154156
getParentPage: () => parent,
155157
getScene: (routeMatch) => getServicesScene(routeMatch),

src/Components/ServiceScene/LogsPanelScene.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export class LogsPanelScene extends SceneObjectBase<LogsPanelSceneState> {
307307
.setOption('enableInfiniteScrolling', true)
308308
.setOption('onNewLogsReceived', this.updateVisibleRange)
309309
.setOption('logRowMenuIconsAfter', [<CopyLinkButton onClick={this.handleShareLogLineClick} key={0} />])
310-
311310
.setHeaderActions(
312311
new LogOptionsScene({ visualizationType, onChangeVisualizationType: parentModel.setVisualizationType })
313312
)

src/services/CustomConstantVariable.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Observable, of } from 'rxjs';
22
import {
33
MultiValueVariable,
44
MultiValueVariableState,
5-
renderSelectForVariable,
5+
MultiOrSingleValueSelect,
66
SceneComponentProps,
77
VariableGetOptionsArgs,
88
VariableValueOption,
@@ -29,8 +29,7 @@ export class CustomConstantVariable extends MultiValueVariable<CustomConstantVar
2929
public getValueOptions(args: VariableGetOptionsArgs): Observable<VariableValueOption[]> {
3030
return of(this.state.options);
3131
}
32-
3332
public static Component = ({ model }: SceneComponentProps<MultiValueVariable>) => {
34-
return renderSelectForVariable(model);
33+
return MultiOrSingleValueSelect({ model });
3534
};
3635
}

src/services/LogsSceneQueryRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export class LogsSceneQueryRunner extends SceneQueryRunner {
1313

1414
// @todo can we make runWithTimeRange protected? (https://github.com/grafana/scenes/pull/866)
1515
// Hack to call private method
16-
this['runWithTimeRange'](timeRange);
16+
this['runWithTimeRangeAndScopes'](timeRange);
1717
}
1818
}

src/services/logqlMatchers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function parseLabelFilters(query: string, filter: IndexedLabelFilter[]) {
108108
if (!identifierPosition || identifierPosition.length === 0) {
109109
continue;
110110
}
111-
111+
112112
const valuePosition = getAllPositionsInNodeByType(matcher, String);
113113
const operator = query.substring(identifierPosition[0].to, valuePosition[0].from);
114114
const key = identifierPosition[0].getExpression(query);

src/services/routing.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ export const SUB_ROUTES = {
6565
};
6666

6767
export const ROUTE_DEFINITIONS: Record<keyof typeof PageSlugs, string> = {
68-
explore: prefixRoute(PageSlugs.explore),
69-
logs: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${PageSlugs.logs}`),
70-
fields: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${PageSlugs.fields}`),
71-
patterns: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${PageSlugs.patterns}`),
72-
labels: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${PageSlugs.labels}`),
68+
explore: `${PageSlugs.explore}/*`,
69+
logs: `:labelName/:labelValue/${PageSlugs.logs}`,
70+
fields: `:labelName/:labelValue/${PageSlugs.fields}`,
71+
patterns: `:labelName/:labelValue/${PageSlugs.patterns}`,
72+
labels: `:labelName/:labelValue/${PageSlugs.labels}`,
7373
};
7474

7575
export const CHILD_ROUTE_DEFINITIONS: Record<keyof typeof ValueSlugs, string> = {
76-
field: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${ValueSlugs.field}/:breakdownLabel`),
77-
label: prefixRoute(`${PageSlugs.explore}/:labelName/:labelValue/${ValueSlugs.label}/:breakdownLabel`),
76+
field: `:labelName/:labelValue/${ValueSlugs.field}/:breakdownLabel`,
77+
label: `:labelName/:labelValue/${ValueSlugs.label}/:breakdownLabel`,
7878
};
7979

8080
export const EXPLORATIONS_ROUTE = `${PLUGIN_BASE_URL}/${PageSlugs.explore}`;

0 commit comments

Comments
 (0)