Logs: Fix displaying the wrong field as body (#73025)

* fix displaying the wrong field as body

* fix test

* fix `getFirstFieldOfType` with non-present type
This commit is contained in:
Sven Grossmann
2023-08-08 12:02:30 +02:00
committed by GitHub
parent 3c4d2edb61
commit 533fae4c60
5 changed files with 65 additions and 5 deletions

View File

@@ -100,4 +100,22 @@ describe('FieldCache', () => {
expect(field!.index).toEqual(2);
});
});
describe('getFirstFieldOfType', () => {
let fieldCache: FieldCache;
beforeEach(() => {
const frame = toDataFrame({
fields: [
{ name: 'time', type: FieldType.time, values: [100, 200, 300] },
{ name: 'value', type: FieldType.number, values: [1, 2, 3] },
],
});
fieldCache = new FieldCache(frame);
});
it('should return undefined if type is not present', () => {
const field = fieldCache.getFirstFieldOfType(FieldType.string);
expect(field).toBeUndefined();
});
});
});

View File

@@ -59,7 +59,7 @@ export class FieldCache {
getFirstFieldOfType(type: FieldType, includeHidden = false): FieldWithIndex | undefined {
const fields = this.fieldByType[type];
const firstField = fields.find((field) => includeHidden || !field.config.custom?.hidden);
const firstField = fields?.find((field) => includeHidden || !field.config.custom?.hidden);
return firstField;
}