File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed
cluster-management/components Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -55,19 +55,29 @@ export const backendActions = [
5555] ;
5656
5757export const json2Yaml = ( obj : Record < string , any > ) => {
58- if ( ! obj || ! Object . keys ( obj ) . length ) return '' ;
59- const res = jsYaml . dump ( JSON . parse ( JSON . stringify ( obj ) ) ) ;
60- return res ;
58+ try {
59+ if ( ! obj || ! Object . keys ( obj ) . length ) return '' ;
60+ const res = jsYaml . dump ( JSON . parse ( JSON . stringify ( obj ) ) ) ;
61+ return res ;
62+ } catch ( error ) {
63+ console . error ( 'json2Yaml error:' , error ) ;
64+ return '' ;
65+ }
6166} ;
6267
6368export const yaml2Json = ( input : string ) => {
64- const str = trim ( input ) ;
65- const obj = jsYaml . load ( str , { schema : SEAL_SCHEMA } ) ;
66- if ( typeof obj !== 'object' || obj === null ) {
69+ try {
70+ const str = trim ( input ) ;
71+ const obj = jsYaml . load ( str , { schema : SEAL_SCHEMA } ) ;
72+ if ( typeof obj !== 'object' || obj === null ) {
73+ return { } ;
74+ }
75+ const jsonStr = JSON . stringify ( obj ) ;
76+ return JSON . parse ( jsonStr ) ;
77+ } catch ( error ) {
78+ console . error ( 'yaml2Json error:' , error ) ;
6779 return { } ;
6880 }
69- const jsonStr = JSON . stringify ( obj ) ;
70- return JSON . parse ( jsonStr ) ;
7181} ;
7282
7383export const customColors = [
Original file line number Diff line number Diff line change @@ -81,10 +81,23 @@ const ClusterForm: React.FC<AddModalProps> = forwardRef(
8181 form . submit ( ) ;
8282 } ,
8383 setFieldsValue : ( values : any ) => {
84- form . setFieldsValue ( values ) ;
84+ form . setFieldsValue ( {
85+ ...values ,
86+ worker_config : undefined
87+ } ) ;
88+ const workerConfigYaml = json2Yaml ( values . worker_config || { } ) ;
89+ advanceConfigRef . current ?. setYamlValue ( workerConfigYaml ) ;
8590 } ,
8691 getFieldsValue : ( ) => {
87- return form . getFieldsValue ( ) ;
92+ const workerConfig = yaml2Json (
93+ advanceConfigRef . current ?. getYamlValue ( )
94+ ) ;
95+ return {
96+ ...form . getFieldsValue ( ) ,
97+ worker_config : {
98+ ...workerConfig
99+ }
100+ } ;
88101 } ,
89102 validateFields : async ( ) => {
90103 const values = await form . validateFields ( ) ;
You can’t perform that action at this time.
0 commit comments