mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
NewPanelEditor: Options/FieldConfig API for defaults and common options selection (#23214)
* Add "some" typesafety to panel options/field config APIs * Allow selected common field config properties config, allow option defaults config via fluent API * Update packages/grafana-data/src/panel/PanelPlugin.ts Co-Authored-By: Ryan McKinley <ryantxu@gmail.com> * Add defaults support for custom field config * Enable defaults setting for standard and custom field configs * Remove setFieldConfigDefaults from PanelPlugin API and replace it with useStandardFieldConfig * Update API for standard field config defaults Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { PanelModel } from './PanelModel';
|
||||
import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks';
|
||||
import { ConfigOverrideRule, PanelProps } from '@grafana/data';
|
||||
import { PanelProps, StandardFieldConfigProperties } from '@grafana/data';
|
||||
import { ComponentClass } from 'react';
|
||||
|
||||
class TablePanelCtrl {}
|
||||
@@ -70,13 +70,6 @@ describe('PanelModel', () => {
|
||||
};
|
||||
|
||||
model = new PanelModel(modelJson);
|
||||
const overrideMock: ConfigOverrideRule = {
|
||||
matcher: {
|
||||
id: '2',
|
||||
options: {},
|
||||
},
|
||||
properties: [],
|
||||
};
|
||||
|
||||
const panelPlugin = getPanelPlugin(
|
||||
{
|
||||
@@ -86,12 +79,9 @@ describe('PanelModel', () => {
|
||||
TablePanelCtrl // angular
|
||||
);
|
||||
panelPlugin.setDefaults(defaultOptionsMock);
|
||||
panelPlugin.setFieldConfigDefaults({
|
||||
defaults: {
|
||||
unit: 'flop',
|
||||
decimals: 2,
|
||||
},
|
||||
overrides: [overrideMock],
|
||||
panelPlugin.useStandardFieldConfig([StandardFieldConfigProperties.Unit, StandardFieldConfigProperties.Decimals], {
|
||||
[StandardFieldConfigProperties.Unit]: 'flop',
|
||||
[StandardFieldConfigProperties.Decimals]: 2,
|
||||
});
|
||||
model.pluginLoaded(panelPlugin);
|
||||
});
|
||||
@@ -108,10 +98,6 @@ describe('PanelModel', () => {
|
||||
expect(model.getOptions().arrayWith2Values.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should merge override field config options', () => {
|
||||
expect(model.getFieldOverrideOptions().fieldOptions.overrides.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should apply field config defaults', () => {
|
||||
// default unit is overriden by model
|
||||
expect(model.getFieldOverrideOptions().fieldOptions.defaults.unit).toBe('mpg');
|
||||
|
||||
Reference in New Issue
Block a user