mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
9b7748ec13
Primarily- moving majority of the types and utils from @grafana/ui to @grafana/data * Move types from grafana-ui to grafana-data * Move valueFormats to grafana-data * Move utils from grafana-ui to grafana-data * Update imports in grafana-ui * revert data's tsconfig change * Update imports in grafana-runtime * Fix import paths in grafana-ui * Move rxjs to devDeps * Core import updates batch 1 * Import updates batch 2 * Imports fix batch 3 * Imports fixes batch i don't know * Fix imorts in grafana-toolkit * Fix imports after master merge
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import coreModule from 'app/core/core_module';
|
|
import { importDataSourcePlugin } from './plugin_loader';
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor';
|
|
import { DataSourcePluginMeta } from '@grafana/data';
|
|
import { TemplateSrv } from '../templating/template_srv';
|
|
|
|
async function loadComponent(meta: DataSourcePluginMeta) {
|
|
const dsPlugin = await importDataSourcePlugin(meta);
|
|
if (dsPlugin.components.VariableQueryEditor) {
|
|
return dsPlugin.components.VariableQueryEditor;
|
|
} else {
|
|
return DefaultVariableQueryEditor;
|
|
}
|
|
}
|
|
|
|
/** @ngInject */
|
|
function variableQueryEditorLoader(templateSrv: TemplateSrv) {
|
|
return {
|
|
restrict: 'E',
|
|
link: async (scope: any, elem: JQuery) => {
|
|
const Component = await loadComponent(scope.currentDatasource.meta);
|
|
const props = {
|
|
datasource: scope.currentDatasource,
|
|
query: scope.current.query,
|
|
onChange: scope.onQueryChange,
|
|
templateSrv,
|
|
};
|
|
ReactDOM.render(<Component {...props} />, elem[0]);
|
|
scope.$on('$destroy', () => {
|
|
ReactDOM.unmountComponentAtNode(elem[0]);
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
coreModule.directive('variableQueryEditorLoader', variableQueryEditorLoader);
|