signoz/frontend/src/utils/functionNameNormalizer.ts

38 lines
1.5 KiB
TypeScript
Raw Normal View History

fixes: includes fixes required in the new QB (#8675) * fix: removed unused code for querycontext (#8674) * Update frontend/src/utils/queryValidationUtils.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * feat: added tooltips in metric aggregations * feat: enabled legend enhancement for explorer pages and alert page * feat: updated the error state in explorer pages with new APIError * fix: cloned panel query shows previous query (#8681) * fix: cloned panel query shows previous query * chore: removed comments * chore: added null check * fix: added fix for auto run query in dashboard panel + trace view issue --------- Co-authored-by: Abhi Kumar <abhikumar@Mac.lan> * feat: added new SubstituteVars api and enable v5 for creating new alerts (#8683) * feat: added new SubstituteVars api and enable v5 for creating new alerts * feat: add warning notification for query response * feat: fixed failing test case * fix: metric histogram UI config state in edit mode * fix: fixed table columns getting duplicate data (#8685) * fix: added fix for conversion of QB function to filter expression. (#8684) * fix: added fix for QB filters for functions * chore: minor fix --------- Co-authored-by: SagarRajput-7 <162284829+SagarRajput-7@users.noreply.github.com> * feat: query builder fixes and enhancement (#8692) * feat: legend format fixes around single and multiple aggregation * feat: fixed table unit and metric units * feat: add fallbacks to columnWidth and columnUnits for old-dashboards * feat: fixed metric edit issue and having filter suggestion duplications * feat: fix and cleanup functions across product for v5 * chore: add tooltips with links to documentation (#8676) * fix: added fix for query validation and empty query error (#8694) * fix: added fix for selected columns being empty in logs explorer (#8709) * feat: added columnUnit changes for old dashboard migrations (#8706) * fix: fixed keyfetching logic (#8712) * chore: lint fix * fix: fixed logs explorer test * feat: fix type checks --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> Co-authored-by: SagarRajput-7 <sagar@signoz.io> Co-authored-by: Abhi Kumar <abhikumar@Mac.lan> Co-authored-by: SagarRajput-7 <162284829+SagarRajput-7@users.noreply.github.com> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2025-08-06 00:16:20 +05:30
import { QueryFunctionsTypes } from 'types/common/queryBuilder';
/**
* Normalizes function names from backend responses to match frontend expectations
* Backend returns lowercase function names (e.g., 'timeshift') while frontend expects camelCase (e.g., 'timeShift')
*/
export const normalizeFunctionName = (functionName: string): string => {
// Create a mapping from lowercase to expected camelCase function names
const functionNameMap: Record<string, string> = {
// Time shift function
timeshift: QueryFunctionsTypes.TIME_SHIFT,
// Other functions that might have case sensitivity issues
cutoffmin: QueryFunctionsTypes.CUTOFF_MIN,
cutoffmax: QueryFunctionsTypes.CUTOFF_MAX,
clampmin: QueryFunctionsTypes.CLAMP_MIN,
clampmax: QueryFunctionsTypes.CLAMP_MAX,
absolut: QueryFunctionsTypes.ABSOLUTE,
runningdiff: QueryFunctionsTypes.RUNNING_DIFF,
log2: QueryFunctionsTypes.LOG_2,
log10: QueryFunctionsTypes.LOG_10,
cumulativesum: QueryFunctionsTypes.CUMULATIVE_SUM,
ewma3: QueryFunctionsTypes.EWMA_3,
ewma5: QueryFunctionsTypes.EWMA_5,
ewma7: QueryFunctionsTypes.EWMA_7,
median3: QueryFunctionsTypes.MEDIAN_3,
median5: QueryFunctionsTypes.MEDIAN_5,
median7: QueryFunctionsTypes.MEDIAN_7,
anomaly: QueryFunctionsTypes.ANOMALY,
};
// Convert to lowercase for case-insensitive matching
const normalizedName = functionName.toLowerCase();
// Return the mapped function name or the original if no mapping exists
return functionNameMap[normalizedName] || functionName;
};