2018-11-22 11:22:15 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
|
2018-11-23 07:32:56 -06:00
|
|
|
import { Emitter } from 'app/core/utils/emitter';
|
2018-11-22 11:22:15 -06:00
|
|
|
import { DataQuery } from 'app/types';
|
2018-11-23 07:32:56 -06:00
|
|
|
import 'app/features/plugins/plugin_loader';
|
2018-11-22 11:22:15 -06:00
|
|
|
|
|
|
|
interface QueryEditorProps {
|
|
|
|
datasource: any;
|
|
|
|
error?: string | JSX.Element;
|
|
|
|
onExecuteQuery?: () => void;
|
|
|
|
onQueryChange?: (value: DataQuery, override?: boolean) => void;
|
2018-11-23 07:32:56 -06:00
|
|
|
initialQuery: DataQuery;
|
|
|
|
exploreEvents: Emitter;
|
2018-11-22 11:22:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class QueryEditor extends PureComponent<QueryEditorProps, any> {
|
|
|
|
element: any;
|
|
|
|
component: AngularComponent;
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
if (!this.element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-23 07:32:56 -06:00
|
|
|
const { datasource, initialQuery, exploreEvents } = this.props;
|
2018-11-22 11:22:15 -06:00
|
|
|
const loader = getAngularLoader();
|
2018-11-23 07:32:56 -06:00
|
|
|
const template = '<plugin-component type="query-ctrl"> </plugin-component>';
|
2018-11-22 11:22:15 -06:00
|
|
|
const target = { datasource: datasource.name };
|
|
|
|
const scopeProps = {
|
2018-11-23 07:32:56 -06:00
|
|
|
target,
|
2018-11-22 11:22:15 -06:00
|
|
|
ctrl: {
|
|
|
|
refresh: () => {
|
2018-11-23 07:32:56 -06:00
|
|
|
this.props.onQueryChange({ refId: initialQuery.refId, ...target }, false);
|
2018-11-22 11:22:15 -06:00
|
|
|
this.props.onExecuteQuery();
|
|
|
|
},
|
2018-11-23 08:12:20 -06:00
|
|
|
events: exploreEvents,
|
2018-11-22 11:22:15 -06:00
|
|
|
panel: {
|
|
|
|
datasource,
|
2018-11-23 07:32:56 -06:00
|
|
|
targets: [{}],
|
2018-11-22 11:22:15 -06:00
|
|
|
},
|
|
|
|
dashboard: {
|
2018-11-23 07:32:56 -06:00
|
|
|
getNextQueryLetter: x => '',
|
2018-11-22 11:22:15 -06:00
|
|
|
},
|
2018-11-23 08:15:41 -06:00
|
|
|
hideEditorRowActions: true,
|
2018-11-23 08:37:49 -06:00
|
|
|
interval: '1m',
|
|
|
|
intervalMs: 60000,
|
2018-11-22 11:22:15 -06:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.component = loader.load(this.element, scopeProps, template);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.component) {
|
|
|
|
this.component.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div ref={element => (this.element = element)} style={{ width: '100%' }} />;
|
|
|
|
}
|
|
|
|
}
|