@@ -21,68 +21,85 @@ export interface SettingsDialogRef {
2121 close : ( ) => void ;
2222}
2323
24- const SettingsDialog = forwardRef < SettingsDialogRef > ( ( _ , ref ) => {
25- const [ display , setDisplay ] = useState < boolean > ( false ) ;
26- const [ settingsData , setSettingsData ] = useState < SettingsData > ( {
27- northboundUrl : "" ,
28- southboundUrl : "" ,
29- pathToValue : "/" ,
30- } ) ;
31- const [ isValid , setIsValid ] = useState ( true ) ;
24+ interface SettingsDialogProps {
25+ jsonIndentation : 2 | 4 ;
26+ onJsonIndentationChange : ( value : 2 | 4 ) => void ;
27+ }
3228
33- useImperativeHandle ( ref , ( ) => {
34- return {
35- openModal : ( ) => open ( ) ,
36- close : ( ) => close ( ) ,
37- } ;
38- } ) ;
29+ const SettingsDialog = forwardRef < SettingsDialogRef , SettingsDialogProps > (
30+ ( { jsonIndentation, onJsonIndentationChange } , ref ) => {
31+ const [ display , setDisplay ] = useState < boolean > ( false ) ;
32+ const [ settingsData , setSettingsData ] = useState < SettingsData > ( {
33+ northboundUrl : "" ,
34+ southboundUrl : "" ,
35+ pathToValue : "/" ,
36+ } ) ;
37+ const [ draftJsonIndentation , setDraftJsonIndentation ] = useState < 2 | 4 > (
38+ jsonIndentation
39+ ) ;
40+ const [ isValid , setIsValid ] = useState ( true ) ;
3941
40- const open = ( ) => {
41- setDisplay ( true ) ;
42- setSettingsData ( {
43- northboundUrl : getLocalStorage ( "northbound" ) || "" ,
44- southboundUrl : getLocalStorage ( "southbound" ) || "" ,
45- pathToValue : getLocalStorage ( "valuePath" ) || "/" ,
42+ useImperativeHandle ( ref , ( ) => {
43+ return {
44+ openModal : ( ) => open ( ) ,
45+ close : ( ) => close ( ) ,
46+ } ;
4647 } ) ;
47- } ;
4848
49- const close = async ( ) => {
50- setDisplay ( false ) ;
51- } ;
49+ const open = ( ) => {
50+ setDisplay ( true ) ;
51+ setSettingsData ( {
52+ northboundUrl : getLocalStorage ( "northbound" ) || "" ,
53+ southboundUrl : getLocalStorage ( "southbound" ) || "" ,
54+ pathToValue : getLocalStorage ( "valuePath" ) || "/" ,
55+ } ) ;
56+ setDraftJsonIndentation ( jsonIndentation ) ;
57+ } ;
5258
53- const handleSubmit = ( ) => {
54- if ( isValid ) {
55- setLocalStorage ( settingsData . northboundUrl , "northbound" ) ;
56- setLocalStorage ( settingsData . southboundUrl , "southbound" ) ;
57- setLocalStorage ( settingsData . pathToValue , "valuePath" ) ;
58- close ( ) ;
59- }
60- } ;
59+ const close = async ( ) => {
60+ setDisplay ( false ) ;
61+ } ;
6162
62- const handleSettingsChange = ( data : SettingsData , valid : boolean ) => {
63- setSettingsData ( data ) ;
64- setIsValid ( valid ) ;
65- } ;
63+ const handleSubmit = ( ) => {
64+ if ( isValid ) {
65+ setLocalStorage ( settingsData . northboundUrl , "northbound" ) ;
66+ setLocalStorage ( settingsData . southboundUrl , "southbound" ) ;
67+ setLocalStorage ( settingsData . pathToValue , "valuePath" ) ;
68+ onJsonIndentationChange ( draftJsonIndentation ) ;
69+ close ( ) ;
70+ }
71+ } ;
6672
67- if ( display ) {
68- return ReactDOM . createPortal (
69- < DialogTemplate
70- hasSubmit = { true }
71- onHandleEventLeftButton = { close }
72- leftButton = { "Cancel" }
73- rightButton = { "Save Changes" }
74- onHandleEventRightButton = { handleSubmit }
75- title = { "Settings" }
76- description = { "Change the ediTDors configuration to your needs" }
77- >
78- < Settings initialData = { settingsData } onChange = { handleSettingsChange } />
79- </ DialogTemplate > ,
80- document . getElementById ( "modal-root" ) as HTMLElement
81- ) ;
82- }
73+ const handleSettingsChange = ( data : SettingsData , valid : boolean ) => {
74+ setSettingsData ( data ) ;
75+ setIsValid ( valid ) ;
76+ } ;
8377
84- return null ;
85- } ) ;
78+ if ( display ) {
79+ return ReactDOM . createPortal (
80+ < DialogTemplate
81+ hasSubmit = { true }
82+ onHandleEventLeftButton = { close }
83+ leftButton = { "Cancel" }
84+ rightButton = { "Save Changes" }
85+ onHandleEventRightButton = { handleSubmit }
86+ title = { "Settings" }
87+ description = { "Change the ediTDors configuration to your needs" }
88+ >
89+ < Settings
90+ initialData = { settingsData }
91+ onChange = { handleSettingsChange }
92+ jsonIndentation = { draftJsonIndentation }
93+ onJsonIndentationChange = { setDraftJsonIndentation }
94+ />
95+ </ DialogTemplate > ,
96+ document . getElementById ( "modal-root" ) as HTMLElement
97+ ) ;
98+ }
99+
100+ return null ;
101+ }
102+ ) ;
86103
87104SettingsDialog . displayName = "SettingsDialog" ;
88105export default SettingsDialog ;
0 commit comments