From 01755608dbf27bc67f050b243a726c8b7f2265d4 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Wed, 13 Sep 2023 19:45:49 +0200 Subject: [PATCH] LogDetails: Fix copy button visibility (#74663) * change css classname * remove class * Log details row: refactor style variable and add class to copy container * Log details row: refactor test * Prettier * Update test * Use toBeVisible * Remove unsused import * Update public/app/features/logs/components/LogDetailsRow.test.tsx * remove `cx` * fix lint --------- Co-authored-by: Matias Chomicki --- .../logs/components/LogDetailsRow.test.tsx | 11 ++++++++++- .../features/logs/components/LogDetailsRow.tsx | 15 +++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/public/app/features/logs/components/LogDetailsRow.test.tsx b/public/app/features/logs/components/LogDetailsRow.test.tsx index 3745df514f7..55e01e99569 100644 --- a/public/app/features/logs/components/LogDetailsRow.test.tsx +++ b/public/app/features/logs/components/LogDetailsRow.test.tsx @@ -1,4 +1,4 @@ -import { screen, render, fireEvent } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; import React, { ComponentProps } from 'react'; import { LogRowModel } from '@grafana/data'; @@ -117,4 +117,13 @@ describe('LogDetailsRow', () => { expect(screen.getByTestId('logLabelStats')).toBeInTheDocument(); expect(screen.getByTestId('logLabelStats')).toHaveTextContent('another value'); }); + + describe('copy button', () => { + it('should be invisible unless mouse is over', () => { + setup({ parsedValues: ['test value'] }); + // This tests a regression where the button was always visible. + expect(screen.getByTitle('Copy value to clipboard')).not.toBeVisible(); + // Asserting visibility on mouse-over is currently not possible. + }); + }); }); diff --git a/public/app/features/logs/components/LogDetailsRow.tsx b/public/app/features/logs/components/LogDetailsRow.tsx index 3d051399cba..210b1fc71d3 100644 --- a/public/app/features/logs/components/LogDetailsRow.tsx +++ b/public/app/features/logs/components/LogDetailsRow.tsx @@ -75,12 +75,11 @@ const getStyles = memoizeOne((theme: GrafanaTheme2) => { align-items: center; line-height: 22px; - .show-on-hover { - display: inline; + .log-details-value-copy { visibility: hidden; } &:hover { - .show-on-hover { + .log-details-value-copy { visibility: visible; } } @@ -206,7 +205,7 @@ class UnThemedLogDetailsRow extends PureComponent { const styles = getStyles(theme); return ( -
+
val} title="Copy value to clipboard" @@ -254,7 +253,7 @@ class UnThemedLogDetailsRow extends PureComponent { } = this.props; const { showFieldsStats, fieldStats, fieldCount } = this.state; const styles = getStyles(theme); - const style = getLogRowStyles(theme); + const rowStyles = getLogRowStyles(theme); const singleKey = parsedKeys == null ? false : parsedKeys.length === 1; const singleVal = parsedValues == null ? false : parsedValues.length === 1; const hasFilteringFunctionality = !disableActions && onClickFilterLabel && onClickFilterOutLabel; @@ -273,8 +272,8 @@ class UnThemedLogDetailsRow extends PureComponent { return ( <> - - + +
{hasFilteringFunctionality && ( <> @@ -311,7 +310,7 @@ class UnThemedLogDetailsRow extends PureComponent { {/* Key - value columns */} - {singleKey ? parsedKeys[0] : this.generateMultiVal(parsedKeys)} + {singleKey ? parsedKeys[0] : this.generateMultiVal(parsedKeys)}
{singleVal ? parsedValues[0] : this.generateMultiVal(parsedValues, true)}