[APM] Cleanup: Remove isValidCoordinateValue
and getResponseTimeTooltipFormatter
(#87836)
This commit is contained in:
parent
cf086b678b
commit
7cd1fa3167
|
@ -8,11 +8,19 @@ import { Maybe } from '../../../typings/common';
|
||||||
import { NOT_AVAILABLE_LABEL } from '../../i18n';
|
import { NOT_AVAILABLE_LABEL } from '../../i18n';
|
||||||
import { isFiniteNumber } from '../is_finite_number';
|
import { isFiniteNumber } from '../is_finite_number';
|
||||||
|
|
||||||
export function asDecimal(value: number) {
|
export function asDecimal(value?: number | null) {
|
||||||
|
if (!isFiniteNumber(value)) {
|
||||||
|
return NOT_AVAILABLE_LABEL;
|
||||||
|
}
|
||||||
|
|
||||||
return numeral(value).format('0,0.0');
|
return numeral(value).format('0,0.0');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function asInteger(value: number) {
|
export function asInteger(value?: number | null) {
|
||||||
|
if (!isFiniteNumber(value)) {
|
||||||
|
return NOT_AVAILABLE_LABEL;
|
||||||
|
}
|
||||||
|
|
||||||
return numeral(value).format('0,0');
|
return numeral(value).format('0,0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,8 @@ function UnoptimizedManagedTable<T>(props: Props<T>) {
|
||||||
...toQuery(history.location.search),
|
...toQuery(history.location.search),
|
||||||
page: options.page.index,
|
page: options.page.index,
|
||||||
pageSize: options.page.size,
|
pageSize: options.page.size,
|
||||||
sortField: options.sort!.field,
|
sortField: options.sort?.field,
|
||||||
sortDirection: options.sort!.direction,
|
sortDirection: options.sort?.direction,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,7 +16,6 @@ import {
|
||||||
import { GenericMetricsChart } from '../../../../../server/lib/metrics/transform_metrics_chart';
|
import { GenericMetricsChart } from '../../../../../server/lib/metrics/transform_metrics_chart';
|
||||||
import { Maybe } from '../../../../../typings/common';
|
import { Maybe } from '../../../../../typings/common';
|
||||||
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
|
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
|
||||||
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
|
|
||||||
import { TimeseriesChart } from '../timeseries_chart';
|
import { TimeseriesChart } from '../timeseries_chart';
|
||||||
|
|
||||||
function getYTickFormatter(chart: GenericMetricsChart) {
|
function getYTickFormatter(chart: GenericMetricsChart) {
|
||||||
|
@ -33,15 +32,13 @@ function getYTickFormatter(chart: GenericMetricsChart) {
|
||||||
return (y: Maybe<number>) => asPercent(y || 0, 1);
|
return (y: Maybe<number>) => asPercent(y || 0, 1);
|
||||||
}
|
}
|
||||||
case 'time': {
|
case 'time': {
|
||||||
return (y: Maybe<number>) => asDuration(y);
|
return asDuration;
|
||||||
}
|
}
|
||||||
case 'integer': {
|
case 'integer': {
|
||||||
return (y: Maybe<number>) =>
|
return asInteger;
|
||||||
isValidCoordinateValue(y) ? asInteger(y) : y;
|
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return (y: Maybe<number>) =>
|
return asDecimal;
|
||||||
isValidCoordinateValue(y) ? asDecimal(y) : y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +60,7 @@ export function MetricsChart({ chart, fetchStatus }: Props) {
|
||||||
fetchStatus={fetchStatus}
|
fetchStatus={fetchStatus}
|
||||||
id={chart.key}
|
id={chart.key}
|
||||||
timeseries={chart.series}
|
timeseries={chart.series}
|
||||||
yLabelFormat={getYTickFormatter(chart) as (y: number) => string}
|
yLabelFormat={getYTickFormatter(chart)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,11 +4,7 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import { getResponseTimeTickFormatter, getMaxY } from './helper';
|
||||||
getResponseTimeTickFormatter,
|
|
||||||
getResponseTimeTooltipFormatter,
|
|
||||||
getMaxY,
|
|
||||||
} from './helper';
|
|
||||||
|
|
||||||
import { TimeSeries, Coordinate } from '../../../../../typings/timeseries';
|
import { TimeSeries, Coordinate } from '../../../../../typings/timeseries';
|
||||||
import {
|
import {
|
||||||
|
@ -25,35 +21,26 @@ describe('transaction chart helper', () => {
|
||||||
'1.0 min'
|
'1.0 min'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('formattes time tick in seconds', () => {
|
it('formattes time tick in seconds', () => {
|
||||||
const formatter = getDurationFormatter(toMicroseconds(11, 'seconds'));
|
const formatter = getDurationFormatter(toMicroseconds(11, 'seconds'));
|
||||||
const timeTickFormatter = getResponseTimeTickFormatter(formatter);
|
const timeTickFormatter = getResponseTimeTickFormatter(formatter);
|
||||||
expect(timeTickFormatter(toMicroseconds(6, 'seconds'))).toEqual('6.0 s');
|
expect(timeTickFormatter(toMicroseconds(6, 'seconds'))).toEqual('6.0 s');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getResponseTimeTooltipFormatter', () => {
|
|
||||||
const formatter = getDurationFormatter(toMicroseconds(11, 'minutes'));
|
|
||||||
const tooltipFormatter = getResponseTimeTooltipFormatter(formatter);
|
|
||||||
it("doesn't format invalid y coordinate", () => {
|
|
||||||
expect(tooltipFormatter({ x: 1, y: undefined })).toEqual('N/A');
|
|
||||||
expect(tooltipFormatter({ x: 1, y: null })).toEqual('N/A');
|
|
||||||
});
|
|
||||||
it('formattes tooltip in minutes', () => {
|
|
||||||
expect(
|
|
||||||
tooltipFormatter({ x: 1, y: toMicroseconds(60, 'seconds') })
|
|
||||||
).toEqual('1.0 min');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('getMaxY', () => {
|
describe('getMaxY', () => {
|
||||||
it('returns zero when empty time series', () => {
|
it('returns zero when empty time series', () => {
|
||||||
expect(getMaxY([])).toEqual(0);
|
expect(getMaxY([])).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns zero for invalid y coordinate', () => {
|
it('returns zero for invalid y coordinate', () => {
|
||||||
const timeSeries = ([
|
const timeSeries = ([
|
||||||
{ data: [{ x: 1 }, { x: 2 }, { x: 3, y: -1 }] },
|
{ data: [{ x: 1 }, { x: 2 }, { x: 3, y: -1 }] },
|
||||||
] as unknown) as Array<TimeSeries<Coordinate>>;
|
] as unknown) as Array<TimeSeries<Coordinate>>;
|
||||||
expect(getMaxY(timeSeries)).toEqual(0);
|
expect(getMaxY(timeSeries)).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the max y coordinate', () => {
|
it('returns the max y coordinate', () => {
|
||||||
const timeSeries = ([
|
const timeSeries = ([
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,23 +4,11 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
|
|
||||||
import { TimeFormatter } from '../../../../../common/utils/formatters';
|
|
||||||
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
|
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
|
||||||
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
|
import { TimeFormatter } from '../../../../../common/utils/formatters';
|
||||||
|
|
||||||
export function getResponseTimeTickFormatter(formatter: TimeFormatter) {
|
export function getResponseTimeTickFormatter(formatter: TimeFormatter) {
|
||||||
return (t: number) => {
|
return (t: number) => formatter(t).formatted;
|
||||||
return formatter(t).formatted;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getResponseTimeTooltipFormatter(formatter: TimeFormatter) {
|
|
||||||
return (coordinate: Coordinate) => {
|
|
||||||
return isValidCoordinateValue(coordinate.y)
|
|
||||||
? formatter(coordinate.y).formatted
|
|
||||||
: NOT_AVAILABLE_LABEL;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMaxY(timeSeries?: Array<TimeSeries<Coordinate>>) {
|
export function getMaxY(timeSeries?: Array<TimeSeries<Coordinate>>) {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
|
||||||
*/
|
|
||||||
import { Maybe } from '../../typings/common';
|
|
||||||
|
|
||||||
export const isValidCoordinateValue = (value: Maybe<number>): value is number =>
|
|
||||||
value !== null && value !== undefined;
|
|
Loading…
Reference in a new issue