Logs: Always keep displayed fields with changed queries (#102493)

* Logs: Always keep displayed fields with changed queries

* Remove unused var
pull/102525/head
Sven Grossmann 4 months ago committed by GitHub
parent d9ca794b30
commit 5fc6d253f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      public/app/features/explore/Logs/Logs.tsx
  2. 27
      public/app/features/explore/Logs/utils/logs.test.ts
  3. 15
      public/app/features/explore/Logs/utils/logs.ts

@ -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: Props) => {
const cancelFlippingTimer = useRef<number | undefined>(undefined);
const toggleLegendRef = useRef<(name: string, mode: SeriesVisibilityChangeMode) => void>(() => {});
const topLogsRef = useRef<HTMLDivElement>(null);
const prevLogsQueries = usePrevious(logsQueries);
const tableHeight = getLogsTableHeight();
const styles = getStyles(theme, wrapLogMessage, tableHeight);
@ -409,20 +408,6 @@ const UnthemedLogs: React.FunctionComponent<Props> = (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) => {

@ -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);
});
});

@ -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;
};

Loading…
Cancel
Save