From 3ca2fff5c59c36d6df8ada542b967272b494627e Mon Sep 17 00:00:00 2001 From: ahmadshaheer Date: Mon, 21 Oct 2024 21:24:55 +0430 Subject: [PATCH] fix: send float number in args array in case of timeshift formula --- .../components/QueryFunctions/QueryFunctions.tsx | 9 ++++++++- .../QueryBuilder/components/QueryFunctions/utils.ts | 7 +++++++ frontend/src/types/api/queryBuilder/queryBuilderData.ts | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 frontend/src/container/QueryBuilder/components/QueryFunctions/utils.ts diff --git a/frontend/src/container/QueryBuilder/components/QueryFunctions/QueryFunctions.tsx b/frontend/src/container/QueryBuilder/components/QueryFunctions/QueryFunctions.tsx index 2192d82cf7..e322625bda 100644 --- a/frontend/src/container/QueryBuilder/components/QueryFunctions/QueryFunctions.tsx +++ b/frontend/src/container/QueryBuilder/components/QueryFunctions/QueryFunctions.tsx @@ -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); } diff --git a/frontend/src/container/QueryBuilder/components/QueryFunctions/utils.ts b/frontend/src/container/QueryBuilder/components/QueryFunctions/utils.ts new file mode 100644 index 0000000000..8c96f11c6a --- /dev/null +++ b/frontend/src/container/QueryBuilder/components/QueryFunctions/utils.ts @@ -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; +}; diff --git a/frontend/src/types/api/queryBuilder/queryBuilderData.ts b/frontend/src/types/api/queryBuilder/queryBuilderData.ts index 9cf8138e96..d15a41cec9 100644 --- a/frontend/src/types/api/queryBuilder/queryBuilderData.ts +++ b/frontend/src/types/api/queryBuilder/queryBuilderData.ts @@ -49,7 +49,7 @@ export type OrderByPayload = { export interface QueryFunctionProps { name: string; - args: string[]; + args: (string | number)[]; namedArgs?: Record; }