From d18205ff2005266abd3821b7f8ff23ba8b5363f1 Mon Sep 17 00:00:00 2001 From: Douglas Thrift Date: Thu, 19 Aug 2021 11:24:01 -0700 Subject: [PATCH] Matchers: handle undefined with Is/Is not null (#38036) --- .../valueMatchers/nullMatchers.test.ts | 22 ++++++++++++++++--- .../matchers/valueMatchers/nullMatchers.ts | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.test.ts b/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.test.ts index 91b1f06bf49..ce2c0702190 100644 --- a/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.test.ts +++ b/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.test.ts @@ -9,7 +9,7 @@ describe('value null matcher', () => { fields: [ { name: 'temp', - values: [23, null, 10], + values: [23, null, 10, undefined], }, ], }), @@ -35,6 +35,14 @@ describe('value null matcher', () => { expect(matcher(valueIndex, field, frame, data)).toBeFalsy(); }); + + it('should match undefined values', () => { + const frame = data[0]; + const field = frame.fields[0]; + const valueIndex = 3; + + expect(matcher(valueIndex, field, frame, data)).toBeTruthy(); + }); }); describe('value not null matcher', () => { @@ -43,7 +51,7 @@ describe('value not null matcher', () => { fields: [ { name: 'temp', - values: [23, null, 10], + values: [23, null, 10, undefined], }, ], }), @@ -62,11 +70,19 @@ describe('value not null matcher', () => { expect(matcher(valueIndex, field, frame, data)).toBeTruthy(); }); - it('should match non-null values', () => { + it('should not match null values', () => { const frame = data[0]; const field = frame.fields[0]; const valueIndex = 1; expect(matcher(valueIndex, field, frame, data)).toBeFalsy(); }); + + it('should not match undefined values', () => { + const frame = data[0]; + const field = frame.fields[0]; + const valueIndex = 3; + + expect(matcher(valueIndex, field, frame, data)).toBeFalsy(); + }); }); diff --git a/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.ts b/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.ts index 42ce8b142bf..e3f19a68d97 100644 --- a/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.ts +++ b/packages/grafana-data/src/transformations/matchers/valueMatchers/nullMatchers.ts @@ -10,7 +10,7 @@ const isNullValueMatcher: ValueMatcherInfo = { get: () => { return (valueIndex: number, field: Field) => { const value = field.values.get(valueIndex); - return value === null; + return value == null; }; }, getOptionsDisplayText: () => { @@ -27,7 +27,7 @@ const isNotNullValueMatcher: ValueMatcherInfo = { get: () => { return (valueIndex: number, field: Field) => { const value = field.values.get(valueIndex); - return value !== null; + return value != null; }; }, getOptionsDisplayText: () => {