| 
									
										
										
										
											2018-10-24 22:26:05 +08:00
										 |  |  | import coreModule from 'app/core/core_module'; | 
					
						
							| 
									
										
										
										
											2019-04-05 00:30:15 +08:00
										 |  |  | import { importDataSourcePlugin } from './plugin_loader'; | 
					
						
							| 
									
										
										
										
											2018-10-24 22:26:05 +08:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import ReactDOM from 'react-dom'; | 
					
						
							| 
									
										
										
										
											2018-11-13 17:57:10 +08:00
										 |  |  | import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor'; | 
					
						
							| 
									
										
										
										
											2019-10-31 17:48:05 +08:00
										 |  |  | import { DataSourcePluginMeta } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2019-05-01 13:36:46 +08:00
										 |  |  | import { TemplateSrv } from '../templating/template_srv'; | 
					
						
							| 
									
										
										
										
											2018-10-24 22:26:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-01 13:36:46 +08:00
										 |  |  | async function loadComponent(meta: DataSourcePluginMeta) { | 
					
						
							|  |  |  |   const dsPlugin = await importDataSourcePlugin(meta); | 
					
						
							| 
									
										
										
										
											2019-04-05 00:30:15 +08:00
										 |  |  |   if (dsPlugin.components.VariableQueryEditor) { | 
					
						
							|  |  |  |     return dsPlugin.components.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 */ | 
					
						
							| 
									
										
										
										
											2019-05-01 13:36:46 +08:00
										 |  |  | function variableQueryEditorLoader(templateSrv: TemplateSrv) { | 
					
						
							| 
									
										
										
										
											2018-10-24 22:26:05 +08:00
										 |  |  |   return { | 
					
						
							|  |  |  |     restrict: 'E', | 
					
						
							| 
									
										
										
										
											2019-07-18 14:03:04 +08:00
										 |  |  |     link: async (scope: any, elem: JQuery) => { | 
					
						
							| 
									
										
										
										
											2019-05-01 13:36:46 +08:00
										 |  |  |       const Component = await loadComponent(scope.currentDatasource.meta); | 
					
						
							| 
									
										
										
										
											2018-10-25 19:30:39 +08:00
										 |  |  |       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); |