The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/panel/timeseries/NullsThresholdInput.tsx

69 lines
1.6 KiB

import * as React from 'react';
import { rangeUtil } from '@grafana/data';
import { Input } from '@grafana/ui';
export enum InputPrefix {
LessThan = 'lessthan',
GreaterThan = 'greaterthan',
}
type Props = {
value: number;
onChange: (value?: number | boolean | undefined) => void;
inputPrefix?: InputPrefix;
isTime: boolean;
};
export const NullsThresholdInput = ({ value, onChange, inputPrefix, isTime }: Props) => {
let defaultValue = rangeUtil.secondsToHms(value / 1000);
if (!isTime) {
defaultValue = '10';
}
const checkAndUpdate = (txt: string) => {
let val: boolean | number = false;
if (txt) {
try {
if (isTime && rangeUtil.isValidTimeSpan(txt)) {
val = rangeUtil.intervalToMs(txt);
} else {
val = Number(txt);
}
} catch (err) {
console.warn('ERROR', err);
}
}
onChange(val);
};
const handleEnterKey = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key !== 'Enter') {
return;
}
checkAndUpdate(e.currentTarget.value);
};
const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
checkAndUpdate(e.currentTarget.value);
};
const prefix =
inputPrefix === InputPrefix.GreaterThan ? (
<div>&gt;</div>
) : inputPrefix === InputPrefix.LessThan ? (
<div>&lt;</div>
) : null;
return (
<Input
autoFocus={false}
placeholder="never"
width={10}
defaultValue={defaultValue}
onKeyDown={handleEnterKey}
onBlur={handleBlur}
prefix={prefix}
spellCheck={false}
/>
);
};