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

[Custom threshold] Fix not showing threshold line in lens preview #171970

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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Comparator, Aggregators } from '../../../../../common/custom_threshold_
import { useKibana } from '../../../../utils/kibana_react';
import { kibanaStartMock } from '../../../../utils/kibana_react.mock';
import { MetricExpression } from '../../types';
import { PreviewChart } from './preview_chart';
import { getBufferThreshold, PreviewChart } from './preview_chart';

jest.mock('../../../../utils/kibana_react');

Expand Down Expand Up @@ -70,3 +70,18 @@ describe('Preview chart', () => {
expect(wrapper.find('[data-test-subj="thresholdRuleNoChartData"]').exists()).toBeTruthy();
});
});

describe('getBufferThreshold', () => {
const testData = [
{ threshold: undefined, buffer: '0.00' },
{ threshold: 0.1, buffer: '0.12' },
{ threshold: 0.01, buffer: '0.02' },
{ threshold: 0.001, buffer: '0.01' },
{ threshold: 0.00098, buffer: '0.01' },
{ threshold: 130, buffer: '143.00' },
];

it.each(testData)('getBufferThreshold($threshold) = $buffer', ({ threshold, buffer }) => {
expect(getBufferThreshold(threshold)).toBe(buffer);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const getOperationTypeFromRuleAggType = (aggType: AggType): OperationType => {
return aggType;
};

export const getBufferThreshold = (threshold?: number): string =>
(Math.ceil((threshold || 0) * 1.1 * 100) / 100).toFixed(2).toString();

export function PreviewChart({
metricExpression,
dataView,
Expand Down Expand Up @@ -147,7 +150,7 @@ export function PreviewChart({
const bufferRefLine = new XYReferenceLinesLayer({
data: [
{
value: Math.round((threshold[0] || 0) * 1.1).toString(),
value: getBufferThreshold(threshold[0]),
color: 'transparent',
fill,
format,
Expand Down
Loading