fix: send float number in args array in case of timeshift formula

This commit is contained in:
ahmadshaheer 2024-10-21 21:24:55 +04:30 committed by Yunus M
parent ef3a9adb48
commit 3ca2fff5c5
3 changed files with 16 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import {
import { DataSource, QueryFunctionsTypes } from 'types/common/queryBuilder';
import Function from './Function';
import { toFloat64 } from './utils';
const defaultMetricFunctionStruct: QueryFunctionProps = {
name: QueryFunctionsTypes.CUTOFF_MIN,
@ -158,7 +159,13 @@ export default function QueryFunctions({
const updateFunctions = cloneDeep(functions);
if (updateFunctions && updateFunctions.length > 0 && updateFunctions[index]) {
updateFunctions[index].args = [value];
updateFunctions[index].args = [
// timeShift expects a float64 value, so we convert the string to a number
// For other functions, we keep the value as a string
updateFunctions[index].name === QueryFunctionsTypes.TIME_SHIFT
? toFloat64(value)
: value,
];
setFunctions(updateFunctions);
onChange(updateFunctions);
}

View File

@ -0,0 +1,7 @@
export const toFloat64 = (value: string): number => {
const parsed = parseFloat(value);
if (!Number.isFinite(parsed)) {
console.error(`Invalid value for timeshift. value: ${value}`);
}
return parsed;
};

View File

@ -49,7 +49,7 @@ export type OrderByPayload = {
export interface QueryFunctionProps {
name: string;
args: string[];
args: (string | number)[];
namedArgs?: Record<string, any>;
}