From bac45b3aee6dd4d696cdaab93c765b8ff8efa78a Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Mon, 30 Jan 2023 11:11:18 +0100 Subject: [PATCH] [9.3.x] Logs: Fix stats not being updated when log results change #62317 (#62449) Logs: Fix stats not being updated when log results change (#62317) update stats in logdetails (cherry picked from commit ae8c61c0b2c2270b23d55576fec4205804d52cfb) --- .../logs/components/LogDetailsRow.tsx | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/public/app/features/logs/components/LogDetailsRow.tsx b/public/app/features/logs/components/LogDetailsRow.tsx index 763fd652fed..dbe4bd64e58 100644 --- a/public/app/features/logs/components/LogDetailsRow.tsx +++ b/public/app/features/logs/components/LogDetailsRow.tsx @@ -1,4 +1,5 @@ import { css, cx } from '@emotion/css'; +import { isEqual } from 'lodash'; import React, { PureComponent } from 'react'; import { Field, LinkModel, LogLabelStatsModel, GrafanaTheme2, LogRowModel, CoreApp } from '@grafana/data'; @@ -76,6 +77,12 @@ class UnThemedLogDetailsRow extends PureComponent { mouseOver: false, }; + componentDidUpdate() { + if (this.state.showFieldsStats) { + this.updateStats(); + } + } + showField = () => { const { onClickShowDetectedField, parsedKey, row } = this.props; if (onClickShowDetectedField) { @@ -128,13 +135,20 @@ class UnThemedLogDetailsRow extends PureComponent { }); }; + updateStats = () => { + const { getStats } = this.props; + const fieldStats = getStats(); + const fieldCount = fieldStats ? fieldStats.reduce((sum, stat) => sum + stat.count, 0) : 0; + if (!isEqual(this.state.fieldStats, fieldStats) || fieldCount !== this.state.fieldCount) { + this.setState({ fieldStats, fieldCount }); + } + }; + showStats = () => { - const { getStats, isLabel, row, app } = this.props; + const { isLabel, row, app } = this.props; const { showFieldsStats } = this.state; if (!showFieldsStats) { - const fieldStats = getStats(); - const fieldCount = fieldStats ? fieldStats.reduce((sum, stat) => sum + stat.count, 0) : 0; - this.setState({ fieldStats, fieldCount }); + this.updateStats(); } this.toggleFieldsStats();