Skip to content

Commit 3f88188

Browse files
authoredAug 26, 2024
Logs panel: update internal displayed fields when the prop changes (grafana#92418)
1 parent 490d6ba commit 3f88188

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎public/app/plugins/panel/logs/LogsPanel.test.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,33 @@ describe('LogsPanel', () => {
481481
expect(screen.getByText('logline text')).toBeInTheDocument();
482482
});
483483

484+
it('updates the provided fields instead of the log line', async () => {
485+
const { rerender, props } = setup({
486+
data: {
487+
series,
488+
},
489+
options: {
490+
showLabels: false,
491+
showTime: false,
492+
wrapLogMessage: false,
493+
showCommonLabels: false,
494+
prettifyLogMessage: false,
495+
sortOrder: LogsSortOrder.Descending,
496+
dedupStrategy: LogsDedupStrategy.none,
497+
enableLogDetails: true,
498+
onClickHideField: undefined,
499+
onClickShowField: undefined,
500+
},
501+
});
502+
503+
expect(await screen.findByRole('row')).toBeInTheDocument();
504+
expect(screen.getByText('logline text')).toBeInTheDocument();
505+
506+
rerender(<LogsPanel {...props} options={{ ...props.options, displayedFields: ['app'] }} />);
507+
508+
expect(screen.getByText('app=common_app')).toBeInTheDocument();
509+
});
510+
484511
it('enables the behavior with a default implementation', async () => {
485512
setup({
486513
data: {

‎public/app/plugins/panel/logs/LogsPanel.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css, cx } from '@emotion/css';
2-
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
2+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
33
import * as React from 'react';
44

55
import {
@@ -305,6 +305,12 @@ export const LogsPanel = ({
305305
[displayedFields]
306306
);
307307

308+
useEffect(() => {
309+
if (options.displayedFields) {
310+
setDisplayedFields(options.displayedFields);
311+
}
312+
}, [options.displayedFields]);
313+
308314
if (!data || logRows.length === 0) {
309315
return <PanelDataErrorView fieldConfig={fieldConfig} panelId={id} data={data} needsStringField />;
310316
}

0 commit comments

Comments
 (0)
Failed to load comments.