refactor: refactor component imports and enhance layout for better responsiveness in dataset previews

This commit is contained in:
twwu 2025-06-13 10:54:31 +08:00
parent 4d2f904d72
commit b9fa3f54e9
8 changed files with 48 additions and 34 deletions

View File

@ -17,7 +17,7 @@ import FamilyMod from '../assets/family-mod.svg'
import Note from '../assets/note-mod.svg' import Note from '../assets/note-mod.svg'
import FileList from '../assets/file-list-3-fill.svg' import FileList from '../assets/file-list-3-fill.svg'
import { indexMethodIcon } from '../icons' import { indexMethodIcon } from '../icons'
import { PreviewContainer } from '../../preview/container' import PreviewContainer from '../../preview/container'
import { ChunkContainer, QAPreview } from '../../chunk' import { ChunkContainer, QAPreview } from '../../chunk'
import { PreviewHeader } from '../../preview/header' import { PreviewHeader } from '../../preview/header'
import { FormattedText } from '../../formatted-text/formatted' import { FormattedText } from '../../formatted-text/formatted'

View File

@ -18,7 +18,7 @@ import Loading from '@/app/components/base/loading'
import type { Node } from '@/app/components/workflow/types' import type { Node } from '@/app/components/workflow/types'
import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types' import type { DataSourceNodeType } from '@/app/components/workflow/nodes/data-source/types'
import FilePreview from './preview/file-preview' import FilePreview from './preview/file-preview'
import NotionPagePreview from './preview/notion-page-preview' import OnlineDocumentPreview from './preview/online-document-preview'
import WebsitePreview from './preview/web-preview' import WebsitePreview from './preview/web-preview'
import ProcessDocuments from './process-documents' import ProcessDocuments from './process-documents'
import ChunkPreview from './preview/chunk-preview' import ChunkPreview from './preview/chunk-preview'
@ -223,9 +223,9 @@ const CreateFormPipeline = () => {
return ( return (
<div <div
className='relative flex h-[calc(100vh-56px)] overflow-x-auto rounded-t-2xl border-t border-effects-highlight bg-background-default-subtle' className='relative flex h-[calc(100vh-56px)] min-w-[1024px] overflow-x-auto rounded-t-2xl border-t border-effects-highlight bg-background-default-subtle'
> >
<div className='flex h-full min-w-[760px] flex-1 flex-col px-14'> <div className='flex h-full flex-1 flex-col px-14'>
<LeftHeader <LeftHeader
steps={steps} steps={steps}
title={t('datasetPipeline.addDocuments.title')} title={t('datasetPipeline.addDocuments.title')}
@ -309,16 +309,16 @@ const CreateFormPipeline = () => {
{/* Preview */} {/* Preview */}
{ {
currentStep === 1 && ( currentStep === 1 && (
<div className='flex h-full w-[752px] shrink-0 pl-2 pt-2'> <div className='flex h-full flex-1 shrink-0 pl-2 pt-2'>
{currentFile && <FilePreview file={currentFile} hidePreview={hideFilePreview} />} {currentFile && <FilePreview file={currentFile} hidePreview={hideFilePreview} />}
{currentDocuments && <NotionPagePreview currentPage={currentDocuments} hidePreview={hideOnlineDocumentPreview} />} {currentDocuments && <OnlineDocumentPreview currentPage={currentDocuments} hidePreview={hideOnlineDocumentPreview} />}
{currentWebsite && <WebsitePreview payload={currentWebsite} hidePreview={hideWebsitePreview} />} {currentWebsite && <WebsitePreview payload={currentWebsite} hidePreview={hideWebsitePreview} />}
</div> </div>
) )
} }
{ {
currentStep === 2 && ( currentStep === 2 && (
<div className='flex h-full w-[752px] shrink-0 pl-2 pt-2'> <div className='flex h-full flex-1 shrink-0 pl-2 pt-2'>
<ChunkPreview <ChunkPreview
dataSourceType={datasource!.type} dataSourceType={datasource!.type}
files={fileList.map(file => file.file)} files={fileList.map(file => file.file)}

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react' import React, { useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { PreviewContainer } from '../../../preview/container' import PreviewContainer from '../../../preview/container'
import { PreviewHeader } from '../../../preview/header' import { PreviewHeader } from '../../../preview/header'
import type { CrawlResultItem, CustomFile, DocumentItem, FileIndexingEstimateResponse } from '@/models/datasets' import type { CrawlResultItem, CustomFile, DocumentItem, FileIndexingEstimateResponse } from '@/models/datasets'
import { ChunkingMode } from '@/models/datasets' import { ChunkingMode } from '@/models/datasets'
@ -189,7 +189,7 @@ const ChunkPreview = ({
</div> </div>
)} )}
{isPending && ( {isPending && (
<div className='space-y-6'> <div className='h-full w-full space-y-6 overflow-hidden'>
{Array.from({ length: 10 }, (_, i) => ( {Array.from({ length: 10 }, (_, i) => (
<SkeletonContainer key={i}> <SkeletonContainer key={i}>
<SkeletonRow> <SkeletonRow>

View File

@ -40,7 +40,7 @@ const FilePreview = ({
} }
return ( return (
<div className='h-full w-full rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'> <div className='flex h-full w-full flex-col rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'>
<div className='flex gap-x-2 border-b border-divider-subtle pb-3 pl-6 pr-4 pt-4'> <div className='flex gap-x-2 border-b border-divider-subtle pb-3 pl-6 pr-4 pt-4'>
<div className='flex grow flex-col gap-y-1'> <div className='flex grow flex-col gap-y-1'>
<div className='system-2xs-semibold-uppercase text-text-accent'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div> <div className='system-2xs-semibold-uppercase text-text-accent'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div>
@ -70,9 +70,15 @@ const FilePreview = ({
<RiCloseLine className='size-[18px]' /> <RiCloseLine className='size-[18px]' />
</button> </button>
</div> </div>
{isFetching && <Loading />} {isFetching && (
<div className='grow'>
<Loading />
</div>
)}
{!isFetching && fileData && ( {!isFetching && fileData && (
<div className='body-md-regular overflow-hidden px-6 py-5 text-text-secondary'>{fileData.content}</div> <div className='body-md-regular grow overflow-hidden px-6 py-5 text-text-secondary'>
{fileData.content}
</div>
)} )}
</div> </div>
) )

View File

@ -8,17 +8,18 @@ import { formatNumberAbbreviated } from '@/utils/format'
import Loading from './loading' import Loading from './loading'
import { Notion } from '@/app/components/base/icons/src/public/common' import { Notion } from '@/app/components/base/icons/src/public/common'
type NotionPagePreviewProps = { type OnlineDocumentPreviewProps = {
currentPage: NotionPage currentPage: NotionPage
hidePreview: () => void hidePreview: () => void
} }
const NotionPagePreview = ({ const OnlineDocumentPreview = ({
currentPage, currentPage,
hidePreview, hidePreview,
}: NotionPagePreviewProps) => { }: OnlineDocumentPreviewProps) => {
const { t } = useTranslation() const { t } = useTranslation()
// todo: replace with a generic hook for previewing online documents
const { data: notionPageData, isFetching } = usePreviewNotionPage({ const { data: notionPageData, isFetching } = usePreviewNotionPage({
workspaceID: currentPage.workspace_id, workspaceID: currentPage.workspace_id,
pageID: currentPage.page_id, pageID: currentPage.page_id,
@ -26,8 +27,8 @@ const NotionPagePreview = ({
}) })
return ( return (
<div className='h-full rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'> <div className='flex h-full w-full flex-col rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'>
<div className='flex gap-x-2 pb-3 pl-6 pr-4 pt-4'> <div className='flex gap-x-2 border-b border-divider-subtle pb-3 pl-6 pr-4 pt-4'>
<div className='flex grow flex-col gap-y-1'> <div className='flex grow flex-col gap-y-1'>
<div className='system-2xs-semibold-uppercase'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div> <div className='system-2xs-semibold-uppercase'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div>
<div className='title-md-semi-bold text-tex-primary'>{currentPage?.page_name}</div> <div className='title-md-semi-bold text-tex-primary'>{currentPage?.page_name}</div>
@ -52,14 +53,18 @@ const NotionPagePreview = ({
<RiCloseLine className='size-[18px]' /> <RiCloseLine className='size-[18px]' />
</button> </button>
</div> </div>
<div className='px-6 py-5'> {isFetching && (
{isFetching && <Loading />} <div className='grow'>
{!isFetching && notionPageData && ( <Loading />
<div className='body-md-regular overflow-hidden text-text-secondary'>{notionPageData.content}</div> </div>
)} )}
</div> {!isFetching && notionPageData && (
<div className='body-md-regular grow overflow-hidden px-6 py-5 text-text-secondary'>
{notionPageData.content}
</div>
)}
</div> </div>
) )
} }
export default NotionPagePreview export default OnlineDocumentPreview

View File

@ -17,8 +17,8 @@ const WebsitePreview = ({
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
<div className='h-full rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'> <div className='flex h-full w-full flex-col rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'>
<div className='flex gap-x-2 pb-3 pl-6 pr-4 pt-4'> <div className='flex gap-x-2 border-b border-divider-subtle pb-3 pl-6 pr-4 pt-4'>
<div className='flex grow flex-col gap-y-1'> <div className='flex grow flex-col gap-y-1'>
<div className='system-2xs-semibold-uppercase'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div> <div className='system-2xs-semibold-uppercase'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div>
<div className='title-md-semi-bold text-tex-primary'>{payload.title}</div> <div className='title-md-semi-bold text-tex-primary'>{payload.title}</div>
@ -38,8 +38,8 @@ const WebsitePreview = ({
<RiCloseLine className='size-[18px]' /> <RiCloseLine className='size-[18px]' />
</button> </button>
</div> </div>
<div className='px-6 py-5'> <div className='body-md-regular grow overflow-hidden px-6 py-5 text-text-secondary'>
<div className='body-md-regular overflow-hidden text-text-secondary'>{payload.markdown}</div> {payload.markdown}
</div> </div>
</div> </div>
) )

View File

@ -78,7 +78,7 @@ const PipelineSettings = ({
return ( return (
<div <div
className='relative flex h-[calc(100vh-56px)] overflow-x-auto rounded-t-2xl border-t border-effects-highlight bg-background-default-subtle' className='relative flex h-[calc(100vh-56px)] min-w-[1024px] overflow-x-auto rounded-t-2xl border-t border-effects-highlight bg-background-default-subtle'
> >
<div className='flex h-full flex-1 flex-col px-14'> <div className='flex h-full flex-1 flex-col px-14'>
<LeftHeader title={t('datasetPipeline.documentSettings.title')} /> <LeftHeader title={t('datasetPipeline.documentSettings.title')} />

View File

@ -1,20 +1,20 @@
import type { ComponentProps, FC, ReactNode } from 'react' import type { ComponentProps, FC, ReactNode } from 'react'
import { forwardRef } from 'react'
import classNames from '@/utils/classnames' import classNames from '@/utils/classnames'
export type PreviewContainerProps = ComponentProps<'div'> & { export type PreviewContainerProps = ComponentProps<'div'> & {
header: ReactNode header: ReactNode
mainClassName?: string mainClassName?: string
ref?: React.Ref<HTMLDivElement>
} }
export const PreviewContainer: FC<PreviewContainerProps> = forwardRef((props, ref) => { const PreviewContainer: FC<PreviewContainerProps> = (props) => {
const { children, className, header, mainClassName, ...rest } = props const { children, className, header, mainClassName, ref, ...rest } = props
return <div className={className}> return <div className={className}>
<div <div
{...rest} {...rest}
ref={ref} ref={ref}
className={classNames( className={classNames(
'flex flex-col w-full h-full overflow-y-auto rounded-l-xl border-t-[0.5px] border-l-[0.5px] border-components-panel-border bg-background-default-lighter shadow shadow-shadow-shadow-5', 'flex flex-col w-full h-full overflow-y-auto rounded-tl-xl border-t-[0.5px] border-l-[0.5px] border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5',
)} )}
> >
<header className='border-b border-divider-subtle pb-3 pl-5 pr-4 pt-4'> <header className='border-b border-divider-subtle pb-3 pl-5 pr-4 pt-4'>
@ -25,5 +25,8 @@ export const PreviewContainer: FC<PreviewContainerProps> = forwardRef((props, re
</main> </main>
</div> </div>
</div> </div>
}) }
PreviewContainer.displayName = 'PreviewContainer' PreviewContainer.displayName = 'PreviewContainer'
export default PreviewContainer