From 324c0d7b4c66a3add4e37d59c691622bcb84d76c Mon Sep 17 00:00:00 2001 From: twwu Date: Mon, 26 May 2025 14:06:04 +0800 Subject: [PATCH] refactor: improve layout and styling in TestRunPanel and FilePreview components --- .../documents/create-from-pipeline/index.tsx | 6 ++-- .../preview/file-preview.tsx | 33 ++++++++++--------- .../create-from-pipeline/preview/loading.tsx | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/web/app/components/datasets/documents/create-from-pipeline/index.tsx b/web/app/components/datasets/documents/create-from-pipeline/index.tsx index 553ad50e9f..e0a584a354 100644 --- a/web/app/components/datasets/documents/create-from-pipeline/index.tsx +++ b/web/app/components/datasets/documents/create-from-pipeline/index.tsx @@ -187,9 +187,9 @@ const TestRunPanel = () => { return (
-
+
{ {/* Preview */} { currentStep === 1 && ( -
+
{currentFile && } {currentNotionPage && } {currentWebsite && } diff --git a/web/app/components/datasets/documents/create-from-pipeline/preview/file-preview.tsx b/web/app/components/datasets/documents/create-from-pipeline/preview/file-preview.tsx index ab6b0d8e12..30d3e4f9c1 100644 --- a/web/app/components/datasets/documents/create-from-pipeline/preview/file-preview.tsx +++ b/web/app/components/datasets/documents/create-from-pipeline/preview/file-preview.tsx @@ -27,22 +27,27 @@ const FilePreview = ({ return arr.slice(0, -1).join() } - const getFileSize = (size: number) => { - if (size / 1024 < 10) - return `${(size / 1024).toFixed(1)} KB` - - return `${(size / 1024 / 1024).toFixed(1)} MB` + const getFileSize = (fileSize: number) => { + if (!fileSize) + return fileSize + const units = ['', 'K', 'M', 'G', 'T', 'P'] + let index = 0 + while (fileSize >= 1024 && index < units.length) { + fileSize = fileSize / 1024 + index++ + } + return `${fileSize.toFixed(2)} ${units[index]}B` } return (
-
+
-
{t('datasetPipeline.addDocuments.stepOne.preview')}
+
{t('datasetPipeline.addDocuments.stepOne.preview')}
{`${getFileName(file)}.${file.extension}`}
-
+
@@ -65,12 +70,10 @@ const FilePreview = ({
-
- {isFetching && } - {!isFetching && fileData && ( -
{fileData.content}
- )} -
+ {isFetching && } + {!isFetching && fileData && ( +
{fileData.content}
+ )}
) } diff --git a/web/app/components/datasets/documents/create-from-pipeline/preview/loading.tsx b/web/app/components/datasets/documents/create-from-pipeline/preview/loading.tsx index 3fd7723ae3..c15fec6c40 100644 --- a/web/app/components/datasets/documents/create-from-pipeline/preview/loading.tsx +++ b/web/app/components/datasets/documents/create-from-pipeline/preview/loading.tsx @@ -3,7 +3,7 @@ import { SkeletonContainer, SkeletonRectangle } from '@/app/components/base/skel const Loading = () => { return ( -
+