mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Apply field overrides in PanelChrome * Move applyFieldOverrides to panel query runner * Review updates * Make sure overrides are applied back on souce panel when exiting the new edit mode * TS ignores in est * Make field display work in viz repeater * Review updates * Review and test updates * Change the way overrides and trransformations are retrieved in PQR * Add fieldConfig property to PanelModel * Dashboard migration v1 * Use field config when exiting new panel edit mode * Gauge - use fieldConfig from panel model * FieldDisplayOptions - don's extend FieldConfigSource * Fix fieldDisplay ts * StatPanel updated * Stat panel defaults applied * Table2 panel options update * React graph updates * BarGauge updated * PieChart, Gauge, BarGauge and Stat updates * PieChart - remove field config defaults from options * FieldDisplayEditor - remove unused methos * PanelModel - remove debugger * Remove fieldConfig from field options when migrating dashboard * Update data links migrations * Update fieldDisaplay tests to respect new fieldConfig * Update dashboard schema version in snapshots * Fix BarGaugePanel test * Rebase fixes * Add onFieldConfigChange to PanelProps type * Update shared single stat migration * Pass PanelModel instead of options only for panel type change handler [breaking] * Renames * Don't mutate panel options * Migrations update * Remove obsolete snap * Minor updates after review * Fix null checks * Temporarily (until we decide to switch to new pane edit) bring back old aditors * Temporarily rename ValueMappingEditor and MappingRow to Legacy* * Migrations update * Updae setFieldConfigDefaults API * Update the way field config defaults are applied * Use standard field config for gauge, bar gauge and stat panels * refactoring * Revert dashboard fieldOptions migrations as those are handled by single stat migrator * Fix ts in tests * Strict null fix and some minor fixes Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
186 lines
4.5 KiB
TypeScript
186 lines
4.5 KiB
TypeScript
import { PanelModel } from '@grafana/data';
|
|
import { gaugePanelMigrationHandler, gaugePanelChangedHandler } from './GaugeMigrations';
|
|
|
|
describe('Gauge Panel Migrations', () => {
|
|
it('from 6.1.1', () => {
|
|
const panel = {
|
|
datasource: '-- Grafana --',
|
|
gridPos: {
|
|
h: 9,
|
|
w: 12,
|
|
x: 0,
|
|
y: 0,
|
|
},
|
|
id: 2,
|
|
options: {
|
|
maxValue: '50',
|
|
minValue: '-50',
|
|
orientation: 'auto',
|
|
showThresholdLabels: true,
|
|
showThresholdMarkers: true,
|
|
thresholds: [
|
|
{
|
|
color: 'green',
|
|
index: 0,
|
|
value: null,
|
|
},
|
|
{
|
|
color: '#EAB839',
|
|
index: 1,
|
|
value: -25,
|
|
},
|
|
{
|
|
color: '#6ED0E0',
|
|
index: 2,
|
|
value: 0,
|
|
},
|
|
{
|
|
color: 'red',
|
|
index: 3,
|
|
value: 25,
|
|
},
|
|
],
|
|
valueMappings: [
|
|
{
|
|
id: 1,
|
|
operator: '',
|
|
value: '',
|
|
text: 'BIG',
|
|
type: 2,
|
|
from: '50',
|
|
to: '1000',
|
|
},
|
|
],
|
|
valueOptions: {
|
|
decimals: 3,
|
|
prefix: 'XX',
|
|
stat: 'last',
|
|
suffix: 'YY',
|
|
unit: 'accMS2',
|
|
},
|
|
},
|
|
pluginVersion: '6.1.6',
|
|
targets: [
|
|
{
|
|
refId: 'A',
|
|
},
|
|
{
|
|
refId: 'B',
|
|
},
|
|
{
|
|
refId: 'C',
|
|
},
|
|
],
|
|
timeFrom: null,
|
|
timeShift: null,
|
|
title: 'Panel Title',
|
|
type: 'gauge',
|
|
} as Omit<PanelModel, 'fieldConfig'>;
|
|
|
|
const result = gaugePanelMigrationHandler(panel as PanelModel);
|
|
expect(result).toMatchSnapshot();
|
|
|
|
// Ignored due to the API change
|
|
//@ts-ignore
|
|
expect(result.fieldOptions.defaults).toBeUndefined();
|
|
// Ignored due to the API change
|
|
//@ts-ignore
|
|
expect(result.fieldOptions.overrides).toBeUndefined();
|
|
|
|
expect((panel as PanelModel).fieldConfig).toMatchInlineSnapshot(`
|
|
Object {
|
|
"defaults": Object {
|
|
"color": Object {
|
|
"mode": "thresholds",
|
|
},
|
|
"decimals": 3,
|
|
"mappings": Array [
|
|
Object {
|
|
"from": "50",
|
|
"id": 1,
|
|
"operator": "",
|
|
"text": "BIG",
|
|
"to": "1000",
|
|
"type": 2,
|
|
"value": "",
|
|
},
|
|
],
|
|
"max": "50",
|
|
"min": "-50",
|
|
"thresholds": Object {
|
|
"mode": "absolute",
|
|
"steps": Array [
|
|
Object {
|
|
"color": "green",
|
|
"index": 0,
|
|
"value": -Infinity,
|
|
},
|
|
Object {
|
|
"color": "#EAB839",
|
|
"index": 1,
|
|
"value": -25,
|
|
},
|
|
Object {
|
|
"color": "#6ED0E0",
|
|
"index": 2,
|
|
"value": 0,
|
|
},
|
|
Object {
|
|
"color": "red",
|
|
"index": 3,
|
|
"value": 25,
|
|
},
|
|
],
|
|
},
|
|
"unit": "accMS2",
|
|
},
|
|
"overrides": Array [],
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('change from angular singlestat to gauge', () => {
|
|
const old: any = {
|
|
angular: {
|
|
format: 'ms',
|
|
decimals: 7,
|
|
gauge: {
|
|
maxValue: 150,
|
|
minValue: -10,
|
|
show: true,
|
|
thresholdLabels: true,
|
|
thresholdMarkers: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
const panel = {} as PanelModel;
|
|
const newOptions = gaugePanelChangedHandler(panel, 'singlestat', old);
|
|
expect(panel.fieldConfig.defaults.unit).toBe('ms');
|
|
expect(panel.fieldConfig.defaults.min).toBe(-10);
|
|
expect(panel.fieldConfig.defaults.max).toBe(150);
|
|
expect(panel.fieldConfig.defaults.decimals).toBe(7);
|
|
expect(newOptions.showThresholdMarkers).toBe(true);
|
|
expect(newOptions.showThresholdLabels).toBe(true);
|
|
});
|
|
|
|
it('change from angular singlestatt with no enabled gauge', () => {
|
|
const old: any = {
|
|
angular: {
|
|
format: 'ms',
|
|
decimals: 7,
|
|
gauge: {
|
|
maxValue: 150,
|
|
minValue: -10,
|
|
show: false,
|
|
},
|
|
},
|
|
};
|
|
const panel = {} as PanelModel;
|
|
gaugePanelChangedHandler(panel, 'singlestat', old);
|
|
expect(panel.fieldConfig.defaults.unit).toBe('ms');
|
|
expect(panel.fieldConfig.defaults.min).toBe(undefined);
|
|
expect(panel.fieldConfig.defaults.max).toBe(undefined);
|
|
});
|
|
});
|