1- import { useGetConfigQuery } from '../store/apiSlice' ;
1+ import { Editor , OnMount , useMonaco } from "@monaco-editor/react" ;
2+ import { useEffect , useRef } from "react" ;
3+ import { useGetConfigQuery } from "../store/apiSlice" ;
4+
5+ type IConfigViewer = Parameters < OnMount > [ 0 ] ;
26
37const ConfigFile = ( ) => {
4- const { data : config } = useGetConfigQuery ( ) ;
8+ const { data : config } = useGetConfigQuery ( ) ;
9+
10+ if ( ! config ) {
11+ return < div > Loading...</ div > ;
12+ }
13+
14+ return < ConfigFileRender config = { config } /> ;
15+ } ;
16+
17+ export default ConfigFile ;
18+
19+ const ConfigFileRender = ( { config } : { config : any } ) => {
20+ console . log ( "ConfigFileRender == " , config ) ;
21+ const monaco = useMonaco ( ) ;
22+ const editorRef = useRef < IConfigViewer | null > ( null ) ;
523
24+ useEffect ( ( ) => {
25+ if ( ! monaco ) return ;
626
7- if ( ! config ) { return < div > Loading...</ div > } ;
27+ ( monaco . languages as any ) . json ?. jsonDefaults ?. setDiagnosticsOptions ( {
28+ enableSchemaRequest : false ,
29+ allowComments : false ,
30+ validate : true ,
31+ } ) ;
32+ } , [ monaco ] ) ;
833
9- return (
10- < div className = "d-flex flex-column overflow-hidden h-100" >
11- < h2 className = 'mb-2' > Merged Configuration</ h2 >
12- < pre className = 'flex-grow-1 overflow-auto' >
13- { JSON . stringify ( config , null , 2 ) }
14- </ pre >
15- </ div >
16- ) ;
17- }
34+ // Set the editor reference
35+ function handleEditorDidMount ( editor : IConfigViewer ) {
36+ editorRef . current = editor ;
37+ }
1838
19- export default ConfigFile ;
39+ return (
40+ < Editor
41+ height = "100%"
42+ defaultLanguage = "json"
43+ language = "json"
44+ options = { {
45+ readOnly : true ,
46+ } }
47+ value = { JSON . stringify ( config , null , 2 ) }
48+ onMount = { handleEditorDidMount }
49+ theme = "vs-dark"
50+ />
51+ ) ;
52+ } ;
0 commit comments