mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: make sure default template query editor state is propagted to parent angular scope
This commit is contained in:
@@ -1,19 +1,9 @@
|
|||||||
import _ from 'lodash';
|
|
||||||
import coreModule from 'app/core/core_module';
|
import coreModule from 'app/core/core_module';
|
||||||
import { importPluginModule } from './plugin_loader';
|
import { importPluginModule } from './plugin_loader';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Provider } from 'react-redux';
|
|
||||||
import DefaultTemplateQueryCtrl from '../templating/defaultTemplateQueryCtrl';
|
import DefaultTemplateQueryCtrl from '../templating/defaultTemplateQueryCtrl';
|
||||||
|
|
||||||
function WrapInProvider(Component, props) {
|
|
||||||
return (
|
|
||||||
<Provider>
|
|
||||||
<Component {...props} />
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadComponent(module) {
|
async function loadComponent(module) {
|
||||||
const component = await importPluginModule(module);
|
const component = await importPluginModule(module);
|
||||||
if (!component.TemplateQueryCtrl) {
|
if (!component.TemplateQueryCtrl) {
|
||||||
@@ -28,9 +18,13 @@ function pluginTemplateQueryComponentLoader(datasourceSrv) {
|
|||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
link: async (scope, elem) => {
|
link: async (scope, elem) => {
|
||||||
const component = await loadComponent(scope.currentDatasource.meta.module);
|
const Component = await loadComponent(scope.currentDatasource.meta.module);
|
||||||
const props = { datasourceSrv, query: scope.current.query, isValid: scope.current.isValid };
|
const props = {
|
||||||
ReactDOM.render(WrapInProvider(component, props), elem[0]);
|
datasourceSrv,
|
||||||
|
query: scope.current.query,
|
||||||
|
onChange: scope.onQueryChange,
|
||||||
|
};
|
||||||
|
ReactDOM.render(<Component {...props} />, elem[0]);
|
||||||
scope.$on('$destroy', () => {
|
scope.$on('$destroy', () => {
|
||||||
ReactDOM.unmountComponentAtNode(elem[0]);
|
ReactDOM.unmountComponentAtNode(elem[0]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,15 +2,23 @@ import React, { PureComponent } from 'react';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
query: string;
|
query: string;
|
||||||
|
onChange: (c: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DefaultTemplateQueryCtrl extends PureComponent<Props> {
|
export default class DefaultTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = { value: props.query };
|
||||||
|
this.handleChange = this.handleChange.bind(this);
|
||||||
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
handleChange(event) {
|
||||||
console.log('componentDidMount');
|
this.setState({ value: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBlur(event) {
|
||||||
|
this.props.onChange(event.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -20,10 +28,10 @@ export default class DefaultTemplateQueryCtrl extends PureComponent<Props> {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="gf-form-input"
|
className="gf-form-input"
|
||||||
ng-model="current.query"
|
value={this.state.value}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
placeholder="metric name or tags query"
|
placeholder="metric name or tags query"
|
||||||
ng-model-onblur
|
|
||||||
ng-change="runQuery()"
|
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ export class VariableEditorCtrl {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.onQueryChange = value => {
|
||||||
|
$scope.current.query = value;
|
||||||
|
$scope.runQuery();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.edit = variable => {
|
$scope.edit = variable => {
|
||||||
$scope.current = variable;
|
$scope.current = variable;
|
||||||
$scope.currentIsNew = false;
|
$scope.currentIsNew = false;
|
||||||
@@ -173,8 +178,9 @@ export class VariableEditorCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.datasourceChanged = async () => {
|
$scope.datasourceChanged = async () => {
|
||||||
$scope.currentDatasource = await datasourceSrv.get($scope.current.datasource);
|
datasourceSrv.get($scope.current.datasource).then(ds => {
|
||||||
console.log($scope.currentDatasource);
|
$scope.currentDatasource = ds;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user