From 5fc6d253f8df92dd08ed89afd3c1f881eb5509a5 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Thu, 20 Mar 2025 11:58:00 +0100 Subject: [PATCH] Logs: Always keep displayed fields with changed queries (#102493) * Logs: Always keep displayed fields with changed queries * Remove unused var --- public/app/features/explore/Logs/Logs.tsx | 17 +----------- .../features/explore/Logs/utils/logs.test.ts | 27 ------------------- .../app/features/explore/Logs/utils/logs.ts | 15 ----------- 3 files changed, 1 insertion(+), 58 deletions(-) delete mode 100644 public/app/features/explore/Logs/utils/logs.test.ts diff --git a/public/app/features/explore/Logs/Logs.tsx b/public/app/features/explore/Logs/Logs.tsx index 1ae6bcd7515..5bf10d2dac2 100644 --- a/public/app/features/explore/Logs/Logs.tsx +++ b/public/app/features/explore/Logs/Logs.tsx @@ -82,7 +82,7 @@ import { LogsMetaRow } from './LogsMetaRow'; import LogsNavigation from './LogsNavigation'; import { LogsTableWrap, getLogsTableHeight } from './LogsTableWrap'; import { LogsVolumePanelList } from './LogsVolumePanelList'; -import { canKeepDisplayedFields, SETTINGS_KEYS, visualisationTypeKey } from './utils/logs'; +import { SETTINGS_KEYS, visualisationTypeKey } from './utils/logs'; interface Props extends Themeable2 { width: number; @@ -225,7 +225,6 @@ const UnthemedLogs: React.FunctionComponent = (props: Props) => { const cancelFlippingTimer = useRef(undefined); const toggleLegendRef = useRef<(name: string, mode: SeriesVisibilityChangeMode) => void>(() => {}); const topLogsRef = useRef(null); - const prevLogsQueries = usePrevious(logsQueries); const tableHeight = getLogsTableHeight(); const styles = getStyles(theme, wrapLogMessage, tableHeight); @@ -409,20 +408,6 @@ const UnthemedLogs: React.FunctionComponent = (props: Props) => { ] ); - useEffect(() => { - if (!prevLogsQueries) { - // Initial load, ignore - return; - } - if (!canKeepDisplayedFields(logsQueries, prevLogsQueries)) { - setDisplayedFields([]); - updatePanelState({ - ...panelState?.logs, - displayedFields: [], - }); - } - }, [logsQueries, panelState?.logs, prevLogsQueries, updatePanelState]); - // actions const onLogRowHover = useCallback( (row?: LogRowModel) => { diff --git a/public/app/features/explore/Logs/utils/logs.test.ts b/public/app/features/explore/Logs/utils/logs.test.ts deleted file mode 100644 index 42883ff1ad4..00000000000 --- a/public/app/features/explore/Logs/utils/logs.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { DataQuery } from '@grafana/data'; - -import { canKeepDisplayedFields } from './logs'; - -describe('canKeepDisplayedFields', () => { - test('Returns false when passing no queries', () => { - expect(canKeepDisplayedFields(undefined, [])).toBe(false); - }); - - test('Returns false when some prev queries are undefined', () => { - const logQueries: DataQuery[] = [{ refId: 'A' }, { refId: 'B' }]; - const prevLogQueries = [{ refId: 'C' }]; - expect(canKeepDisplayedFields(logQueries, prevLogQueries)).toBe(false); - }); - - test('Returns false when some new queries are undefined', () => { - const logQueries: DataQuery[] = [{ refId: 'A' }]; - const prevLogQueries = [{ refId: 'C' }, { refId: 'B' }]; - expect(canKeepDisplayedFields(logQueries, prevLogQueries)).toBe(false); - }); - - test('Returns true when the queries exactly match', () => { - const logQueries: DataQuery[] = [{ refId: 'C' }, { refId: 'B' }]; - const prevLogQueries = [{ refId: 'C' }, { refId: 'B' }]; - expect(canKeepDisplayedFields(logQueries, prevLogQueries)).toBe(true); - }); -}); diff --git a/public/app/features/explore/Logs/utils/logs.ts b/public/app/features/explore/Logs/utils/logs.ts index edcaf0fc2c4..2aec91da980 100644 --- a/public/app/features/explore/Logs/utils/logs.ts +++ b/public/app/features/explore/Logs/utils/logs.ts @@ -1,6 +1,3 @@ -import { shallowCompare } from '@grafana/data'; -import { DataQuery } from '@grafana/schema'; - export const SETTINGS_KEYS = { showLabels: 'grafana.explore.logs.showLabels', showTime: 'grafana.explore.logs.showTime', @@ -11,15 +8,3 @@ export const SETTINGS_KEYS = { }; export const visualisationTypeKey = 'grafana.explore.logs.visualisationType'; - -export const canKeepDisplayedFields = (logsQueries: DataQuery[] | undefined, prevLogsQueries: DataQuery[]): boolean => { - if (!logsQueries) { - return false; - } - for (let i = 0; i < logsQueries.length; i++) { - if (!logsQueries[i] || !prevLogsQueries[i] || !shallowCompare(logsQueries[i], prevLogsQueries[i])) { - return false; - } - } - return true; -};