Skip to content

Commit 89bcb7c

Browse files
CasLubbersj-zimnowoda
authored andcommitted
fix: set correct workload values on first load (#455)
* fix: set correct workload values on first load * fix: review comments (cherry picked from commit 901a979)
1 parent b34152b commit 89bcb7c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/components/CodeEditor.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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'
44
import { Editor } from '@monaco-editor/react'
55
import { isEmpty } from 'lodash'
66
import { Box } from '@mui/material'
@@ -51,6 +51,7 @@ interface Props {
5151
setValid?: CallableFunction
5252
showComments?: boolean
5353
validationSchema?: any
54+
setWorkloadValues?: CallableFunction
5455
}
5556

5657
const 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

src/components/WorkloadValues.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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
)}

0 commit comments

Comments
 (0)