Annotations: check for null or undefined fields before conversion (#27712)

This commit is contained in:
Ryan McKinley 2020-09-22 10:45:26 -07:00 committed by GitHub
parent f6c91d1318
commit d46f33c34c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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,
},
]
`);
});

View File

@ -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;