fix: edit worker_config

This commit is contained in:
jialin
2025-12-19 16:44:52 +08:00
parent bd76934e40
commit 79ccb96c95
2 changed files with 33 additions and 10 deletions
+18 -8
View File
@@ -55,19 +55,29 @@ export const backendActions = [
]; ];
export const json2Yaml = (obj: Record<string, any>) => { export const json2Yaml = (obj: Record<string, any>) => {
if (!obj || !Object.keys(obj).length) return ''; try {
const res = jsYaml.dump(JSON.parse(JSON.stringify(obj))); if (!obj || !Object.keys(obj).length) return '';
return res; const res = jsYaml.dump(JSON.parse(JSON.stringify(obj)));
return res;
} catch (error) {
console.error('json2Yaml error:', error);
return '';
}
}; };
export const yaml2Json = (input: string) => { export const yaml2Json = (input: string) => {
const str = trim(input); try {
const obj = jsYaml.load(str, { schema: SEAL_SCHEMA }); const str = trim(input);
if (typeof obj !== 'object' || obj === null) { const obj = jsYaml.load(str, { schema: SEAL_SCHEMA });
if (typeof obj !== 'object' || obj === null) {
return {};
}
const jsonStr = JSON.stringify(obj);
return JSON.parse(jsonStr);
} catch (error) {
console.error('yaml2Json error:', error);
return {}; return {};
} }
const jsonStr = JSON.stringify(obj);
return JSON.parse(jsonStr);
}; };
export const customColors = [ export const customColors = [
@@ -81,10 +81,23 @@ const ClusterForm: React.FC<AddModalProps> = forwardRef(
form.submit(); form.submit();
}, },
setFieldsValue: (values: any) => { setFieldsValue: (values: any) => {
form.setFieldsValue(values); form.setFieldsValue({
...values,
worker_config: undefined
});
const workerConfigYaml = json2Yaml(values.worker_config || {});
advanceConfigRef.current?.setYamlValue(workerConfigYaml);
}, },
getFieldsValue: () => { getFieldsValue: () => {
return form.getFieldsValue(); const workerConfig = yaml2Json(
advanceConfigRef.current?.getYamlValue()
);
return {
...form.getFieldsValue(),
worker_config: {
...workerConfig
}
};
}, },
validateFields: async () => { validateFields: async () => {
const values = await form.validateFields(); const values = await form.validateFields();