* [TSVB] Stop inserting zeroes for null series * Replace empty default value with hyphen * Stop treating 0 as false * Fix test cases Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
8fa702c9f6
commit
7b835f980c
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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)', () => {
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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)) ||
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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 () => {
|
||||
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in a new issue