From dcd8b172a94a152109478f9f41c0be3ba9a296b9 Mon Sep 17 00:00:00 2001 From: ahmadshaheer Date: Thu, 4 Dec 2025 10:20:54 +0430 Subject: [PATCH] fix: copy values without keys in log body JSON view --- .../src/container/LogDetailedView/BodyTitleRenderer.tsx | 8 ++++---- .../LogDetailedView/__tests__/BodyTitleRenderer.test.tsx | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/container/LogDetailedView/BodyTitleRenderer.tsx b/frontend/src/container/LogDetailedView/BodyTitleRenderer.tsx index 7b2ef943cb3..704e3fcf0ac 100644 --- a/frontend/src/container/LogDetailedView/BodyTitleRenderer.tsx +++ b/frontend/src/container/LogDetailedView/BodyTitleRenderer.tsx @@ -92,14 +92,14 @@ function BodyTitleRenderer({ if (isObject) { // For objects/arrays, stringify the entire structure - copyText = `"${cleanedKey}": ${JSON.stringify(value, null, 2)}`; + copyText = JSON.stringify(value, null, 2); } else if (parentIsArray) { // For array elements, copy just the value - copyText = `"${cleanedKey}": ${value}`; + copyText = `${value}`; } else { // For primitive values, format as JSON key-value pair - const valueStr = typeof value === 'string' ? `"${value}"` : String(value); - copyText = `"${cleanedKey}": ${valueStr}`; + const valueStr = typeof value === 'string' ? value : String(value); + copyText = valueStr; } setCopy(copyText); diff --git a/frontend/src/container/LogDetailedView/__tests__/BodyTitleRenderer.test.tsx b/frontend/src/container/LogDetailedView/__tests__/BodyTitleRenderer.test.tsx index 8cb50b87faf..bfb62434276 100644 --- a/frontend/src/container/LogDetailedView/__tests__/BodyTitleRenderer.test.tsx +++ b/frontend/src/container/LogDetailedView/__tests__/BodyTitleRenderer.test.tsx @@ -51,7 +51,7 @@ describe('BodyTitleRenderer', () => { await user.click(screen.getByText('name')); await waitFor(() => { - expect(mockSetCopy).toHaveBeenCalledWith('"user.name": "John"'); + expect(mockSetCopy).toHaveBeenCalledWith('John'); expect(mockNotification).toHaveBeenCalledWith( expect.objectContaining({ message: expect.stringContaining('user.name'), @@ -75,7 +75,7 @@ describe('BodyTitleRenderer', () => { await user.click(screen.getByText('0')); await waitFor(() => { - expect(mockSetCopy).toHaveBeenCalledWith('"items[*].0": arrayElement'); + expect(mockSetCopy).toHaveBeenCalledWith('arrayElement'); }); }); @@ -96,9 +96,8 @@ describe('BodyTitleRenderer', () => { await waitFor(() => { const callArg = mockSetCopy.mock.calls[0][0]; - expect(callArg).toContain('"user.metadata":'); - expect(callArg).toContain('"id": 123'); - expect(callArg).toContain('"active": true'); + const expectedJson = JSON.stringify(testObject, null, 2); + expect(callArg).toBe(expectedJson); expect(mockNotification).toHaveBeenCalledWith( expect.objectContaining({ message: expect.stringContaining('object copied'),