File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* eslint-disable @typescript-eslint/restrict-plus-operands */
22/* eslint-disable no-nested-ternary */
3- import React , { useState } from 'react'
3+ import React , { useEffect , useState } from 'react'
44import { Editor } from '@monaco-editor/react'
55import { isEmpty } from 'lodash'
66import { Box } from '@mui/material'
@@ -51,6 +51,7 @@ interface Props {
5151 setValid ?: CallableFunction
5252 showComments ?: boolean
5353 validationSchema ?: any
54+ setWorkloadValues ?: CallableFunction
5455}
5556
5657const toYaml = ( obj ) => YAML . stringify ( obj , { blockQuote : 'literal' } )
@@ -63,6 +64,7 @@ export default function CodeEditor({
6364 disabled,
6465 showComments = false ,
6566 validationSchema,
67+ setWorkloadValues,
6668 ...props
6769} : Props ) : React . ReactElement {
6870 const [ startCode ] = useState ( isEmpty ( inCode ) ? '' : toYaml ( inCode ) . replace ( '|\n' , '' ) . replace ( / \n $ / , '' ) )
@@ -116,6 +118,11 @@ export default function CodeEditor({
116118 validateCode ( newValue )
117119 }
118120
121+ useEffect ( ( ) => {
122+ const obj = fromYaml ( modifiedCode )
123+ setWorkloadValues ( obj )
124+ } , [ modifiedCode ] )
125+
119126 return (
120127 < >
121128 < Editor
Original file line number Diff line number Diff line change @@ -30,7 +30,14 @@ export default function ({
3030 return (
3131 < Box pt = { 2 } >
3232 { show && workloadValues ? (
33- < CodeEditor code = { yaml } onChange = { ( data ) => setWorkloadValues ( data ) } showComments = { showComments } />
33+ < CodeEditor
34+ code = { yaml }
35+ onChange = { ( data ) => {
36+ setWorkloadValues ( data )
37+ } }
38+ setWorkloadValues = { setWorkloadValues }
39+ showComments = { showComments }
40+ />
3441 ) : (
3542 < CircularProgress sx = { { mb : '1rem' } } />
3643 ) }
You can’t perform that action at this time.
0 commit comments