mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Datasource: updates PromExploreQueryEditor - rewrite to functional component * Datasource: updates PromQueryField - moves an extra field from children to the separate prop * Datasource: adds PromExploreExtraField * Datasource: updates PromExploreQueryEditor - fixes typo * Datasource: updates prometheus explore editor snapshots * Datasource: updates PromExploreExtraField export * Datasource: removes unnecessary div from PromExploreQueryEditor * Datasource: adds basic PromExploreExtraField snapshot test * Datasource: adds basic PromExploreQueryEditor test * Datasource: updates PromExploreQueryEditor snapshot to fix timezone issues * Datasource: updates PromExploreQueryEditor - onChangeQueryStep cleanup * Datasource: updates PromExploreQueryEditor test to check ExtraFieldElement render * Datasource: simplified PromExploreQueryEditor onStepChange method * Datasource: updates Prometheus module import * Datasource: updates PromExploreQueryEditor test * Datasource: updates PromExploreQueryEditor tests * Datasource: fixes PromExploreQueryEditor error on empty interval init * Datasource: adds a tooltip to PromExploreExtraField mounted in PromExploreQueryEditor * Datasource: updates PromExploreQueryEditor snapshots
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import React, { memo } from 'react';
|
|
|
|
// Types
|
|
import { ExploreQueryFieldProps } from '@grafana/data';
|
|
|
|
import { PrometheusDatasource } from '../datasource';
|
|
import { PromQuery, PromOptions } from '../types';
|
|
|
|
import PromQueryField from './PromQueryField';
|
|
import { PromExploreExtraField } from './PromExploreExtraField';
|
|
|
|
export type Props = ExploreQueryFieldProps<PrometheusDatasource, PromQuery, PromOptions>;
|
|
|
|
export function PromExploreQueryEditor(props: Props) {
|
|
const { query, data, datasource, history, onChange, onRunQuery } = props;
|
|
|
|
function onChangeQueryStep(value: string) {
|
|
const { query, onChange } = props;
|
|
const nextQuery = { ...query, interval: value };
|
|
onChange(nextQuery);
|
|
}
|
|
|
|
function onStepChange(e: React.SyntheticEvent<HTMLInputElement>) {
|
|
if (e.currentTarget.value !== query.interval) {
|
|
onChangeQueryStep(e.currentTarget.value);
|
|
}
|
|
}
|
|
|
|
function onReturnKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
|
|
if (e.key === 'Enter') {
|
|
onRunQuery();
|
|
}
|
|
}
|
|
|
|
return (
|
|
<PromQueryField
|
|
datasource={datasource}
|
|
query={query}
|
|
onRunQuery={onRunQuery}
|
|
onChange={onChange}
|
|
history={history}
|
|
data={data}
|
|
ExtraFieldElement={
|
|
<PromExploreExtraField
|
|
label={'Step'}
|
|
onChangeFunc={onStepChange}
|
|
onKeyDownFunc={onReturnKeyDown}
|
|
value={query.interval || ''}
|
|
hasTooltip={true}
|
|
tooltipContent={'Needs to be a valid time unit string, for example 5s, 1m, 3h, 1d, 1y'}
|
|
/>
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default memo(PromExploreQueryEditor);
|