Merge pull request #17365 from akshatsinha0/fix/old-ui-createExpressionLink

fix(react-app): correct createExpressionLink query for /graph links
This commit is contained in:
Julius Volz 2025-10-19 13:14:19 +02:00 committed by GitHub
commit 4c1355e14b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -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,

View File

@ -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`
);
});
});
});
});