Skip to content

Commit 79ccb96

Browse files
committed
fix: edit worker_config
1 parent bd76934 commit 79ccb96

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/pages/backends/config/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,29 @@ export const backendActions = [
5555
];
5656

5757
export 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

6368
export 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

7383
export const customColors = [

src/pages/cluster-management/components/cluster-form.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)