Skip to content

Commit 47e4c8b

Browse files
committed
Remove isValidCoordinateValue and getResponseTimeTooltipFormatter
1 parent 8a21b64 commit 47e4c8b

6 files changed

Lines changed: 23 additions & 52 deletions

File tree

x-pack/plugins/apm/common/utils/formatters/formatters.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ import { Maybe } from '../../../typings/common';
88
import { NOT_AVAILABLE_LABEL } from '../../i18n';
99
import { isFiniteNumber } from '../is_finite_number';
1010

11-
export function asDecimal(value: number) {
11+
export function asDecimal(value?: number | null) {
12+
if (!isFiniteNumber(value)) {
13+
return NOT_AVAILABLE_LABEL;
14+
}
15+
1216
return numeral(value).format('0,0.0');
1317
}
1418

15-
export function asInteger(value: number) {
19+
export function asInteger(value?: number | null) {
20+
if (!isFiniteNumber(value)) {
21+
return NOT_AVAILABLE_LABEL;
22+
}
23+
1624
return numeral(value).format('0,0');
1725
}
1826

x-pack/plugins/apm/public/components/shared/ManagedTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ function UnoptimizedManagedTable<T>(props: Props<T>) {
102102
...toQuery(history.location.search),
103103
page: options.page.index,
104104
pageSize: options.page.size,
105-
sortField: options.sort!.field,
106-
sortDirection: options.sort!.direction,
105+
sortField: options.sort?.field,
106+
sortDirection: options.sort?.direction,
107107
}),
108108
});
109109
},

x-pack/plugins/apm/public/components/shared/charts/metrics_chart/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
import { GenericMetricsChart } from '../../../../../server/lib/metrics/transform_metrics_chart';
1717
import { Maybe } from '../../../../../typings/common';
1818
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
19-
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
2019
import { TimeseriesChart } from '../timeseries_chart';
2120

2221
function getYTickFormatter(chart: GenericMetricsChart) {
@@ -33,15 +32,13 @@ function getYTickFormatter(chart: GenericMetricsChart) {
3332
return (y: Maybe<number>) => asPercent(y || 0, 1);
3433
}
3534
case 'time': {
36-
return (y: Maybe<number>) => asDuration(y);
35+
return asDuration;
3736
}
3837
case 'integer': {
39-
return (y: Maybe<number>) =>
40-
isValidCoordinateValue(y) ? asInteger(y) : y;
38+
return asInteger;
4139
}
4240
default: {
43-
return (y: Maybe<number>) =>
44-
isValidCoordinateValue(y) ? asDecimal(y) : y;
41+
return asDecimal;
4542
}
4643
}
4744
}
@@ -63,7 +60,7 @@ export function MetricsChart({ chart, fetchStatus }: Props) {
6360
fetchStatus={fetchStatus}
6461
id={chart.key}
6562
timeseries={chart.series}
66-
yLabelFormat={getYTickFormatter(chart) as (y: number) => string}
63+
yLabelFormat={getYTickFormatter(chart)}
6764
/>
6865
</>
6966
);

x-pack/plugins/apm/public/components/shared/charts/transaction_charts/helper.test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import {
8-
getResponseTimeTickFormatter,
9-
getResponseTimeTooltipFormatter,
10-
getMaxY,
11-
} from './helper';
7+
import { getResponseTimeTickFormatter, getMaxY } from './helper';
128

139
import { TimeSeries, Coordinate } from '../../../../../typings/timeseries';
1410
import {
@@ -25,35 +21,26 @@ describe('transaction chart helper', () => {
2521
'1.0 min'
2622
);
2723
});
24+
2825
it('formattes time tick in seconds', () => {
2926
const formatter = getDurationFormatter(toMicroseconds(11, 'seconds'));
3027
const timeTickFormatter = getResponseTimeTickFormatter(formatter);
3128
expect(timeTickFormatter(toMicroseconds(6, 'seconds'))).toEqual('6.0 s');
3229
});
3330
});
34-
describe('getResponseTimeTooltipFormatter', () => {
35-
const formatter = getDurationFormatter(toMicroseconds(11, 'minutes'));
36-
const tooltipFormatter = getResponseTimeTooltipFormatter(formatter);
37-
it("doesn't format invalid y coordinate", () => {
38-
expect(tooltipFormatter({ x: 1, y: undefined })).toEqual('N/A');
39-
expect(tooltipFormatter({ x: 1, y: null })).toEqual('N/A');
40-
});
41-
it('formattes tooltip in minutes', () => {
42-
expect(
43-
tooltipFormatter({ x: 1, y: toMicroseconds(60, 'seconds') })
44-
).toEqual('1.0 min');
45-
});
46-
});
31+
4732
describe('getMaxY', () => {
4833
it('returns zero when empty time series', () => {
4934
expect(getMaxY([])).toEqual(0);
5035
});
36+
5137
it('returns zero for invalid y coordinate', () => {
5238
const timeSeries = ([
5339
{ data: [{ x: 1 }, { x: 2 }, { x: 3, y: -1 }] },
5440
] as unknown) as Array<TimeSeries<Coordinate>>;
5541
expect(getMaxY(timeSeries)).toEqual(0);
5642
});
43+
5744
it('returns the max y coordinate', () => {
5845
const timeSeries = ([
5946
{

x-pack/plugins/apm/public/components/shared/charts/transaction_charts/helper.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
8-
import { TimeFormatter } from '../../../../../common/utils/formatters';
97
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
10-
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
8+
import { TimeFormatter } from '../../../../../common/utils/formatters';
119

1210
export function getResponseTimeTickFormatter(formatter: TimeFormatter) {
13-
return (t: number) => {
14-
return formatter(t).formatted;
15-
};
16-
}
17-
18-
export function getResponseTimeTooltipFormatter(formatter: TimeFormatter) {
19-
return (coordinate: Coordinate) => {
20-
return isValidCoordinateValue(coordinate.y)
21-
? formatter(coordinate.y).formatted
22-
: NOT_AVAILABLE_LABEL;
23-
};
11+
return (t: number) => formatter(t).formatted;
2412
}
2513

2614
export function getMaxY(timeSeries?: Array<TimeSeries<Coordinate>>) {

x-pack/plugins/apm/public/utils/isValidCoordinateValue.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)