DashboardScene: Map timezone and fiscal year to scene model and back (#75715)

* DashboardScene: Map timezone and fiscal year to scene model and back

* weekstart

* update scenes
This commit is contained in:
Torkel Ödegaard
2023-10-03 11:03:53 +02:00
committed by GitHub
parent a2088c0fb0
commit 9201c47e59
8 changed files with 30 additions and 14 deletions

View File

@ -251,7 +251,7 @@
"@grafana/lezer-traceql": "0.0.6",
"@grafana/monaco-logql": "^0.0.7",
"@grafana/runtime": "workspace:*",
"@grafana/scenes": "^1.5.1",
"@grafana/scenes": "^1.11.0",
"@grafana/schema": "workspace:*",
"@grafana/ui": "workspace:*",
"@kusto/monaco-kusto": "^7.4.0",

View File

@ -190,9 +190,10 @@ exports[`transformSceneToSaveModel Given a scene with rows Should transform back
"from": "now-6h",
"to": "now",
},
"timezone": "browser",
"timezone": "",
"title": "Repeating rows",
"uid": "Repeating-rows-uid",
"weekStart": "",
}
`;
@ -260,7 +261,7 @@ exports[`transformSceneToSaveModel Given a simple scene Should transform back to
],
},
"editable": true,
"fiscalYearStartMonth": 0,
"fiscalYearStartMonth": 1,
"graphTooltip": 0,
"links": [],
"panels": [
@ -366,8 +367,9 @@ exports[`transformSceneToSaveModel Given a simple scene Should transform back to
"from": "now-5m",
"to": "now",
},
"timezone": "browser",
"timezone": "America/New_York",
"title": "Dashboard to load1",
"uid": "nP8rcffGkasd",
"weekStart": "saturday",
}
`;

View File

@ -59,7 +59,7 @@
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"fiscalYearStartMonth": 1,
"graphTooltip": 0,
"id": 1351,
"links": [],
@ -204,5 +204,5 @@
"title": "Dashboard to load1",
"uid": "nP8rcffGkasd",
"version": 2,
"weekStart": ""
"weekStart": "saturday"
}

View File

@ -348,6 +348,5 @@
"timezone": "",
"title": "Repeating rows",
"uid": "Repeating-rows-uid",
"version": 1,
"weekStart": ""
"version": 1
}

View File

@ -42,6 +42,9 @@ describe('transformSaveModelToScene', () => {
title: 'test',
uid: 'test-uid',
time: { from: 'now-10h', to: 'now' },
weekStart: 'saturday',
fiscalYearStartMonth: 2,
timezone: 'America/New_York',
templating: {
list: [
{
@ -69,6 +72,9 @@ describe('transformSaveModelToScene', () => {
expect(scene.state.title).toBe('test');
expect(scene.state.uid).toBe('test-uid');
expect(scene.state?.$timeRange?.state.value.raw).toEqual(dash.time);
expect(scene.state?.$timeRange?.state.fiscalYearStartMonth).toEqual(2);
expect(scene.state?.$timeRange?.state.timeZone).toEqual('America/New_York');
expect(scene.state?.$timeRange?.state.weekStart).toEqual('saturday');
expect(scene.state?.$variables?.state.variables).toHaveLength(1);
expect(scene.state.controls).toBeDefined();
});

View File

@ -208,7 +208,13 @@ export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel)
isLazy: true,
children: createSceneObjectsForPanels(oldModel.panels),
}),
$timeRange: new SceneTimeRange(oldModel.time),
$timeRange: new SceneTimeRange({
from: oldModel.time.from,
to: oldModel.time.to,
fiscalYearStartMonth: oldModel.fiscalYearStartMonth,
timeZone: oldModel.timezone,
weekStart: oldModel.weekStart,
}),
$variables: variables,
$behaviors: [
new behaviors.CursorSync({

View File

@ -59,6 +59,9 @@ export function transformSceneToSaveModel(scene: DashboardScene): Dashboard {
annotations: {
list: annotations,
},
timezone: timeRange.timeZone,
fiscalYearStartMonth: timeRange.fiscalYearStartMonth,
weekStart: timeRange.weekStart,
};
return sortedDeepCloneWithoutNulls(dashboard);

View File

@ -4242,9 +4242,9 @@ __metadata:
languageName: unknown
linkType: soft
"@grafana/scenes@npm:^1.5.1":
version: 1.8.0
resolution: "@grafana/scenes@npm:1.8.0"
"@grafana/scenes@npm:^1.11.0":
version: 1.11.0
resolution: "@grafana/scenes@npm:1.11.0"
dependencies:
"@grafana/e2e-selectors": 10.0.2
react-grid-layout: 1.3.4
@ -4256,7 +4256,7 @@ __metadata:
"@grafana/runtime": 10.0.3
"@grafana/schema": 10.0.3
"@grafana/ui": 10.0.3
checksum: 7eef4391988b116b0c95923b9025cb509c08c5254058caacaf1e33cc3e6bc68458ec488132b8390ae8d781002a671ce03728670ce2e34968d2b0fa3e4cf8e7bd
checksum: fb7e21e11af29d861de2a47db25fc87fa6ffa4bc2c80784afcbf24d273f4aad1e21e7aa4cb176838cf5d869ae03b14822da235c9a398a2c41f816a93ef48c7e5
languageName: node
linkType: hard
@ -19989,7 +19989,7 @@ __metadata:
"@grafana/lezer-traceql": 0.0.6
"@grafana/monaco-logql": ^0.0.7
"@grafana/runtime": "workspace:*"
"@grafana/scenes": ^1.5.1
"@grafana/scenes": ^1.11.0
"@grafana/schema": "workspace:*"
"@grafana/tsconfig": ^1.3.0-rc1
"@grafana/ui": "workspace:*"