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

[TSVB] Stop inserting zeroes for null series #90861

Merged
merged 9 commits into from
Feb 23, 2021
8 changes: 4 additions & 4 deletions src/plugins/vis_type_timeseries/common/get_last_value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import { isArray, last } from 'lodash';

const DEFAULT_VALUE = 0;
const extractValue = (data) => (data && data[1]) || null;
const DEFAULT_VALUE = '-';
const extractValue = (data) => (data && data[1]) ?? null;

export const getLastValue = (data, defaultValue = DEFAULT_VALUE) => {
if (!isArray(data)) {
return data || defaultValue;
return data ?? defaultValue;
}

return extractValue(last(data)) || defaultValue;
return extractValue(last(data)) ?? defaultValue;
};
14 changes: 11 additions & 3 deletions src/plugins/vis_type_timeseries/common/get_last_value.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ describe('getLastValue(data)', () => {
expect(getLastValue('foo')).toBe('foo');
});

test('should returns 0 as a value when not an array', () => {
expect(getLastValue(0)).toBe(0);
});

test('should returns the last value', () => {
expect(getLastValue([[1, 2]])).toBe(2);
});

test('should return 0 as a valid value', () => {
expect(getLastValue([[0, 0]])).toBe(0);
});

test('should returns the default value ', () => {
expect(getLastValue()).toBe(0);
expect(getLastValue()).toBe('-');
});

test('should returns 0 if second to last is not defined (default)', () => {
Expand All @@ -27,10 +35,10 @@ describe('getLastValue(data)', () => {
[1, null],
[2, null],
])
).toBe(0);
).toBe('-');
});

test('should allows to override the default value', () => {
expect(getLastValue(null, '-')).toBe('-');
expect(getLastValue(null, 'default')).toBe('default');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Gauge extends Component {
render() {
const { metric, type } = this.props;
const { scale, translateX, translateY } = this.state;
const value = (metric && getLastValue(metric.data)) || 0;
const value = metric && getLastValue(metric.data);
const max = (metric && getValueBy('max', metric.data)) || 1;
const formatter =
(metric && (metric.tickFormatter || metric.formatter)) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Metric extends Component {
const { metric, secondary } = this.props;
const { scale, translateX, translateY } = this.state;
const primaryFormatter = (metric && (metric.tickFormatter || metric.formatter)) || ((n) => n);
const primaryValue = primaryFormatter(getLastValue((metric && metric.data) || 0));
const primaryValue = primaryFormatter(getLastValue(metric && metric.data));
const styles = reactcss(
{
default: {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/dashboard/dashboard_filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('tsvb top n is filtered', async () => {
await dashboardExpect.tsvbTopNValuesExist(['0', '0']);
await dashboardExpect.tsvbTopNValuesExist(['-', '-']);
});

it('saved search is filtered', async () => {
Expand Down Expand Up @@ -172,7 +172,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('tsvb top n is filtered', async () => {
await dashboardExpect.tsvbTopNValuesExist(['0', '0']);
await dashboardExpect.tsvbTopNValuesExist(['-', '-']);
});

it('saved search is filtered', async () => {
Expand Down