11import { Component , createRef } from 'react'
22import { createPortal } from 'react-dom'
33import { Handle , Position , type NodeProps } from 'reactflow'
4- import { ChevronDown , ChevronUp , CheckCircle , AlertCircle , Code2 , List , X } from 'lucide-react'
4+ import { ChevronDown , ChevronUp , CheckCircle , AlertCircle , Code2 , List , X , FileJson } from 'lucide-react'
55import { Card , CardContent , CardHeader , CardTitle } from '@/components/ui/card'
66import { Button } from '@/components/ui/button'
77import { PropertyViewer } from './PropertyViewer'
@@ -125,14 +125,20 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
125125 const next = ! diagramRegistry . getViewState ( ) . globalRawViewPreference
126126 this . onMaximizeRawJson ?.( next )
127127 } else {
128- // notify diagram (e.g., to mark dirty)
129128 const next = ! this . model . rawView
130129 this . model . rawView = next
131130 }
132131 this . onNodeChange ?.( )
133132 this . forceUpdate ( )
134133 }
135134
135+ private handleToggleShowExamples = ( ) => {
136+ const next = ! this . model . showExamples
137+ this . model . showExamples = next
138+ this . onNodeChange ?.( )
139+ this . forceUpdate ( )
140+ }
141+
136142 private findPropertyInJson ( code : string , instancePath : string , rootObj ?: any ) : { lineStart : number ; lineEnd : number ; charStart : number ; charEnd : number } | null {
137143 // Parse instancePath like "/retention2" or "/nested/property"
138144 if ( ! instancePath || instancePath === '/' ) return null
@@ -444,15 +450,28 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
444450 </ Popup >
445451 ) }
446452 </ div >
447- < Button
448- variant = "ghost"
449- size = "sm"
450- className = "h-6 px-2 bg-gray-200"
451- onClick = { this . handleToggleRawView }
452- title = { rawView ? 'Switch to formatted view' : 'Switch to raw JSON' }
453- >
454- { rawView ? < List className = "h-3.5 w-3.5" /> : < Code2 className = "h-3.5 w-3.5" /> }
455- </ Button >
453+ < div className = "flex gap-1" >
454+ { this . model ?. examplesProperties && this . model . examplesProperties . length > 0 && ! rawView && (
455+ < Button
456+ variant = "ghost"
457+ size = "sm"
458+ className = "h-6 px-2 bg-gray-200"
459+ onClick = { this . handleToggleShowExamples }
460+ title = { this . model . showExamples ? 'Show schema' : 'Show examples' }
461+ >
462+ < FileJson className = "h-3.5 w-3.5" />
463+ </ Button >
464+ ) }
465+ < Button
466+ variant = "ghost"
467+ size = "sm"
468+ className = "h-6 px-2 bg-gray-200"
469+ onClick = { this . handleToggleRawView }
470+ title = { rawView ? 'Switch to formatted view' : 'Switch to raw JSON' }
471+ >
472+ { rawView ? < List className = "h-3.5 w-3.5" /> : < Code2 className = "h-3.5 w-3.5" /> }
473+ </ Button >
474+ </ div >
456475 </ div >
457476 ) }
458477 { ( this . model ?. entity ?. validation || d . entity ?. validation ) && ( this . model ?. entity ?. validation || d . entity ?. validation ) . errors . length > 0 && (
@@ -473,7 +492,7 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
473492 { this . renderCodeWithErrors ( JSON . stringify ( ( this . model ?. entity ?. content ?? d . entity ?. content ) , null , 2 ) ) }
474493 </ div >
475494 ) : (
476- this . model ?. properties && (
495+ ( this . model ?. showExamples && this . model ?. examplesProperties ? this . model . examplesProperties : this . model ?. properties ) && (
477496 < div
478497 className = "max-h-96 overflow-y-auto overflow-x-hidden pr-2"
479498 onWheel = { ( e ) => {
@@ -495,7 +514,7 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
495514 } }
496515 >
497516 < PropertyViewer
498- properties = { this . model . properties }
517+ properties = { ( this . model . showExamples && this . model . examplesProperties ? this . model . examplesProperties : this . model . properties ) || [ ] }
499518 sectionStates = { sectionStates }
500519 onToggleSection = { this . handleToggleSection }
501520 validationErrors = { this . model ?. entity ?. validation ?. errors }
@@ -552,15 +571,28 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
552571 ) : (
553572 < span className = "truncate cursor-default overflow-hidden" > { this . model ?. entity ?. file ?. name } </ span >
554573 ) }
555- < Button
556- variant = "ghost"
557- size = "sm"
558- className = "h-6 px-2 bg-gray-200"
559- onClick = { ( e ) => { e . stopPropagation ( ) ; this . handleToggleRawView ( ) } }
560- title = { ( this . model ?. rawView ? true : false ) ? 'Switch to formatted view' : 'Switch to raw JSON' }
561- >
562- { ( this . model ?. rawView ? true : false ) ? < List className = "h-3.5 w-3.5" /> : < Code2 className = "h-3.5 w-3.5" /> }
563- </ Button >
574+ < div className = "flex gap-1" >
575+ { this . model ?. examplesProperties && this . model . examplesProperties . length > 0 && ! rawView && (
576+ < Button
577+ variant = "ghost"
578+ size = "sm"
579+ className = "h-6 px-2 bg-gray-200"
580+ onClick = { ( e ) => { e . stopPropagation ( ) ; this . handleToggleShowExamples ( ) } }
581+ title = { this . model . showExamples ? 'Show schema' : 'Show examples' }
582+ >
583+ < FileJson className = "h-3.5 w-3.5" />
584+ </ Button >
585+ ) }
586+ < Button
587+ variant = "ghost"
588+ size = "sm"
589+ className = "h-6 px-2 bg-gray-200"
590+ onClick = { ( e ) => { e . stopPropagation ( ) ; this . handleToggleRawView ( ) } }
591+ title = { ( this . model ?. rawView ? true : false ) ? 'Switch to formatted view' : 'Switch to raw JSON' }
592+ >
593+ { ( this . model ?. rawView ? true : false ) ? < List className = "h-3.5 w-3.5" /> : < Code2 className = "h-3.5 w-3.5" /> }
594+ </ Button >
595+ </ div >
564596 </ div >
565597 ) }
566598 { this . model ?. entity ?. validation && this . model . entity . validation . errors . length > 0 && (
@@ -581,10 +613,10 @@ export class SchemaNodeView extends Component<NodeProps<any>, {}> {
581613 { this . renderCodeWithErrors ( JSON . stringify ( this . model ?. entity ?. content , null , 2 ) ) }
582614 </ div >
583615 ) : (
584- this . model ?. properties && (
616+ ( this . model ?. showExamples && this . model ?. examplesProperties ? this . model . examplesProperties : this . model ?. properties ) && (
585617 < div className = "h-[calc(100%-2rem)] overflow-y-auto overflow-x-hidden pr-2" >
586618 < PropertyViewer
587- properties = { this . model . properties }
619+ properties = { ( this . model . showExamples && this . model . examplesProperties ? this . model . examplesProperties : this . model . properties ) || [ ] }
588620 sectionStates = { this . model . sections }
589621 onToggleSection = { this . handleToggleSection }
590622 validationErrors = { this . model ?. entity ?. validation ?. errors }
0 commit comments