From d46f33c34ca6f61af31f3cb27f76248558e3b0c4 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 22 Sep 2020 10:45:26 -0700 Subject: [PATCH] Annotations: check for null or undefined fields before conversion (#27712) --- .../annotations/standardAnnotationSupport.test.ts | 12 +++++++++--- .../annotations/standardAnnotationSupport.ts | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/public/app/features/annotations/standardAnnotationSupport.test.ts b/public/app/features/annotations/standardAnnotationSupport.test.ts index 1c9a563d247..9db387f4ecf 100644 --- a/public/app/features/annotations/standardAnnotationSupport.test.ts +++ b/public/app/features/annotations/standardAnnotationSupport.test.ts @@ -5,9 +5,9 @@ describe('DataFrame to annotations', () => { test('simple conversion', () => { const frame = toDataFrame({ fields: [ - { type: FieldType.time, values: [1, 2, 3] }, - { name: 'first string field', values: ['t1', 't2', 't3'] }, - { name: 'tags', values: ['aaa,bbb', 'bbb,ccc', 'zyz'] }, + { type: FieldType.time, values: [1, 2, 3, 4, 5] }, + { name: 'first string field', values: ['t1', 't2', 't3', null, undefined] }, + { name: 'tags', values: ['aaa,bbb', 'bbb,ccc', 'zyz', null, undefined] }, ], }); @@ -37,6 +37,12 @@ describe('DataFrame to annotations', () => { "text": "t3", "time": 3, }, + Object { + "time": 4, + }, + Object { + "time": 5, + }, ] `); }); diff --git a/public/app/features/annotations/standardAnnotationSupport.ts b/public/app/features/annotations/standardAnnotationSupport.ts index 90fbab38c26..95bc71adefb 100644 --- a/public/app/features/annotations/standardAnnotationSupport.ts +++ b/public/app/features/annotations/standardAnnotationSupport.ts @@ -175,8 +175,8 @@ export function getAnnotationsFromData(data: DataFrame[], options?: AnnotationEv } } - if (v !== undefined) { - if (f.split) { + if (!(v === null || v === undefined)) { + if (v && f.split) { v = (v as string).split(','); } (anno as any)[f.key] = v;