mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
05b0bfafe4
* panel container menu gets new Explore entry (between Edit and Share) * entry only shows if datasource has `supportsExplore` set to true (set for Prometheus only for now) * click on Explore entry changes url to `/explore/state` via location provider * `state` is a JSON representation of the panel queries * datasources implement `getExploreState()` how to turn a panel config into explore initial state * Explore can parse the state and initialize its query expressions * ReactContainer now forwards route parameters as props to component * `pluginlist` and `singlestat` panel subclasses needed to be adapted because `panel_ctrl` now has the location provider as a property already
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
|
|
import QueryField from './QueryField';
|
|
|
|
class QueryRow extends PureComponent<any, any> {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
edited: false,
|
|
query: props.query || '',
|
|
};
|
|
}
|
|
|
|
handleChangeQuery = value => {
|
|
const { index, onChangeQuery } = this.props;
|
|
const { query } = this.state;
|
|
const edited = query !== value;
|
|
this.setState({ edited, query: value });
|
|
if (onChangeQuery) {
|
|
onChangeQuery(value, index);
|
|
}
|
|
};
|
|
|
|
handleClickAddButton = () => {
|
|
const { index, onAddQueryRow } = this.props;
|
|
if (onAddQueryRow) {
|
|
onAddQueryRow(index);
|
|
}
|
|
};
|
|
|
|
handleClickRemoveButton = () => {
|
|
const { index, onRemoveQueryRow } = this.props;
|
|
if (onRemoveQueryRow) {
|
|
onRemoveQueryRow(index);
|
|
}
|
|
};
|
|
|
|
handlePressEnter = () => {
|
|
const { onExecuteQuery } = this.props;
|
|
if (onExecuteQuery) {
|
|
onExecuteQuery();
|
|
}
|
|
};
|
|
|
|
render() {
|
|
const { request } = this.props;
|
|
const { edited, query } = this.state;
|
|
return (
|
|
<div className="query-row">
|
|
<div className="query-row-tools">
|
|
<button className="btn btn-small btn-inverse" onClick={this.handleClickAddButton}>
|
|
<i className="fa fa-plus" />
|
|
</button>
|
|
<button className="btn btn-small btn-inverse" onClick={this.handleClickRemoveButton}>
|
|
<i className="fa fa-minus" />
|
|
</button>
|
|
</div>
|
|
<div className="query-field-wrapper">
|
|
<QueryField
|
|
initialQuery={edited ? null : query}
|
|
onPressEnter={this.handlePressEnter}
|
|
onQueryChange={this.handleChangeQuery}
|
|
request={request}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default class QueryRows extends PureComponent<any, any> {
|
|
render() {
|
|
const { className = '', queries, ...handlers } = this.props;
|
|
return (
|
|
<div className={className}>
|
|
{queries.map((q, index) => <QueryRow key={q.key} index={index} query={q.query} {...handlers} />)}
|
|
</div>
|
|
);
|
|
}
|
|
}
|