SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: restore click-to-copy for non-JSON body fields after #9657 (#9769)
Shaheer Kochaif3256aeac43f
diff --git a/frontend/src/container/LogDetailedView/TableView/TableViewActions.tsx b/frontend/src/container/LogDetailedView/TableView/TableViewActions.tsxindex 032d0756b0..422ddc77e8 100644--- a/frontend/src/container/LogDetailedView/TableView/TableViewActions.tsx+++ b/frontend/src/container/LogDetailedView/TableView/TableViewActions.tsx@@ -60,7 +60,8 @@ const BodyContent: React.FC<{fieldData: Record<string, string>;record: DataType;bodyHtml: { __html: string };-}> = React.memo(({ fieldData, record, bodyHtml }) => {+ textToCopy: string;+}> = React.memo(({ fieldData, record, bodyHtml, textToCopy }) => {const { isLoading, treeData, error } = useAsyncJSONProcessing(fieldData.value,record.field === 'body',@@ -92,11 +93,13 @@ const BodyContent: React.FC<{if (record.field === 'body') {return (- <span- style={{ color: Color.BG_SIENNA_400, whiteSpace: 'pre-wrap', tabSize: 4 }}- >- <span dangerouslySetInnerHTML={bodyHtml} />- </span>+ <CopyClipboardHOC entityKey="body" textToCopy={textToCopy}>+ <span+ style={{ color: Color.BG_SIENNA_400, whiteSpace: 'pre-wrap', tabSize: 4 }}+ >+ <span dangerouslySetInnerHTML={bodyHtml} />+ </span>+ </CopyClipboardHOC>);}@@ -172,7 +175,12 @@ export default function TableViewActions(switch (record.field) {case 'body':return (- <BodyContent fieldData={fieldData} record={record} bodyHtml={bodyHtml} />+ <BodyContent+ fieldData={fieldData}+ record={record}+ bodyHtml={bodyHtml}+ textToCopy={textToCopy}+ />);case 'timestamp':@@ -194,6 +202,7 @@ export default function TableViewActions(record,fieldData,bodyHtml,+ textToCopy,formatTimezoneAdjustedTimestamp,cleanTimestamp,]);@@ -202,7 +211,12 @@ export default function TableViewActions(if (record.field === 'body') {return (<div className={cx('value-field', isOpen ? 'open-popover' : '')}>- <BodyContent fieldData={fieldData} record={record} bodyHtml={bodyHtml} />+ <BodyContent+ fieldData={fieldData}+ record={record}+ bodyHtml={bodyHtml}+ textToCopy={textToCopy}+ />{!isListViewPanel && !RESTRICTED_SELECTED_FIELDS.includes(fieldFilterKey) && (<span className="action-btn"><Tooltip title="Filter for value">diff --git a/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx b/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsxindex da6b3bdad3..8c94ae78c5 100644--- a/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx+++ b/frontend/src/container/LogDetailedView/TableView/__test__/TableViewActions.test.tsx@@ -1,16 +1,54 @@-import { render, screen } from '@testing-library/react';+import { fireEvent, render, screen } from '@testing-library/react';import { RESTRICTED_SELECTED_FIELDS } from 'container/LogsFilters/config';import TableViewActions from '../TableViewActions';+import useAsyncJSONProcessing from '../useAsyncJSONProcessing';++// Mock data for tests+let mockCopyToClipboard: jest.Mock;+let mockNotificationsSuccess: jest.Mock;// Mock the components and hooksjest.mock('components/Logs/CopyClipboardHOC', () => ({__esModule: true,- default: ({ children }: { children: React.ReactNode }): JSX.Element => (- <div className="CopyClipboardHOC">{children}</div>+ default: ({+ children,+ textToCopy,+ entityKey,+ }: {+ children: React.ReactNode;+ textToCopy: string;+ entityKey: string;+ }): JSX.Element => (+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events+ <div+ className="CopyClipboardHOC"+ data-testid={`copy-clipboard-${entityKey}`}+ data-text-to-copy={textToCopy}+ onClick={(): void => {+ if (mockCopyToClipboard) {+ mockCopyToClipboard(textToCopy);+ }+ if (mockNotificationsSuccess) {+ mockNotificationsSuccess({+ message: `${entityKey} copied to clipboard`,+ key: `${entityKey} copied to clipboard`,+ });+ }+ }}+ role="button"+ tabIndex={0}+ >+ {children}+ </div>),}));+jest.mock('../useAsyncJSONProcessing', () => ({+ __esModule: true,+ default: jest.fn(),+}));+jest.mock('providers/Timezone', () => ({useTimezone: (): {formatTimezoneAdjustedTimestamp: (timestamp: string) => string;@@ -53,6 +91,19 @@ describe('TableViewActions', () => {onGroupByAttribute: jest.fn(),};+ beforeEach(() => {+ mockCopyToClipboard = jest.fn();+ mockNotificationsSuccess = jest.fn();++ // Default mock for useAsyncJSONProcessing+ const mockUseAsyncJSONProcessing = jest.mocked(useAsyncJSONProcessing);+ mockUseAsyncJSONProcessing.mockReturnValue({+ isLoading: false,+ treeData: null,+ error: null,+ });+ });+it('should render without crashing', () => {render(<TableViewActions@@ -127,4 +178,60 @@ describe('TableViewActions', () => {container.querySelector(ACTION_BUTTON_TEST_ID),).not.toBeInTheDocument();});++ it('should copy non-JSON body text without quotes when user clicks on body', () => {+ // Setup: body field with surrounding quotes+ const bodyValueWithQuotes =+ '"FeatureFlag \'kafkaQueueProblems\' is enabled, sleeping 1 second"';+ const expectedCopiedText =+ "FeatureFlag 'kafkaQueueProblems' is enabled, sleeping 1 second";++ const bodyProps = {+ fieldData: {+ field: 'body',+ value: bodyValueWithQuotes,+ },+ record: {+ key: 'body-key',+ field: 'body',+ value: bodyValueWithQuotes,+ },+ isListViewPanel: false,+ isfilterInLoading: false,+ isfilterOutLoading: false,+ onClickHandler: jest.fn(),+ onGroupByAttribute: jest.fn(),+ };++ // Render component with body field+ render(+ <TableViewActions+ fieldData={bodyProps.fieldData}+ record={bodyProps.record}+ isListViewPanel={bodyProps.isListViewPanel}+ isfilterInLoading={bodyProps.isfilterInLoading}+ isfilterOutLoading={bodyProps.isfilterOutLoading}+ onClickHandler={bodyProps.onClickHandler}+ onGroupByAttribute={bodyProps.onGroupByAttribute}+ />,+ );++ // Find the clickable copy area for body+ const copyArea = screen.getByTestId('copy-clipboard-body');++ // Verify it has the correct text to copy (without quotes)+ expect(copyArea).toHaveAttribute('data-text-to-copy', expectedCopiedText);++ // Action: User clicks on body content+ fireEvent.click(copyArea);++ // Assert: Text was copied without surrounding quotes+ expect(mockCopyToClipboard).toHaveBeenCalledWith(expectedCopiedText);++ // Assert: Success notification shown+ expect(mockNotificationsSuccess).toHaveBeenCalledWith({+ message: 'body copied to clipboard',+ key: 'body copied to clipboard',+ });+ });});