mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scenes: improve createVizPanelFromPanelModel helper (#64918)
This commit is contained in:
@@ -53,6 +53,7 @@ function DashboardSceneRenderer({ model }: SceneComponentProps<DashboardScene>)
|
||||
|
||||
const toolbarActions = (actions ?? []).map((action) => <action.Component key={action.state.key} model={action} />);
|
||||
|
||||
if (uid?.length) {
|
||||
toolbarActions.push(
|
||||
<ToolbarButton
|
||||
icon="apps"
|
||||
@@ -61,6 +62,7 @@ function DashboardSceneRenderer({ model }: SceneComponentProps<DashboardScene>)
|
||||
key="scene-to-dashboard-switch"
|
||||
/>
|
||||
);
|
||||
}
|
||||
const pageToolbar = config.featureToggles.topnav ? (
|
||||
<AppChromeUpdate actions={toolbarActions} />
|
||||
) : (
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { StateManagerBase } from 'app/core/services/StateManagerBase';
|
||||
import { dashboardLoaderSrv } from 'app/features/dashboard/services/DashboardLoaderSrv';
|
||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
||||
import { graphToTimeseriesOptions } from 'app/plugins/panel/timeseries/migrations';
|
||||
import { DashboardDTO } from 'app/types';
|
||||
|
||||
import { DashboardScene } from './DashboardScene';
|
||||
@@ -156,7 +157,7 @@ export function createSceneObjectsForPanels(oldPanels: PanelModel[]): SceneObjec
|
||||
export function createDashboardSceneFromDashboardModel(oldModel: DashboardModel) {
|
||||
let variables: SceneVariableSet | undefined = undefined;
|
||||
|
||||
if (oldModel.templating.list.length) {
|
||||
if (oldModel.templating?.list?.length) {
|
||||
const variableObjects = oldModel.templating.list
|
||||
.map((v) => {
|
||||
try {
|
||||
@@ -256,6 +257,19 @@ export function createSceneVariableFromVariableModel(variable: VariableModel): S
|
||||
}
|
||||
|
||||
export function createVizPanelFromPanelModel(panel: PanelModel) {
|
||||
const queryRunner = new SceneQueryRunner({
|
||||
queries: panel.targets,
|
||||
maxDataPoints: panel.maxDataPoints ?? undefined,
|
||||
});
|
||||
|
||||
// Migrate graph to timeseries
|
||||
if (panel.type === 'graph') {
|
||||
const { fieldConfig, options } = graphToTimeseriesOptions(panel);
|
||||
panel.fieldConfig = fieldConfig;
|
||||
panel.options = options;
|
||||
panel.type = 'timeseries';
|
||||
}
|
||||
|
||||
return new VizPanel({
|
||||
title: panel.title,
|
||||
pluginId: panel.type,
|
||||
@@ -265,19 +279,18 @@ export function createVizPanelFromPanelModel(panel: PanelModel) {
|
||||
width: panel.gridPos.w,
|
||||
height: panel.gridPos.h,
|
||||
},
|
||||
options: panel.options,
|
||||
options: panel.options ?? {},
|
||||
fieldConfig: panel.fieldConfig,
|
||||
pluginVersion: panel.pluginVersion,
|
||||
displayMode: panel.transparent ? 'transparent' : undefined,
|
||||
// To be replaced with it's own option persited option instead derived
|
||||
hoverHeader: !panel.title && !panel.timeFrom && !panel.timeShift,
|
||||
$data: new SceneDataTransformer({
|
||||
$data: new SceneQueryRunner({
|
||||
queries: panel.targets,
|
||||
maxDataPoints: panel.maxDataPoints ?? undefined,
|
||||
}),
|
||||
transformations: panel.transformations ?? [],
|
||||
}),
|
||||
$data: panel.transformations?.length
|
||||
? new SceneDataTransformer({
|
||||
$data: queryRunner,
|
||||
transformations: panel.transformations,
|
||||
})
|
||||
: queryRunner,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export const graphPanelChangedHandler: PanelTypeChangedHandler = (
|
||||
) => {
|
||||
// Changing from angular/flot panel to react/uPlot
|
||||
if (prevPluginId === 'graph' && prevOptions.angular) {
|
||||
const { fieldConfig, options } = flotToGraphOptions({
|
||||
const { fieldConfig, options } = graphToTimeseriesOptions({
|
||||
...prevOptions.angular,
|
||||
fieldConfig: prevFieldConfig,
|
||||
});
|
||||
@@ -61,7 +61,7 @@ export const graphPanelChangedHandler: PanelTypeChangedHandler = (
|
||||
return {};
|
||||
};
|
||||
|
||||
export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSource; options: TimeSeriesOptions } {
|
||||
export function graphToTimeseriesOptions(angular: any): { fieldConfig: FieldConfigSource; options: TimeSeriesOptions } {
|
||||
const overrides: ConfigOverrideRule[] = angular.fieldConfig?.overrides ?? [];
|
||||
const yaxes = angular.yaxes ?? [];
|
||||
let y1 = getFieldConfigFromOldAxis(yaxes[0]);
|
||||
|
||||
Reference in New Issue
Block a user