11import { useEffect , useState } from 'react'
22import { Button } from '@/components/ui/button'
3+ import { redactApiKeys } from '@/lib/utils'
34
45interface JSONViewProps {
56 data : any
@@ -154,6 +155,9 @@ export const JSONView = ({ data }: JSONViewProps) => {
154155 y : number
155156 } | null > ( null )
156157
158+ // Apply redaction to the data before displaying
159+ const redactedData = redactApiKeys ( data )
160+
157161 const handleContextMenu = ( e : React . MouseEvent ) => {
158162 e . preventDefault ( )
159163 setContextMenuPosition ( { x : e . clientX , y : e . clientY } )
@@ -167,18 +171,18 @@ export const JSONView = ({ data }: JSONViewProps) => {
167171 }
168172 } , [ contextMenuPosition ] )
169173
170- if ( data === null )
174+ if ( redactedData === null )
171175 return < span className = 'font-[380] text-muted-foreground leading-normal' > null</ span >
172176
173177 // For non-object data, show simple JSON
174- if ( typeof data !== 'object' ) {
175- const stringValue = JSON . stringify ( data )
178+ if ( typeof redactedData !== 'object' ) {
179+ const stringValue = JSON . stringify ( redactedData )
176180 return (
177181 < span
178182 onContextMenu = { handleContextMenu }
179183 className = 'relative max-w-full overflow-hidden break-all font-[380] font-mono text-muted-foreground leading-normal'
180184 >
181- { typeof data === 'string' ? (
185+ { typeof redactedData === 'string' ? (
182186 < TruncatedValue value = { stringValue } />
183187 ) : (
184188 < span className = 'break-all font-[380] text-muted-foreground leading-normal' >
@@ -192,7 +196,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
192196 >
193197 < button
194198 className = 'w-full px-3 py-1.5 text-left font-[380] text-sm hover:bg-accent'
195- onClick = { ( ) => copyToClipboard ( data ) }
199+ onClick = { ( ) => copyToClipboard ( redactedData ) }
196200 >
197201 Copy value
198202 </ button >
@@ -206,7 +210,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
206210 return (
207211 < div onContextMenu = { handleContextMenu } >
208212 < pre className = 'max-w-full overflow-hidden whitespace-pre-wrap break-all font-mono' >
209- < CollapsibleJSON data = { data } />
213+ < CollapsibleJSON data = { redactedData } />
210214 </ pre >
211215 { contextMenuPosition && (
212216 < div
@@ -215,7 +219,7 @@ export const JSONView = ({ data }: JSONViewProps) => {
215219 >
216220 < button
217221 className = 'w-full px-3 py-1.5 text-left font-[380] text-sm hover:bg-accent'
218- onClick = { ( ) => copyToClipboard ( data ) }
222+ onClick = { ( ) => copyToClipboard ( redactedData ) }
219223 >
220224 Copy object
221225 </ button >
0 commit comments