mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-18 09:24:03 +00:00
optimize editor default value code (#4794)
This commit is contained in:
@@ -178,12 +178,11 @@ const JSONEditor = ({
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (typeof value === 'object') {
|
||||||
return JSON.stringify(value, null, 2);
|
return JSON.stringify(value, null, 2);
|
||||||
} catch (error) {
|
|
||||||
console.error('JSON stringify error:', error);
|
|
||||||
return String(value) || '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return String(value);
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
const onBlur = useCallback(() => {
|
const onBlur = useCallback(() => {
|
||||||
|
@@ -140,20 +140,15 @@ const ChatItemContextProvider = ({
|
|||||||
(props?: { variables?: Record<string, any>; variableList?: VariableItemType[] }) => {
|
(props?: { variables?: Record<string, any>; variableList?: VariableItemType[] }) => {
|
||||||
const { variables, variableList = [] } = props || {};
|
const { variables, variableList = [] } = props || {};
|
||||||
|
|
||||||
let newVariableValue: Record<string, any> = {};
|
|
||||||
if (variables) {
|
if (variables) {
|
||||||
variableList.forEach((item) => {
|
variableList.forEach((item) => {
|
||||||
newVariableValue[item.key] = variables[item.key];
|
variablesForm.setValue(`variables.${item.key}`, variables[item.key]);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
variableList.forEach((item) => {
|
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]
|
[variablesForm]
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user