From 09c95714627d666fb73015f98945f04d5c85e70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Bedi?= Date: Tue, 8 Sep 2020 11:04:25 +0200 Subject: [PATCH] Explore: table result should not override display property (#27411) --- .../explore/utils/ResultProcessor.test.ts | 18 ++++++++++++++++++ .../features/explore/utils/ResultProcessor.ts | 12 +++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/public/app/features/explore/utils/ResultProcessor.test.ts b/public/app/features/explore/utils/ResultProcessor.test.ts index f095589031f..3778049d436 100644 --- a/public/app/features/explore/utils/ResultProcessor.test.ts +++ b/public/app/features/explore/utils/ResultProcessor.test.ts @@ -197,6 +197,24 @@ describe('ResultProcessor', () => { expect(result.fields[1].values.toArray()).toEqual([4, 5, 6]); expect(result.fields[2].values.toArray()).toEqual([4, 5, 6]); }); + + it('should not override fields display property when filled', () => { + const { resultProcessor, dataFrames } = testContext({ + dataFrames: [ + toDataFrame({ + name: 'A-series', + refId: 'A', + fields: [{ name: 'Text', type: FieldType.string, values: ['someText'] }], + }), + ], + }); + const displayFunctionMock = jest.fn(); + dataFrames[0].fields[0].display = displayFunctionMock; + + const data = resultProcessor.getTableResult(); + + expect(data?.fields[0].display).toBe(displayFunctionMock); + }); }); describe('when calling getLogsResult', () => { diff --git a/public/app/features/explore/utils/ResultProcessor.ts b/public/app/features/explore/utils/ResultProcessor.ts index 24f187333dc..c441c79d5f0 100644 --- a/public/app/features/explore/utils/ResultProcessor.ts +++ b/public/app/features/explore/utils/ResultProcessor.ts @@ -99,11 +99,13 @@ export class ResultProcessor { // set display processor for (const field of data.fields) { - field.display = getDisplayProcessor({ - field, - theme: config.theme, - timeZone: this.timeZone, - }); + field.display = + field.display ?? + getDisplayProcessor({ + field, + theme: config.theme, + timeZone: this.timeZone, + }); } return data;