Skip to content

Commit 91d950f

Browse files
authored
feat: Add copy row as JSON button to DBRowJsonViewer (#2035)
## Summary Adds ability to copy JSON button for entire row ### Screenshots or video https://github.com/user-attachments/assets/0a30db15-6db0-4858-8503-d1b1688615ca ### How to test locally or on Vercel 1. Go to vercel preview 2. Click on any row 3. Copy to clipboard by clicking copy icon ### References - Linear Issue: Closes HDX-3900
1 parent bb24994 commit 91d950f

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎packages/app/src/components/DBRowJsonViewer.tsx‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,31 @@ const viewerOptionsAtom = atomWithStorage<ViewerOptions>(
210210
viewerOptionsStorage,
211211
);
212212

213-
function HyperJsonMenu() {
213+
function HyperJsonMenu({ rowData }: { rowData: any }) {
214214
const [jsonOptions, setJsonOptions] = useAtom(viewerOptionsAtom);
215215
const effectiveWhiteSpace = jsonOptions.whiteSpace ?? 'pre-wrap';
216216

217217
return (
218218
<Group>
219+
{rowData != null && (
220+
<UnstyledButton
221+
onClick={() => {
222+
window.navigator.clipboard.writeText(
223+
typeof rowData === 'string'
224+
? rowData
225+
: JSON.stringify(rowData, null, 2),
226+
);
227+
notifications.show({
228+
color: 'green',
229+
message: `Value copied to clipboard`,
230+
});
231+
}}
232+
variant="copy"
233+
title={'Copy row as JSON'}
234+
>
235+
<IconCopy size={14} />
236+
</UnstyledButton>
237+
)}
219238
<UnstyledButton
220239
color="gray"
221240
data-testid="json-viewer-wrap-toggle"
@@ -604,7 +623,7 @@ export function DBRowJsonViewer({
604623
</Button>
605624
)}
606625
<div className="flex-grow-1" />
607-
<HyperJsonMenu />
626+
<HyperJsonMenu rowData={rowData} />
608627
</Group>
609628
</Box>
610629
<Paper bg="transparent" mt="sm">

0 commit comments

Comments
 (0)