From ce175905a5ec7e945b99d8420e6075790e6f27e3 Mon Sep 17 00:00:00 2001 From: Akshat Sinha Date: Sun, 19 Oct 2025 04:01:53 +0530 Subject: [PATCH] fix(react-app): correct createExpressionLink query for /graph links Ensure params are joined with & and remove trailing dot to restore working links from Alerts/Rules to Graph. Signed-off-by: Akshat Sinha --- web/ui/react-app/src/utils/index.ts | 2 +- web/ui/react-app/src/utils/utils.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/web/ui/react-app/src/utils/index.ts b/web/ui/react-app/src/utils/index.ts index 08111b1580..441431e3a9 100644 --- a/web/ui/react-app/src/utils/index.ts +++ b/web/ui/react-app/src/utils/index.ts @@ -270,7 +270,7 @@ export const getQueryParam = (key: string): string => { export const createExpressionLink = (expr: string): string => { return `../graph?g0.expr=${encodeURIComponent(expr)}&g0.tab=1&g0.display_mode=${ GraphDisplayMode.Lines - }&g0.show_exemplars=0.g0.range_input=1h.`; + }&g0.show_exemplars=0&g0.range_input=1h`; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any, diff --git a/web/ui/react-app/src/utils/utils.test.ts b/web/ui/react-app/src/utils/utils.test.ts index 4b14465816..93174df87b 100644 --- a/web/ui/react-app/src/utils/utils.test.ts +++ b/web/ui/react-app/src/utils/utils.test.ts @@ -15,6 +15,7 @@ import { parseOption, decodePanelOptionsFromQueryString, parsePrometheusFloat, + createExpressionLink, } from '.'; import { GraphDisplayMode, PanelType } from '../pages/graph/Panel'; @@ -332,5 +333,17 @@ describe('Utils', () => { expect(parsePrometheusFloat('-1.7e+01')).toEqual(-17); }); }); + describe('createExpressionLink',()=>{ + it('<....>builds link',()=>{ + expect(createExpressionLink('up')).toEqual( + `../graph?g0.expr=up&g0.tab=1&g0.display_mode=${GraphDisplayMode.Lines}&g0.show_exemplars=0&g0.range_input=1h` + ); + }); + it('url-encodes PromQL',() =>{ + expect(createExpressionLink('ALERTS{alertname="HighCPU"}')).toEqual( + `../graph?g0.expr=ALERTS%7Balertname%3D%22High%20CPU%22%7D&g0.tab=1&g0.display_mode=${GraphDisplayMode.Lines}&g0.show_exemplars=0&g0.range_input=1h` + ); + }); + }); }); });