Commit bdb1221d by heheer Committed by GitHub

optimize editor default value code (#4794)

parent cac4b1d4
......@@ -178,12 +178,11 @@ const JSONEditor = ({
return '';
}
try {
if (typeof value === 'object') {
return JSON.stringify(value, null, 2);
} catch (error) {
console.error('JSON stringify error:', error);
return String(value) || '';
}
return String(value);
}, [value]);
const onBlur = useCallback(() => {
......
......@@ -140,20 +140,15 @@ const ChatItemContextProvider = ({
(props?: { variables?: Record<string, any>; variableList?: VariableItemType[] }) => {
const { variables, variableList = [] } = props || {};
let newVariableValue: Record<string, any> = {};
if (variables) {
variableList.forEach((item) => {
newVariableValue[item.key] = variables[item.key];
variablesForm.setValue(`variables.${item.key}`, variables[item.key]);
});
} else {
variableList.forEach((item) => {
newVariableValue[item.key] = item.defaultValue;
variablesForm.setValue(`variables.${item.key}`, item.defaultValue);
});
}
Object.entries(newVariableValue).forEach(([key, value]) => {
variablesForm.setValue(`variables.${key}`, value);
});
},
[variablesForm]
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment