Commit 2ad8856
feat(reactotron-core-ui): add copy button for nested objects in API response (#1597)
## Please verify the following:
- [x] `yarn build-and-test:local` passes
- [ ] I have added tests for any new features, if relevant
- [ ] `README.md` (or relevant documentation) has been updated with your
changes
---
# Describe your PR
Adds a **Copy button for nested objects** in the `TreeView` component
inside the **Response Body** tab.
This allows users to quickly copy the JSON representation of any nested
object in an API response without manually selecting or expanding large
sections of the tree.
---
# Motivation
Previously, Reactotron only allowed copying **top-level values**.
When API responses contained deeply nested objects, users had to
manually expand the tree and select the text to copy.
This change enables **one-click copying of any nested object**,
improving the developer experience when inspecting API responses.
---
# Implementation
- **TreeView/index.tsx**
- Accepts an optional `copyToClipboard` prop
- Renders a `ButtonCopy` next to object-type nodes (e.g. `{3}`)
- Copies `JSON.stringify(data, null, 2)` when clicked
- Uses `event.stopPropagation()` so clicking the button does not toggle
the node
- **ContentView/index.tsx**
- Passes `copyToClipboard` down to `TreeView`
- **ApiResponseCommand/index.tsx**
- Provides the existing `copyToClipboard` handler to `ContentView` for
the **Response Body** tab
---
# Test Plan and Preview
1. Open Reactotron and trigger an API request with nested objects
2. Navigate to the **Response Body** tab
3. Verify a **Copy** button appears next to nested objects
4. Click the button and confirm the **prettified JSON** is copied to the
clipboard
5. Ensure clicking **Copy** does **not expand/collapse** the tree node
<img width="1112" height="1868" alt="image"
src="https://github.com/user-attachments/assets/6839b931-cd94-486b-a82f-29297d79029b"
/>
Co-authored-by: Deepak Mukka <deepak.mukka@gullak.money>1 parent 96df54c commit 2ad8856
3 files changed
Lines changed: 36 additions & 5 deletions
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
32 | 48 | | |
33 | 49 | | |
34 | 50 | | |
| |||
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
| 60 | + | |
44 | 61 | | |
45 | 62 | | |
46 | | - | |
| 63 | + | |
47 | 64 | | |
48 | 65 | | |
49 | 66 | | |
| |||
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
58 | 86 | | |
59 | 87 | | |
60 | 88 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
171 | 173 | | |
172 | 174 | | |
173 | 175 | | |
| |||
0 commit comments