1
- import React , { useCallback } from "react" ;
1
+ import React , { useCallback , useMemo , useState } from "react" ;
2
2
import PropTypes from "prop-types" ;
3
3
import { i18n } from "@mov-ai/mov-fe-lib-react" ;
4
4
import { MonacoCodeEditor } from "@mov-ai/mov-fe-lib-code-editor" ;
@@ -31,6 +31,7 @@ export const Configuration = (props, ref) => {
31
31
propsData : props . data ,
32
32
keysToDisconsider : Model . KEYS_TO_DISCONSIDER ,
33
33
} ) ;
34
+ const [ extension , setExtension ] = useState ( "yaml" ) ;
34
35
// Style Hooks
35
36
const classes = configurationStyles ( ) ;
36
37
const theme = useTheme ( ) ;
@@ -99,6 +100,7 @@ export const Configuration = (props, ref) => {
99
100
*/
100
101
const handleChangeFileType = ( event , newExtension ) => {
101
102
event . stopPropagation ( ) ;
103
+ setExtension ( newExtension ) ;
102
104
updateConfigExtension ( newExtension ) ;
103
105
} ;
104
106
@@ -116,15 +118,15 @@ export const Configuration = (props, ref) => {
116
118
* */
117
119
//========================================================================================
118
120
119
- const renderEditor = ( ) => {
121
+ const editorEl = useMemo ( ( ) => {
120
122
return (
121
123
< div
122
124
data-testid = "section_configuration-editor"
123
125
className = { classes . codeContainer }
124
126
>
125
127
< MonacoCodeEditor
126
128
value = { data . code }
127
- language = { data . extension }
129
+ language = { extension }
128
130
theme = { theme . codeEditor ?. theme }
129
131
options = { { readOnly : ! editable } }
130
132
onChange = { updateConfigCode }
@@ -133,7 +135,7 @@ export const Configuration = (props, ref) => {
133
135
/>
134
136
</ div >
135
137
) ;
136
- } ;
138
+ } , [ extension , classes . codeContainer , data . code ] ) ;
137
139
138
140
return (
139
141
< div
@@ -157,7 +159,7 @@ export const Configuration = (props, ref) => {
157
159
</ ToggleButtonGroup >
158
160
</ Toolbar >
159
161
</ AppBar >
160
- { renderEditor ( ) }
162
+ { editorEl }
161
163
</ div >
162
164
) ;
163
165
} ;
0 commit comments