mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user