mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Tempo: Fix NaN value using fallback (#81150)
This commit is contained in:
parent
f726ea1e52
commit
0434f191fe
@ -13,6 +13,19 @@ interface Props {
|
||||
query: Partial<TempoQuery> & TempoQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string value to integer. If the conversion fails, for example because we are prosessing an empty value for
|
||||
* a field, return a fallback (default) value.
|
||||
*
|
||||
* @param val the value to be parsed to an integer
|
||||
* @param fallback the fallback value
|
||||
* @returns the converted value or the fallback value if the conversion fails
|
||||
*/
|
||||
const parseIntWithFallback = (val: string, fallback: number) => {
|
||||
const parsed = parseInt(val, 10);
|
||||
return isNaN(parsed) ? fallback : parsed;
|
||||
};
|
||||
|
||||
export const TempoQueryBuilderOptions = React.memo<Props>(({ onChange, query }) => {
|
||||
if (!query.hasOwnProperty('limit')) {
|
||||
query.limit = DEFAULT_LIMIT;
|
||||
@ -23,10 +36,10 @@ export const TempoQueryBuilderOptions = React.memo<Props>(({ onChange, query })
|
||||
}
|
||||
|
||||
const onLimitChange = (e: React.FormEvent<HTMLInputElement>) => {
|
||||
onChange({ ...query, limit: parseInt(e.currentTarget.value, 10) });
|
||||
onChange({ ...query, limit: parseIntWithFallback(e.currentTarget.value, DEFAULT_LIMIT) });
|
||||
};
|
||||
const onSpssChange = (e: React.FormEvent<HTMLInputElement>) => {
|
||||
onChange({ ...query, spss: parseInt(e.currentTarget.value, 10) });
|
||||
onChange({ ...query, spss: parseIntWithFallback(e.currentTarget.value, DEFAULT_SPSS) });
|
||||
};
|
||||
const onTableTypeChange = (val: SearchTableType) => {
|
||||
onChange({ ...query, tableType: val });
|
||||
|
Loading…
Reference in New Issue
Block a user