mirror of
https://github.com/grafana/grafana.git
synced 2025-02-04 12:41:12 -06:00
47f8717149
* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
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>></div>
|
|
) : inputPrefix === InputPrefix.LessThan ? (
|
|
<div><</div>
|
|
) : null;
|
|
|
|
return (
|
|
<Input
|
|
autoFocus={false}
|
|
placeholder="never"
|
|
width={10}
|
|
defaultValue={defaultValue}
|
|
onKeyDown={handleEnterKey}
|
|
onBlur={handleBlur}
|
|
prefix={prefix}
|
|
spellCheck={false}
|
|
/>
|
|
);
|
|
};
|