Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Cleanup: Remove isValidCoordinateValue and getResponseTimeTooltipFormatter #87836

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions x-pack/plugins/apm/common/utils/formatters/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import { Maybe } from '../../../typings/common';
import { NOT_AVAILABLE_LABEL } from '../../i18n';
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');
}

export function asInteger(value: number) {
export function asInteger(value?: number | null) {
if (!isFiniteNumber(value)) {
return NOT_AVAILABLE_LABEL;
}

return numeral(value).format('0,0');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function UnoptimizedManagedTable<T>(props: Props<T>) {
...toQuery(history.location.search),
page: options.page.index,
pageSize: options.page.size,
sortField: options.sort!.field,
sortDirection: options.sort!.direction,
sortField: options.sort?.field,
sortDirection: options.sort?.direction,
}),
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { GenericMetricsChart } from '../../../../../server/lib/metrics/transform_metrics_chart';
import { Maybe } from '../../../../../typings/common';
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
import { TimeseriesChart } from '../timeseries_chart';

function getYTickFormatter(chart: GenericMetricsChart) {
Expand All @@ -33,15 +32,13 @@ function getYTickFormatter(chart: GenericMetricsChart) {
return (y: Maybe<number>) => asPercent(y || 0, 1);
}
case 'time': {
return (y: Maybe<number>) => asDuration(y);
return asDuration;
}
case 'integer': {
return (y: Maybe<number>) =>
isValidCoordinateValue(y) ? asInteger(y) : y;
return asInteger;
}
default: {
return (y: Maybe<number>) =>
isValidCoordinateValue(y) ? asDecimal(y) : y;
return asDecimal;
}
}
}
Expand All @@ -63,7 +60,7 @@ export function MetricsChart({ chart, fetchStatus }: Props) {
fetchStatus={fetchStatus}
id={chart.key}
timeseries={chart.series}
yLabelFormat={getYTickFormatter(chart) as (y: number) => string}
yLabelFormat={getYTickFormatter(chart)}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
getResponseTimeTickFormatter,
getResponseTimeTooltipFormatter,
getMaxY,
} from './helper';
import { getResponseTimeTickFormatter, getMaxY } from './helper';

import { TimeSeries, Coordinate } from '../../../../../typings/timeseries';
import {
Expand All @@ -25,35 +21,26 @@ describe('transaction chart helper', () => {
'1.0 min'
);
});

it('formattes time tick in seconds', () => {
const formatter = getDurationFormatter(toMicroseconds(11, 'seconds'));
const timeTickFormatter = getResponseTimeTickFormatter(formatter);
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', () => {
it('returns zero when empty time series', () => {
expect(getMaxY([])).toEqual(0);
});

it('returns zero for invalid y coordinate', () => {
const timeSeries = ([
{ data: [{ x: 1 }, { x: 2 }, { x: 3, y: -1 }] },
] as unknown) as Array<TimeSeries<Coordinate>>;
expect(getMaxY(timeSeries)).toEqual(0);
});

it('returns the max y coordinate', () => {
const timeSeries = ([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@
* 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 { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue';
import { TimeFormatter } from '../../../../../common/utils/formatters';

export function getResponseTimeTickFormatter(formatter: TimeFormatter) {
return (t: number) => {
return formatter(t).formatted;
};
}

export function getResponseTimeTooltipFormatter(formatter: TimeFormatter) {
return (coordinate: Coordinate) => {
return isValidCoordinateValue(coordinate.y)
? formatter(coordinate.y).formatted
: NOT_AVAILABLE_LABEL;
};
return (t: number) => formatter(t).formatted;
}

export function getMaxY(timeSeries?: Array<TimeSeries<Coordinate>>) {
Expand Down
9 changes: 0 additions & 9 deletions x-pack/plugins/apm/public/utils/isValidCoordinateValue.ts

This file was deleted.