2018-10-24 09:26:05 -05:00
|
|
|
import coreModule from 'app/core/core_module';
|
2019-04-04 11:30:15 -05:00
|
|
|
import { importDataSourcePlugin } from './plugin_loader';
|
2018-10-24 09:26:05 -05:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-11-13 03:57:10 -06:00
|
|
|
import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor';
|
2019-10-31 04:48:05 -05:00
|
|
|
import { DataSourcePluginMeta } from '@grafana/data';
|
2019-05-01 00:36:46 -05:00
|
|
|
import { TemplateSrv } from '../templating/template_srv';
|
2018-10-24 09:26:05 -05:00
|
|
|
|
2019-05-01 00:36:46 -05:00
|
|
|
async function loadComponent(meta: DataSourcePluginMeta) {
|
|
|
|
const dsPlugin = await importDataSourcePlugin(meta);
|
2019-04-04 11:30:15 -05:00
|
|
|
if (dsPlugin.components.VariableQueryEditor) {
|
|
|
|
return dsPlugin.components.VariableQueryEditor;
|
2018-10-24 09:26:05 -05:00
|
|
|
} else {
|
2018-11-13 03:57:10 -06:00
|
|
|
return DefaultVariableQueryEditor;
|
2018-10-24 09:26:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @ngInject */
|
2019-05-01 00:36:46 -05:00
|
|
|
function variableQueryEditorLoader(templateSrv: TemplateSrv) {
|
2018-10-24 09:26:05 -05:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2019-07-18 01:03:04 -05:00
|
|
|
link: async (scope: any, elem: JQuery) => {
|
2019-05-01 00:36:46 -05:00
|
|
|
const Component = await loadComponent(scope.currentDatasource.meta);
|
2018-10-25 06:30:39 -05:00
|
|
|
const props = {
|
2018-10-25 06:53:02 -05:00
|
|
|
datasource: scope.currentDatasource,
|
2018-10-25 06:30:39 -05:00
|
|
|
query: scope.current.query,
|
|
|
|
onChange: scope.onQueryChange,
|
2018-11-19 07:44:40 -06:00
|
|
|
templateSrv,
|
2018-10-25 06:30:39 -05:00
|
|
|
};
|
|
|
|
ReactDOM.render(<Component {...props} />, elem[0]);
|
2018-10-24 09:26:05 -05:00
|
|
|
scope.$on('$destroy', () => {
|
|
|
|
ReactDOM.unmountComponentAtNode(elem[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-13 03:57:10 -06:00
|
|
|
coreModule.directive('variableQueryEditorLoader', variableQueryEditorLoader);
|