LogDetailsRow: customize filters tooltip according to the current app (#89183)

* LogDetailsRow: customize filters tooltip

* Update tests
This commit is contained in:
Matias Chomicki 2024-06-13 19:54:33 +02:00 committed by GitHub
parent bd35fa10f1
commit 06c0ce4325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import {
FieldType,
createDataFrame,
DataFrameType,
CoreApp,
} from '@grafana/data';
import { LogDetails, Props } from './LogDetails';
@ -32,6 +33,7 @@ const setup = (propOverrides?: Partial<Props>, rowOverrides?: Partial<LogRowMode
onClickHideField: () => {},
theme,
styles,
app: CoreApp.Explore,
...(propOverrides || {}),
};

View File

@ -1,6 +1,8 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React, { ComponentProps } from 'react';
import { CoreApp } from '@grafana/data';
import { LogDetailsRow } from './LogDetailsRow';
import { createLogRow } from './__mocks__/logRow';
@ -20,6 +22,7 @@ const setup = (propOverrides?: Partial<Props>) => {
displayedFields: [],
row: createLogRow(),
disableActions: false,
app: CoreApp.Explore,
};
Object.assign(props, propOverrides);

View File

@ -261,6 +261,7 @@ class UnThemedLogDetailsRow extends PureComponent<Props, State> {
onClickFilterOutLabel,
disableActions,
row,
app,
} = this.props;
const { showFieldsStats, fieldStats, fieldCount } = this.state;
const styles = getStyles(theme);
@ -268,7 +269,7 @@ class UnThemedLogDetailsRow extends PureComponent<Props, State> {
const singleKey = parsedKeys == null ? false : parsedKeys.length === 1;
const singleVal = parsedValues == null ? false : parsedValues.length === 1;
const hasFilteringFunctionality = !disableActions && onClickFilterLabel && onClickFilterOutLabel;
const refIdTooltip = row.dataFrame?.refId ? ` in query ${row.dataFrame?.refId}` : '';
const refIdTooltip = app === CoreApp.Explore && row.dataFrame?.refId ? ` in query ${row.dataFrame?.refId}` : '';
const isMultiParsedValueWithNoContent =
!singleVal && parsedValues != null && !parsedValues.every((val) => val === '');

View File

@ -374,9 +374,9 @@ describe('LogsPanel', () => {
expect(await screen.findByRole('row')).toBeInTheDocument();
await userEvent.click(screen.getByText('logline text'));
await userEvent.click(screen.getByLabelText('Filter for value in query A'));
await userEvent.click(screen.getByLabelText('Filter for value'));
expect(filterForMock).toHaveBeenCalledTimes(1);
await userEvent.click(screen.getByLabelText('Filter out value in query A'));
await userEvent.click(screen.getByLabelText('Filter out value'));
expect(filterOutMock).toHaveBeenCalledTimes(1);
expect(isFilterLabelActiveMock).toHaveBeenCalledTimes(1);
@ -399,8 +399,8 @@ describe('LogsPanel', () => {
await userEvent.click(screen.getByText('logline text'));
expect(screen.queryByLabelText('Filter for value in query A')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Filter out value in query A')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Filter for value')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Filter out value')).not.toBeInTheDocument();
});
it('shows the controls if onAddAdHocFilter is defined', async () => {
jest.spyOn(grafanaUI, 'usePanelContext').mockReturnValue({
@ -421,8 +421,8 @@ describe('LogsPanel', () => {
expect(await screen.findByText('common_app')).toBeInTheDocument();
expect(screen.getByLabelText('Filter for value in query A')).toBeInTheDocument();
expect(screen.getByLabelText('Filter out value in query A')).toBeInTheDocument();
expect(screen.getByLabelText('Filter for value')).toBeInTheDocument();
expect(screen.getByLabelText('Filter out value')).toBeInTheDocument();
});
});
});