mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
REACT UI: CollapsibleAlertPanel - value field more friendly human readable (scientific notation -> number) (#7426)
* value field more human readable Signed-off-by: kisc <nuno_kisc@hotmail.com> * fix typo Signed-off-by: Nuno Cardoso <nuno_kisc@hotmail.com> * add function convertSCToNumber Signed-off-by: nunokisc <nuno_kisc@hotmail.com> * add convertSCToNumber test Signed-off-by: nunokisc <nuno_kisc@hotmail.com> * normalize function name Signed-off-by: kisc <nuno_kisc@hotmail.com> * convertScientificNotationToNumber to parsePrometheusFloat Signed-off-by: kisc <nuno_kisc@hotmail.com>
This commit is contained in:
parent
153f859b74
commit
f97d2ddb6e
|
@ -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')();
|
||||
|
|
|
@ -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<CollapsibleAlertPanelProps> = ({ rule, showAnnot
|
|||
</h5>
|
||||
</td>
|
||||
<td>{alert.activeAt}</td>
|
||||
<td>{alert.value}</td>
|
||||
<td>{parsePrometheusFloat(alert.value)}</td>
|
||||
</tr>
|
||||
{showAnnotations && <Annotations annotations={alert.annotations} />}
|
||||
</Fragment>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue