grafana/public/app/plugins/datasource/prometheus/components/PromExploreQueryEditor.tsx
Lukas Siatka 1de24cc929 Explore: adds PrometheusExploreQueryEditor (#20195)
* Explore: updates prom query field styles with flex-grow

* Explore: adds prometheus explore query editor

* Explore: updates step input width in prom explore query editor

* Explore: updates prom explore query editor step field input placeholder to auto

* Explore: updates prom explore query editor to include history

* Explore: updates prom explore query editor, removes unused lodash import

* Explore: updates step spacing in prom explore query editor

* Explore: updates prom explore query editor - moves logic to query field

* Explore: updates prom query field - adds step field with conditional rendering

* Explore: updates promql cheat sheet with step description

* Explore: updates prom cheat sheet  step description

* Explore: updates styles - adds query row break class

* Explore: moves back step markup to PromExploreQueryEditor
2019-12-23 11:42:31 +01:00

86 lines
2.2 KiB
TypeScript

import React, { PureComponent } from 'react';
// Types
import { ExploreQueryFieldProps } from '@grafana/data';
import { FormLabel } from '@grafana/ui';
import { PrometheusDatasource } from '../datasource';
import { PromQuery, PromOptions } from '../types';
import PromQueryField from './PromQueryField';
export type Props = ExploreQueryFieldProps<PrometheusDatasource, PromQuery, PromOptions>;
interface State {
interval: string;
}
export class PromExploreQueryEditor extends PureComponent<Props, State> {
// Query target to be modified and used for queries
query: PromQuery;
constructor(props: Props) {
super(props);
const { query } = props;
this.query = query;
// Query target properties that are fully controlled inputs
this.state = {
// Fully controlled text inputs
interval: query.interval,
};
}
onFieldChange = (query: PromQuery, override?: any) => {
this.query.expr = query.expr;
};
onIntervalChange = (e: React.SyntheticEvent<HTMLInputElement>) => {
const interval = e.currentTarget.value;
this.query.interval = interval;
this.setState({ interval });
};
onRunQuery = () => {
const { query } = this;
this.props.onChange(query);
this.props.onRunQuery();
};
onReturnKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
this.onRunQuery();
}
};
render() {
const { datasource, query, data, history } = this.props;
const { interval } = this.state;
return (
<div className="gf-form-inline">
<PromQueryField
datasource={datasource}
query={query}
onRunQuery={this.onRunQuery}
onChange={this.onFieldChange}
history={history}
data={data}
>
<div className="gf-form-inline explore-input--ml">
<div className="gf-form">
<FormLabel width={4}>Step</FormLabel>
<input
type="text"
className="gf-form-input width-6"
placeholder={'auto'}
onChange={this.onIntervalChange}
onKeyDown={this.onReturnKeyDown}
value={interval}
/>
</div>
</div>
</PromQueryField>
</div>
);
}
}