From 4c81040796fe36f625a8587d6c88f3d3edfcc217 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 13 Jun 2025 15:16:52 +0800 Subject: [PATCH] fix file display --- .../variable-inspect/value-content.tsx | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/web/app/components/workflow/variable-inspect/value-content.tsx b/web/app/components/workflow/variable-inspect/value-content.tsx index 47a4633a54..3770dbb022 100644 --- a/web/app/components/workflow/variable-inspect/value-content.tsx +++ b/web/app/components/workflow/variable-inspect/value-content.tsx @@ -41,18 +41,20 @@ const ValueContent = ({ const textEditorDisabled = currentVar.type === VarInInspectType.environment || (currentVar.type === VarInInspectType.system && currentVar.name !== 'query' && currentVar.name !== 'files') const JSONEditorDisabled = currentVar.value_type === 'array[any]' + const formatFileValue = (value: VarInInspect) => { + if (value.value_type === 'file') + return value.value ? getProcessedFilesFromResponse([value.value]) : [] + if (value.value_type === 'array[file]' || (value.type === VarInInspectType.system && currentVar.name === 'files')) + return value.value && value.value.length > 0 ? getProcessedFilesFromResponse(value.value) : [] + return [] + } + const [value, setValue] = useState() const [json, setJson] = useState('') const [parseError, setParseError] = useState(null) const [validationError, setValidationError] = useState('') const fileFeature = useFeatures(s => s.features.file) - const [fileValue, setFileValue] = useState( - currentVar.value_type === 'array[file]' - ? getProcessedFilesFromResponse(currentVar.value || []) - : currentVar.value - ? getProcessedFilesFromResponse([currentVar.value]) - : [], - ) + const [fileValue, setFileValue] = useState(formatFileValue(currentVar)) const { run: debounceValueChange } = useDebounceFn(handleValueChange, { wait: 500 }) @@ -68,16 +70,8 @@ const ValueContent = ({ if (showJSONEditor) setJson(currentVar.value ? JSON.stringify(currentVar.value, null, 2) : '') - if (showFileEditor) { - console.log(getProcessedFilesFromResponse(currentVar.value || [])) - setFileValue( - (currentVar.value_type === 'array[file]' || isSysFiles) - ? getProcessedFilesFromResponse(currentVar.value || []) - : currentVar.value - ? getProcessedFilesFromResponse([currentVar.value]) - : [], - ) - } + if (showFileEditor) + setFileValue(formatFileValue(currentVar)) // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentVar.id, currentVar.value])