diff --git a/packages/grafana-ui/src/types/plugin.ts b/packages/grafana-ui/src/types/plugin.ts index e2dda8ad407..bb1794a5154 100644 --- a/packages/grafana-ui/src/types/plugin.ts +++ b/packages/grafana-ui/src/types/plugin.ts @@ -91,6 +91,7 @@ export interface PluginMeta { includes: PluginInclude[]; // Datasource-specific + builtIn?: boolean; metrics?: boolean; tables?: boolean; logs?: boolean; diff --git a/public/app/core/config.ts b/public/app/core/config.ts index bbf7fb88d62..9789888e60f 100644 --- a/public/app/core/config.ts +++ b/public/app/core/config.ts @@ -13,7 +13,7 @@ export interface BuildInfo { export class Settings { datasources: any; - panels: PanelPlugin[]; + panels: { [key: string]: PanelPlugin }; appSubUrl: string; windowTitlePrefix: string; buildInfo: BuildInfo; diff --git a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts index ac1b5f08632..1562953fd1b 100644 --- a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts +++ b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts @@ -4,13 +4,16 @@ jest.mock('app/core/store', () => { }; }); +// @ts-ignore import _ from 'lodash'; import config from 'app/core/config'; import { DashboardExporter } from './DashboardExporter'; import { DashboardModel } from '../../state/DashboardModel'; +import { DatasourceSrv } from 'app/features/plugins/datasource_srv'; +import { PanelPlugin } from 'app/types'; describe('given dashboard with repeated panels', () => { - let dash, exported; + let dash: any, exported: any; beforeEach(done => { dash = { @@ -89,25 +92,25 @@ describe('given dashboard with repeated panels', () => { config.buildInfo.version = '3.0.2'; //Stubs test function calls - const datasourceSrvStub = { get: jest.fn(arg => getStub(arg)) }; + const datasourceSrvStub = ({ get: jest.fn(arg => getStub(arg)) } as any) as DatasourceSrv; config.panels['graph'] = { id: 'graph', name: 'Graph', info: { version: '1.1.0' }, - }; + } as PanelPlugin; config.panels['table'] = { id: 'table', name: 'Table', info: { version: '1.1.1' }, - }; + } as PanelPlugin; config.panels['heatmap'] = { id: 'heatmap', name: 'Heatmap', info: { version: '1.1.2' }, - }; + } as PanelPlugin; dash = new DashboardModel(dash, {}); const exporter = new DashboardExporter(datasourceSrvStub); @@ -213,7 +216,7 @@ describe('given dashboard with repeated panels', () => { }); // Stub responses -const stubs = []; +const stubs: { [key: string]: {} } = {}; stubs['gfdb'] = { name: 'gfdb', meta: { id: 'testdb', info: { version: '1.2.1' }, name: 'TestDB' }, @@ -249,6 +252,6 @@ stubs['-- Grafana --'] = { }, }; -function getStub(arg) { +function getStub(arg: string) { return Promise.resolve(stubs[arg || 'gfdb']); } diff --git a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts index 6cf14f81c86..4150cb9a848 100644 --- a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts +++ b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts @@ -1,9 +1,42 @@ -import config from 'app/core/config'; +// @ts-ignore import _ from 'lodash'; + +import config from 'app/core/config'; import { DashboardModel } from '../../state/DashboardModel'; +import DatasourceSrv from 'app/features/plugins/datasource_srv'; +import { PanelModel } from 'app/features/dashboard/state'; +import { PanelPlugin } from 'app/types/plugins'; + +interface Input { + name: string; + type: string; + label: string; + value: any; + description: string; +} + +interface Requires { + [key: string]: { + type: string; + id: string; + name: string; + version: string; + }; +} + +interface DataSources { + [key: string]: { + name: string; + label: string; + description: string; + type: string; + pluginId: string; + pluginName: string; + }; +} export class DashboardExporter { - constructor(private datasourceSrv) {} + constructor(private datasourceSrv: DatasourceSrv) {} makeExportable(dashboard: DashboardModel) { // clean up repeated rows and panels, @@ -18,19 +51,19 @@ export class DashboardExporter { // undo repeat cleanup dashboard.processRepeats(); - const inputs = []; - const requires = {}; - const datasources = {}; - const promises = []; - const variableLookup: any = {}; + const inputs: Input[] = []; + const requires: Requires = {}; + const datasources: DataSources = {}; + const promises: Array> = []; + const variableLookup: { [key: string]: any } = {}; for (const variable of saveModel.templating.list) { variableLookup[variable.name] = variable; } - const templateizeDatasourceUsage = obj => { - let datasource = obj.datasource; - let datasourceVariable = null; + const templateizeDatasourceUsage = (obj: any) => { + let datasource: string = obj.datasource; + let datasourceVariable: any = null; // ignore data source properties that contain a variable if (datasource && datasource.indexOf('$') === 0) { @@ -74,7 +107,7 @@ export class DashboardExporter { ); }; - const processPanel = panel => { + const processPanel = (panel: PanelModel) => { if (panel.datasource !== undefined) { templateizeDatasourceUsage(panel); } @@ -87,7 +120,7 @@ export class DashboardExporter { } } - const panelDef = config.panels[panel.type]; + const panelDef: PanelPlugin = config.panels[panel.type]; if (panelDef) { requires['panel' + panelDef.id] = { type: 'panel', @@ -135,7 +168,7 @@ export class DashboardExporter { return Promise.all(promises) .then(() => { - _.each(datasources, (value, key) => { + _.each(datasources, (value: any) => { inputs.push(value); }); @@ -160,7 +193,7 @@ export class DashboardExporter { } // make inputs and requires a top thing - const newObj = {}; + const newObj: { [key: string]: {} } = {}; newObj['__inputs'] = inputs; newObj['__requires'] = _.sortBy(requires, ['id']); diff --git a/public/test/specs/helpers.ts b/public/test/specs/helpers.ts index 58403ac7ed7..f9124773c97 100644 --- a/public/test/specs/helpers.ts +++ b/public/test/specs/helpers.ts @@ -3,6 +3,7 @@ import config from 'app/core/config'; import * as dateMath from 'app/core/utils/datemath'; import { angularMocks, sinon } from '../lib/common'; import { PanelModel } from 'app/features/dashboard/state/PanelModel'; +import { PanelPlugin } from 'app/types'; export function ControllerTestContext(this: any) { const self = this; @@ -62,7 +63,7 @@ export function ControllerTestContext(this: any) { $rootScope.colors.push('#' + i); } - config.panels['test'] = { info: {} }; + config.panels['test'] = { info: {} } as PanelPlugin; self.ctrl = $controller( Ctrl, { $scope: self.scope },