diff --git a/web/ui/react-app/src/pages/alerts/AlertContents.test.tsx b/web/ui/react-app/src/pages/alerts/AlertContents.test.tsx index 78b5a05513..e0832f99f3 100644 --- a/web/ui/react-app/src/pages/alerts/AlertContents.test.tsx +++ b/web/ui/react-app/src/pages/alerts/AlertContents.test.tsx @@ -30,7 +30,7 @@ describe('AlertsContent', () => { }); }); - it('toggles the "annotations" checkbox from false to true when clicked and back to true when clicked again', () => { + it('toggles the "annotations" checkbox from false to true when clicked and back to false when clicked again', () => { wrapper.find('#show-annotations-toggler').invoke('onClick')(); expect(wrapper.find('#show-annotations-toggler').prop('checked')).toBe(true); wrapper.find('#show-annotations-toggler').invoke('onClick')(); diff --git a/web/ui/react-app/src/pages/alerts/CollapsibleAlertPanel.tsx b/web/ui/react-app/src/pages/alerts/CollapsibleAlertPanel.tsx index 02d700e3a9..ee1f507f96 100644 --- a/web/ui/react-app/src/pages/alerts/CollapsibleAlertPanel.tsx +++ b/web/ui/react-app/src/pages/alerts/CollapsibleAlertPanel.tsx @@ -5,7 +5,7 @@ import { RuleStatus } from './AlertContents'; import { Rule } from '../../types/types'; import { faChevronDown, faChevronRight } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { createExpressionLink } from '../../utils/index'; +import { createExpressionLink, parsePrometheusFloat } from '../../utils/index'; interface CollapsibleAlertPanelProps { rule: Rule; @@ -78,7 +78,7 @@ const CollapsibleAlertPanel: FC = ({ rule, showAnnot {alert.activeAt} - {alert.value} + {parsePrometheusFloat(alert.value)} {showAnnotations && } diff --git a/web/ui/react-app/src/utils/index.ts b/web/ui/react-app/src/utils/index.ts index ebcf1b6243..53431bbfff 100644 --- a/web/ui/react-app/src/utils/index.ts +++ b/web/ui/react-app/src/utils/index.ts @@ -210,3 +210,11 @@ export const callAll = (...fns: Array<(...args: any) => void>) => (...args: any) // eslint-disable-next-line prefer-spread fns.filter(Boolean).forEach(fn => fn.apply(null, args)); }; + +export const parsePrometheusFloat = (value: string) => { + if (isNaN(Number(value))) { + return value; + } else { + return Number(value); + } +}; diff --git a/web/ui/react-app/src/utils/utils.test.ts b/web/ui/react-app/src/utils/utils.test.ts index a59f3373d5..3a906bc444 100644 --- a/web/ui/react-app/src/utils/utils.test.ts +++ b/web/ui/react-app/src/utils/utils.test.ts @@ -14,6 +14,7 @@ import { encodePanelOptionsToQueryString, parseOption, decodePanelOptionsFromQueryString, + parsePrometheusFloat, } from '.'; import { PanelType } from '../pages/graph/Panel'; @@ -237,5 +238,23 @@ describe('Utils', () => { expect(encodePanelOptionsToQueryString(panels)).toEqual(query); }); }); + + describe('parsePrometheusFloat', () => { + it('returns Inf when param is Inf', () => { + expect(parsePrometheusFloat('Inf')).toEqual('Inf'); + }); + it('returns +Inf when param is +Inf', () => { + expect(parsePrometheusFloat('+Inf')).toEqual('+Inf'); + }); + it('returns -Inf when param is -Inf', () => { + expect(parsePrometheusFloat('-Inf')).toEqual('-Inf'); + }); + it('returns 17 when param is 1.7e+01', () => { + expect(parsePrometheusFloat('1.7e+01')).toEqual(17); + }); + it('returns -17 when param is -1.7e+01', () => { + expect(parsePrometheusFloat('-1.7e+01')).toEqual(-17); + }); + }); }); });