mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scene: Exploring typed scene panels (#58168)
* Scene: Exploring typed scene panels * Updated * minor rename
This commit is contained in:
parent
c7671b6d1d
commit
c6db57c7d0
@ -1,3 +1,4 @@
|
|||||||
|
import { DeepPartial } from '@reduxjs/toolkit';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { AbsoluteTimeRange, FieldConfigSource, PanelModel, PanelPlugin, toUtc } from '@grafana/data';
|
import { AbsoluteTimeRange, FieldConfigSource, PanelModel, PanelPlugin, toUtc } from '@grafana/data';
|
||||||
@ -15,23 +16,21 @@ import { VizPanelRenderer } from './VizPanelRenderer';
|
|||||||
export interface VizPanelState<TOptions = {}, TFieldConfig = {}> extends SceneLayoutChildState {
|
export interface VizPanelState<TOptions = {}, TFieldConfig = {}> extends SceneLayoutChildState {
|
||||||
title: string;
|
title: string;
|
||||||
pluginId: string;
|
pluginId: string;
|
||||||
options: TOptions;
|
options: DeepPartial<TOptions>;
|
||||||
fieldConfig: FieldConfigSource<TFieldConfig>;
|
fieldConfig: FieldConfigSource<DeepPartial<TFieldConfig>>;
|
||||||
pluginVersion?: string;
|
pluginVersion?: string;
|
||||||
// internal state
|
// internal state
|
||||||
pluginLoadError?: string;
|
pluginLoadError?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class VizPanel<TOptions = {}, TFieldConfig = {}> extends SceneObjectBase<
|
export class VizPanel<TOptions = {}, TFieldConfig = {}> extends SceneObjectBase<VizPanelState<TOptions, TFieldConfig>> {
|
||||||
VizPanelState<Partial<TOptions>, TFieldConfig>
|
|
||||||
> {
|
|
||||||
public static Component = VizPanelRenderer;
|
public static Component = VizPanelRenderer;
|
||||||
public static Editor = VizPanelEditor;
|
public static Editor = VizPanelEditor;
|
||||||
|
|
||||||
// Not part of state as this is not serializable
|
// Not part of state as this is not serializable
|
||||||
private _plugin?: PanelPlugin;
|
private _plugin?: PanelPlugin;
|
||||||
|
|
||||||
public constructor(state: Partial<VizPanelState<Partial<TOptions>, TFieldConfig>>) {
|
public constructor(state: Partial<VizPanelState<TOptions, TFieldConfig>>) {
|
||||||
super({
|
super({
|
||||||
options: {},
|
options: {},
|
||||||
fieldConfig: { defaults: {}, overrides: [] },
|
fieldConfig: { defaults: {}, overrides: [] },
|
||||||
@ -109,7 +108,7 @@ export class VizPanel<TOptions = {}, TFieldConfig = {}> extends SceneObjectBase<
|
|||||||
this.setState({ options });
|
this.setState({ options });
|
||||||
};
|
};
|
||||||
|
|
||||||
public onFieldConfigChange = (fieldConfig: FieldConfigSource) => {
|
public onFieldConfigChange = (fieldConfig: FieldConfigSource<TFieldConfig>) => {
|
||||||
this.setState({ fieldConfig });
|
this.setState({ fieldConfig });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
import { GraphFieldConfig, TableFieldOptions } from '@grafana/schema';
|
||||||
|
import { PanelOptions as BarGaugePanelOptions } from 'app/plugins/panel/bargauge/models.gen';
|
||||||
|
import { PanelOptions as TablePanelOptions } from 'app/plugins/panel/table/models.gen';
|
||||||
|
import { TimeSeriesOptions } from 'app/plugins/panel/timeseries/types';
|
||||||
|
|
||||||
|
import { VizPanel, VizPanelState } from './VizPanel';
|
||||||
|
|
||||||
|
export type TypedVizPanelState<TOptions, TFieldConfig> = Omit<
|
||||||
|
Partial<VizPanelState<TOptions, TFieldConfig>>,
|
||||||
|
'pluginId'
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const panelBuilders = {
|
||||||
|
newTable: (state: TypedVizPanelState<TablePanelOptions, TableFieldOptions>) => {
|
||||||
|
return new VizPanel<TablePanelOptions, TableFieldOptions>({
|
||||||
|
...state,
|
||||||
|
pluginId: 'table',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
newGraph: (state: TypedVizPanelState<TimeSeriesOptions, GraphFieldConfig>) => {
|
||||||
|
return new VizPanel({
|
||||||
|
...state,
|
||||||
|
pluginId: 'timeseries',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
newBarGauge: (state: TypedVizPanelState<BarGaugePanelOptions, {}>) => {
|
||||||
|
return new VizPanel({
|
||||||
|
...state,
|
||||||
|
pluginId: 'bargauge',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
@ -8,6 +8,7 @@ import {
|
|||||||
VizPanel,
|
VizPanel,
|
||||||
} from '../components';
|
} from '../components';
|
||||||
import { EmbeddedScene } from '../components/Scene';
|
import { EmbeddedScene } from '../components/Scene';
|
||||||
|
import { panelBuilders } from '../components/VizPanel/panelBuilders';
|
||||||
import { SceneTimeRange } from '../core/SceneTimeRange';
|
import { SceneTimeRange } from '../core/SceneTimeRange';
|
||||||
import { SceneEditManager } from '../editor/SceneEditManager';
|
import { SceneEditManager } from '../editor/SceneEditManager';
|
||||||
|
|
||||||
@ -19,21 +20,27 @@ export function getFlexLayoutTest(standalone: boolean): Scene {
|
|||||||
layout: new SceneFlexLayout({
|
layout: new SceneFlexLayout({
|
||||||
direction: 'row',
|
direction: 'row',
|
||||||
children: [
|
children: [
|
||||||
new VizPanel({
|
panelBuilders.newGraph({
|
||||||
size: { minWidth: '70%' },
|
size: { minWidth: '70%' },
|
||||||
pluginId: 'timeseries',
|
|
||||||
title: 'Dynamic height and width',
|
title: 'Dynamic height and width',
|
||||||
$data: getQueryRunnerWithRandomWalkQuery({}, { maxDataPointsFromWidth: true }),
|
$data: getQueryRunnerWithRandomWalkQuery({}, { maxDataPointsFromWidth: true }),
|
||||||
}),
|
}),
|
||||||
new SceneFlexLayout({
|
new SceneFlexLayout({
|
||||||
direction: 'column',
|
direction: 'column',
|
||||||
children: [
|
children: [
|
||||||
new VizPanel({
|
panelBuilders.newGraph({
|
||||||
pluginId: 'timeseries',
|
|
||||||
title: 'Fill height',
|
title: 'Fill height',
|
||||||
|
options: {},
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {
|
||||||
|
custom: {
|
||||||
|
fillOpacity: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
new VizPanel({
|
panelBuilders.newGraph({
|
||||||
pluginId: 'timeseries',
|
|
||||||
title: 'Fill height',
|
title: 'Fill height',
|
||||||
}),
|
}),
|
||||||
new SceneCanvasText({
|
new SceneCanvasText({
|
||||||
@ -42,10 +49,9 @@ export function getFlexLayoutTest(standalone: boolean): Scene {
|
|||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
}),
|
}),
|
||||||
new VizPanel({
|
panelBuilders.newGraph({
|
||||||
size: { height: 300 },
|
|
||||||
pluginId: 'timeseries',
|
|
||||||
title: 'Fixed height',
|
title: 'Fixed height',
|
||||||
|
size: { height: 300 },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user