variableQueryEditorLoader.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import coreModule from 'app/core/core_module';
  2. import { importPluginModule } from './plugin_loader';
  3. import React from 'react';
  4. import ReactDOM from 'react-dom';
  5. import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor';
  6. async function loadComponent(module) {
  7. const component = await importPluginModule(module);
  8. if (component && component.VariableQueryEditor) {
  9. return component.VariableQueryEditor;
  10. } else {
  11. return DefaultVariableQueryEditor;
  12. }
  13. }
  14. /** @ngInject */
  15. function variableQueryEditorLoader(templateSrv) {
  16. return {
  17. restrict: 'E',
  18. link: async (scope, elem) => {
  19. const Component = await loadComponent(scope.currentDatasource.meta.module);
  20. const props = {
  21. datasource: scope.currentDatasource,
  22. query: scope.current.query,
  23. onChange: scope.onQueryChange,
  24. templateSrv,
  25. };
  26. ReactDOM.render(<Component {...props} />, elem[0]);
  27. scope.$on('$destroy', () => {
  28. ReactDOM.unmountComponentAtNode(elem[0]);
  29. });
  30. },
  31. };
  32. }
  33. coreModule.directive('variableQueryEditorLoader', variableQueryEditorLoader);