mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Changed how react panels store their options
This commit is contained in:
@@ -14,4 +14,3 @@ export const DASHBOARD_TOP_PADDING = 20;
|
||||
|
||||
export const PANEL_HEADER_HEIGHT = 27;
|
||||
export const PANEL_BORDER = 2;
|
||||
export const PANEL_OPTIONS_KEY_PREFIX = 'options-';
|
||||
|
||||
@@ -22,7 +22,7 @@ export class DashboardMigrator {
|
||||
let i, j, k, n;
|
||||
const oldVersion = this.dashboard.schemaVersion;
|
||||
const panelUpgrades = [];
|
||||
this.dashboard.schemaVersion = 17;
|
||||
this.dashboard.schemaVersion = 18;
|
||||
|
||||
if (oldVersion === this.dashboard.schemaVersion) {
|
||||
return;
|
||||
@@ -387,6 +387,16 @@ export class DashboardMigrator {
|
||||
});
|
||||
}
|
||||
|
||||
if (oldVersion < 18) {
|
||||
// migrate change to gauge options
|
||||
panelUpgrades.push(panel => {
|
||||
if (panel['options-gauge']) {
|
||||
panel.options = panel['options-gauge'];
|
||||
delete panel['options-gauge'];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (panelUpgrades.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,5 +55,19 @@ describe('PanelModel', () => {
|
||||
expect(model.alert).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get panel options', () => {
|
||||
it('should apply defaults', () => {
|
||||
model.options = { existingProp: 10 };
|
||||
const options = model.getOptions({
|
||||
defaultProp: true,
|
||||
existingProp: 0,
|
||||
});
|
||||
|
||||
expect(options.defaultProp).toBe(true);
|
||||
expect(options.existingProp).toBe(10);
|
||||
expect(model.options).toBe(options);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@ import _ from 'lodash';
|
||||
|
||||
// Types
|
||||
import { Emitter } from 'app/core/utils/emitter';
|
||||
import { PANEL_OPTIONS_KEY_PREFIX } from 'app/core/constants';
|
||||
import { DataQuery, TimeSeries } from '@grafana/ui';
|
||||
import { TableData } from '@grafana/ui/src';
|
||||
|
||||
@@ -92,6 +91,7 @@ export class PanelModel {
|
||||
timeFrom?: any;
|
||||
timeShift?: any;
|
||||
hideTimeOverride?: any;
|
||||
options: object;
|
||||
|
||||
maxDataPoints?: number;
|
||||
interval?: string;
|
||||
@@ -105,8 +105,6 @@ export class PanelModel {
|
||||
hasRefreshed: boolean;
|
||||
events: Emitter;
|
||||
cacheTimeout?: any;
|
||||
|
||||
// cache props between plugins
|
||||
cachedPluginOptions?: any;
|
||||
|
||||
constructor(model) {
|
||||
@@ -134,20 +132,14 @@ export class PanelModel {
|
||||
}
|
||||
|
||||
getOptions(panelDefaults) {
|
||||
return _.defaultsDeep(this[this.getOptionsKey()] || {}, panelDefaults);
|
||||
return _.defaultsDeep(this.options || {}, panelDefaults);
|
||||
}
|
||||
|
||||
updateOptions(options: object) {
|
||||
const update: any = {};
|
||||
update[this.getOptionsKey()] = options;
|
||||
Object.assign(this, update);
|
||||
this.options = options;
|
||||
this.render();
|
||||
}
|
||||
|
||||
private getOptionsKey() {
|
||||
return PANEL_OPTIONS_KEY_PREFIX + this.type;
|
||||
}
|
||||
|
||||
getSaveModel() {
|
||||
const model: any = {};
|
||||
for (const property in this) {
|
||||
|
||||
Reference in New Issue
Block a user