2018-10-24 22:26:05 +08:00
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
|
import { importPluginModule } from './plugin_loader';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-11-13 17:57:10 +08:00
|
|
|
import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor';
|
2018-10-24 22:26:05 +08:00
|
|
|
|
|
|
|
|
async function loadComponent(module) {
|
|
|
|
|
const component = await importPluginModule(module);
|
2018-11-13 17:57:10 +08:00
|
|
|
if (component && component.VariableQueryEditor) {
|
|
|
|
|
return component.VariableQueryEditor;
|
2018-10-24 22:26:05 +08:00
|
|
|
} else {
|
2018-11-13 17:57:10 +08:00
|
|
|
return DefaultVariableQueryEditor;
|
2018-10-24 22:26:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @ngInject */
|
2018-11-19 21:44:40 +08:00
|
|
|
function variableQueryEditorLoader(templateSrv) {
|
2018-10-24 22:26:05 +08:00
|
|
|
return {
|
|
|
|
|
restrict: 'E',
|
|
|
|
|
link: async (scope, elem) => {
|
2018-10-25 19:30:39 +08:00
|
|
|
const Component = await loadComponent(scope.currentDatasource.meta.module);
|
|
|
|
|
const props = {
|
2018-10-25 19:53:02 +08:00
|
|
|
datasource: scope.currentDatasource,
|
2018-10-25 19:30:39 +08:00
|
|
|
query: scope.current.query,
|
|
|
|
|
onChange: scope.onQueryChange,
|
2018-11-19 21:44:40 +08:00
|
|
|
templateSrv,
|
2018-10-25 19:30:39 +08:00
|
|
|
};
|
|
|
|
|
ReactDOM.render(<Component {...props} />, elem[0]);
|
2018-10-24 22:26:05 +08:00
|
|
|
scope.$on('$destroy', () => {
|
|
|
|
|
ReactDOM.unmountComponentAtNode(elem[0]);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 17:57:10 +08:00
|
|
|
coreModule.directive('variableQueryEditorLoader', variableQueryEditorLoader);
|