1+ import JsonView from "@uiw/react-json-view" ;
12import React , { useState } from "react" ;
2- import { JsonView , defaultStyles } from "react-json-view-lite" ;
3- import "react-json-view-lite/dist/index.css" ;
43
5- import "./jsonview.css" ;
4+ // import { JSONTree } from "react-json-tree";
5+ // import "./jsonview.css";
66
77import DataTable from "../components/DataTable" ;
88import {
@@ -57,17 +57,10 @@ function FileTable({ title, dataArray = [], onView }) {
5757}
5858
5959export default function RawDataVisualiser ( { nodeData = { } } ) {
60- const [ copiedIndex , setCopiedIndex ] = useState ( null ) ;
6160 const [ previewContent , setPreviewContent ] = useState ( null ) ;
6261 const [ previewName , setPreviewName ] = useState ( null ) ;
6362 const [ isOpen , setIsOpen ] = useState ( false ) ;
6463
65- const copyToClipboard = ( data , index ) => {
66- navigator . clipboard . writeText ( JSON . stringify ( data , null , 2 ) ) ;
67- setCopiedIndex ( index ) ;
68- setTimeout ( ( ) => setCopiedIndex ( null ) , 700 ) ;
69- } ;
70-
7164 const handleViewFile = async ( name , url ) => {
7265 try {
7366 const res = await fetch ( url ) ;
@@ -115,13 +108,6 @@ export default function RawDataVisualiser({ nodeData = {} }) {
115108 </ >
116109 ) ;
117110
118- const customStyle = {
119- ...defaultStyles ,
120- basicChildStyle : `${ defaultStyles . basicChildStyle } custom-basic-childstyle` ,
121- label : `${ defaultStyles . label } custom-json-label` ,
122- container : `${ defaultStyles . container } custom-json-container` ,
123- } ;
124-
125111 return (
126112 < div className = "ae:flex ae:flex-col ae:px-3 ae:py-2 ae:gap-2 ae:lg:gap-4" >
127113 { fileTables }
@@ -134,32 +120,48 @@ export default function RawDataVisualiser({ nodeData = {} }) {
134120 < div key = { index } className = "ae:py-1 ae:px-2" >
135121 < div className = "ae:flex ae:items-center ae:gap-2 ae:pb-2" >
136122 < div className = "explorerHeading" > { section . title } </ div >
137- < button
138- className = "ae:relative ae:flex ae:items-center ae:gap-1 ae:hover:text-blue-800"
139- onClick = { ( ) => copyToClipboard ( safeData , index ) }
140- >
141- < ClipBoardIcon size = { 18 } />
142- < div
143- className = { `ae:absolute ae:left-full ae:ml-2 ae:top-1/2 ae:-translate-y-1/2 ae:flex ae:items-center ae:gap-1 ae:text-green-400 ae:text-sm ae:transition-all ae:duration-400 ae:transform ${
144- copiedIndex === index
145- ? "ae:opacity-100 ae:translate-x-0"
146- : "ae:opacity-0 ae:-translate-x-2"
147- } `}
148- >
149- < ClipboardCopyIcon size = { 16 } />
150- < span > Copied</ span >
151- </ div >
152- </ button >
153123 </ div >
154124
155125 < div className = "ae:max-h-32 ae:md:max-h-96 ae:overflow-auto ae:border ae:border-slate-200 ae:rounded ae:p-1 ae:bg-slate-100" >
156126 < JsonView
157- data = { safeData }
158- shouldExpandNode = { ( level ) =>
159- level < ( section . collapseLevel ?? 1 )
160- }
161- style = { customStyle }
162- />
127+ value = { safeData }
128+ rootName = { false }
129+ collapsed = { false }
130+ shouldExpandNodeInitially = { ( isExpanded , { level } ) => level < 2 }
131+ displayDataTypes = { false }
132+ enableClipboard = { true }
133+ quotesOnKeys = { false }
134+ >
135+ { /* Remove quotes only for keys */ }
136+ < JsonView . Quote
137+ render = { ( { children, ...rest } , { type } ) => {
138+ // Only remove quotes for object keys
139+ if ( type === "key" ) return null ;
140+ return < span { ...rest } > { children } </ span > ;
141+ } }
142+ />
143+ < JsonView . Copied
144+ render = { ( { "data-copied" : copied , onClick, ...props } ) => (
145+ < button
146+ { ...props }
147+ onClick = { onClick }
148+ type = "button"
149+ className = "ae:flex ae:items-center ae:gap-1 ae:text-slate-700 ae:hover:text-blue-500"
150+ >
151+ { copied ? (
152+ < >
153+ < ClipboardCopyIcon
154+ size = { 16 }
155+ className = "ae:text-xs ae:text-green-400"
156+ />
157+ </ >
158+ ) : (
159+ < ClipBoardIcon size = { 16 } />
160+ ) }
161+ </ button >
162+ ) }
163+ />
164+ </ JsonView >
163165 </ div >
164166 </ div >
165167 ) ;
0 commit comments