Refactor: Plugin exports & data source / panel types (#16364)

* wip: began work off removing meta and pluginExports from DataSourceApi interface

* WIP: changing how plugins are exports and loaded

* Down the refactoring rabit hole that keeps expanding

* TestData now returns DataSourcePlugin

* Refactoring: fixed app config page loading, type renamings and more typings

* Refactor: Correct casing on DatasourceStatus => DataSourceStatus
This commit is contained in:
Torkel Ödegaard
2019-04-04 18:30:15 +02:00
committed by GitHub
parent e04990752c
commit 47e51cb6b3
31 changed files with 411 additions and 251 deletions

View File

@@ -1,6 +1,8 @@
import { PanelModel } from './PanelModel';
import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks';
import { ReactPanelPlugin } from '@grafana/ui/src/types/panel';
import { ReactPanelPlugin, AngularPanelPlugin } from '@grafana/ui/src/types/panel';
class TablePanelCtrl {}
describe('PanelModel', () => {
describe('when creating new panel model', () => {
@@ -28,7 +30,12 @@ describe('PanelModel', () => {
},
};
model = new PanelModel(modelJson);
model.pluginLoaded(getPanelPlugin({ id: 'table', exports: { PanelCtrl: {} as any } }));
model.pluginLoaded(
getPanelPlugin({
id: 'table',
angularPlugin: new AngularPanelPlugin(TablePanelCtrl),
})
);
});
it('should apply defaults', () => {
@@ -79,7 +86,7 @@ describe('PanelModel', () => {
describe('when changing panel type', () => {
beforeEach(() => {
model.changePlugin(getPanelPlugin({ id: 'graph', exports: {} }));
model.changePlugin(getPanelPlugin({ id: 'graph' }));
model.alert = { id: 2 };
});
@@ -88,12 +95,12 @@ describe('PanelModel', () => {
});
it('should restore table properties when changing back', () => {
model.changePlugin(getPanelPlugin({ id: 'table', exports: {} }));
model.changePlugin(getPanelPlugin({ id: 'table' }));
expect(model.showColumns).toBe(true);
});
it('should remove alert rule when changing type that does not support it', () => {
model.changePlugin(getPanelPlugin({ id: 'table', exports: {} }));
model.changePlugin(getPanelPlugin({ id: 'table' }));
expect(model.alert).toBe(undefined);
});
});
@@ -105,7 +112,7 @@ describe('PanelModel', () => {
model.events.on('panel-teardown', () => {
tearDownPublished = true;
});
model.changePlugin(getPanelPlugin({ id: 'graph', exports: {} }));
model.changePlugin(getPanelPlugin({ id: 'graph' }));
});
it('should teardown / destroy panel so angular panels event subscriptions are removed', () => {
@@ -116,15 +123,13 @@ describe('PanelModel', () => {
describe('when changing to react panel', () => {
const onPanelTypeChanged = jest.fn();
const reactPanel = new ReactPanelPlugin({} as any).setPanelChangeHandler(onPanelTypeChanged as any);
const reactPlugin = new ReactPanelPlugin({} as any).setPanelChangeHandler(onPanelTypeChanged as any);
beforeEach(() => {
model.changePlugin(
getPanelPlugin({
id: 'react',
exports: {
reactPanel,
},
reactPlugin: reactPlugin,
})
);
});