Log Labels: add support to disable labels for unique labels (#97567)

* LogLabels: add support to disable labels for unique labels

* LogRow: disable tooltip for unique labels
This commit is contained in:
Matias Chomicki 2024-12-06 16:15:25 +00:00 committed by GitHub
parent 1ff0978efe
commit 8243e030b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import { render, screen } from '@testing-library/react'; import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { LogLabels, LogLabelsList } from './LogLabels'; import { LogLabels, LogLabelsList } from './LogLabels';
@ -23,6 +24,16 @@ describe('<LogLabels />', () => {
expect(screen.queryByText('foo=bar')).toBeInTheDocument(); expect(screen.queryByText('foo=bar')).toBeInTheDocument();
expect(screen.queryByText(/baz/)).not.toBeInTheDocument(); expect(screen.queryByText(/baz/)).not.toBeInTheDocument();
}); });
it('shows a tooltip', async () => {
render(<LogLabels labels={{ foo: 'bar' }} />);
await userEvent.hover(screen.getByText('foo=bar'));
expect(screen.getAllByText('foo=bar')).toHaveLength(2);
});
it('disables the tooltip', async () => {
render(<LogLabels labels={{ foo: 'bar' }} addTooltip={false} />);
await userEvent.hover(screen.getByText('foo=bar'));
expect(screen.getAllByText('foo=bar')).toHaveLength(1);
});
}); });
describe('<LogLabelsList />', () => { describe('<LogLabelsList />', () => {

View File

@ -10,15 +10,16 @@ const HIDDEN_LABELS = ['detected_level', 'level', 'lvl', 'filename'];
interface Props { interface Props {
labels: Labels; labels: Labels;
emptyMessage?: string; emptyMessage?: string;
addTooltip?: boolean;
} }
export const LogLabels = memo(({ labels, emptyMessage }: Props) => { export const LogLabels = memo(({ labels, emptyMessage, addTooltip = true }: Props) => {
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
const displayLabels = useMemo( const displayLabels = useMemo(
() => () =>
Object.keys(labels) Object.keys(labels)
.filter((label) => !label.startsWith('_') && !HIDDEN_LABELS.includes(label)) .filter((label) => !label.startsWith('_') && !HIDDEN_LABELS.includes(label) && labels[label])
.sort(), .map((label) => `${label}=${labels[label]}`),
[labels] [labels]
); );
@ -32,16 +33,15 @@ export const LogLabels = memo(({ labels, emptyMessage }: Props) => {
return ( return (
<span className={cx([styles.logsLabels])}> <span className={cx([styles.logsLabels])}>
{displayLabels.map((label) => { {displayLabels.map((labelValue) => {
const value = labels[label]; return addTooltip ? (
if (!value) { <Tooltip content={labelValue} key={labelValue} placement="top">
return;
}
const labelValue = `${label}=${value}`;
return (
<Tooltip content={labelValue} key={label} placement="top">
<LogLabel styles={styles}>{labelValue}</LogLabel> <LogLabel styles={styles}>{labelValue}</LogLabel>
</Tooltip> </Tooltip>
) : (
<LogLabel styles={styles} tooltip={labelValue} key={labelValue}>
{labelValue}
</LogLabel>
); );
})} })}
</span> </span>

View File

@ -281,7 +281,7 @@ class UnThemedLogRow extends PureComponent<Props, State> {
{showTime && <td className={styles.logsRowLocalTime}>{this.renderTimeStamp(row.timeEpochMs)}</td>} {showTime && <td className={styles.logsRowLocalTime}>{this.renderTimeStamp(row.timeEpochMs)}</td>}
{showLabels && processedRow.uniqueLabels && ( {showLabels && processedRow.uniqueLabels && (
<td className={styles.logsRowLabels}> <td className={styles.logsRowLabels}>
<LogLabels labels={processedRow.uniqueLabels} /> <LogLabels labels={processedRow.uniqueLabels} addTooltip={false} />
</td> </td>
)} )}
{displayedFields && displayedFields.length > 0 ? ( {displayedFields && displayedFields.length > 0 ? (