diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index ac8f2c873a..8381125f2f 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -1,10 +1,8 @@ 'use client' -import type { FC, PropsWithChildren, ReactNode } from 'react' -import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react' +import type { FC, PropsWithChildren } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' -import { useBoolean } from 'ahooks' -import { XMarkIcon } from '@heroicons/react/20/solid' import { RiArrowLeftLine, RiCloseLine, @@ -65,13 +63,6 @@ const TextLabel: FC = (props) => { return } -const FormField: FC> = (props) => { - return
- {props.label} - {props.children} -
-} - type ValueOf = T[keyof T] type StepTwoProps = { isSetting?: boolean @@ -117,7 +108,6 @@ type ParentChildConfig = { delimiter: string maxLength: number } - rules: PreProcessingRule[] } const defaultParentChildConfig: ParentChildConfig = { @@ -130,7 +120,6 @@ const defaultParentChildConfig: ParentChildConfig = { delimiter: '\\n\\n', maxLength: 4000, }, - rules: [], } const StepTwo = ({ @@ -162,10 +151,6 @@ const StepTwo = ({ const { dataset: currentDataset, mutateDatasetRes } = useDatasetDetailContext() const isInCreatePage = !datasetId || (datasetId && !currentDataset?.data_source_type) const dataSourceType = isInCreatePage ? inCreatePageDataSourceType : currentDataset?.data_source_type - const scrollRef = useRef(null) - const [scrolled, setScrolled] = useState(false) - const previewScrollRef = useRef(null) - const [previewScrolled, setPreviewScrolled] = useState(false) const [segmentationType, setSegmentationType] = useState(SegmentType.AUTO) const [segmentIdentifier, doSetSegmentIdentifier] = useState(DEFAULT_SEGMENT_IDENTIFIER) const setSegmentIdentifier = useCallback((value: string) => { @@ -191,32 +176,17 @@ const StepTwo = ({ ) const [QATipHide, setQATipHide] = useState(false) const [previewSwitched, setPreviewSwitched] = useState(false) - const [showPreview, { setTrue: setShowPreview, setFalse: hidePreview }] = useBoolean() const [customFileIndexingEstimate, setCustomFileIndexingEstimate] = useState(null) const [automaticFileIndexingEstimate, setAutomaticFileIndexingEstimate] = useState(null) - const fileIndexingEstimate = (() => { - return segmentationType === SegmentType.AUTO ? automaticFileIndexingEstimate : customFileIndexingEstimate - })() + const fileIndexingEstimate = segmentationType === SegmentType.AUTO + ? automaticFileIndexingEstimate + : customFileIndexingEstimate + const [isCreating, setIsCreating] = useState(false) const [parentChildConfig, setParentChildConfig] = useState(defaultParentChildConfig) - const scrollHandle = (e: Event) => { - if ((e.target as HTMLDivElement).scrollTop > 0) - setScrolled(true) - - else - setScrolled(false) - } - - const previewScrollHandle = (e: Event) => { - if ((e.target as HTMLDivElement).scrollTop > 0) - setPreviewScrolled(true) - - else - setPreviewScrolled(false) - } const getFileName = (name: string) => { const arr = name.split('.') return arr.slice(0, -1).join('.') @@ -248,7 +218,7 @@ const StepTwo = ({ if (defaultConfig) { setSegmentIdentifier(defaultConfig.segmentation.separator) setMax(defaultConfig.segmentation.max_tokens) - setOverlap(defaultConfig.segmentation.chunk_overlap) + setOverlap(defaultConfig.segmentation.chunk_overlap!) setRules(defaultConfig.pre_processing_rules) } setParentChildConfig(defaultParentChildConfig) @@ -263,13 +233,12 @@ const StepTwo = ({ setAutomaticFileIndexingEstimate(res) } - const confirmChangeCustomConfig = () => { + const updatePreview = () => { if (segmentationType === SegmentType.CUSTOM && max > 4000) { Toast.notify({ type: 'error', message: t('datasetCreation.stepTwo.maxLengthCheck') }) return } setCustomFileIndexingEstimate(null) - setShowPreview() fetchFileIndexingEstimate() setPreviewSwitched(false) } @@ -468,7 +437,7 @@ const StepTwo = ({ const separator = res.rules.segmentation.separator setSegmentIdentifier(separator) setMax(res.rules.segmentation.max_tokens) - setOverlap(res.rules.segmentation.chunk_overlap) + setOverlap(res.rules.segmentation.chunk_overlap!) setRules(res.rules.pre_processing_rules) setDefaultConfig(res.rules) } @@ -540,8 +509,8 @@ const StepTwo = ({ } } - const handleSwitch = (state: boolean) => { - if (state) + const handleDocformSwitch = (isQAMode: boolean) => { + if (isQAMode) setDocForm(DocForm.QA) else setDocForm(DocForm.TEXT) @@ -587,22 +556,6 @@ const StepTwo = ({ } }, []) - useEffect(() => { - scrollRef.current?.addEventListener('scroll', scrollHandle) - return () => { - scrollRef.current?.removeEventListener('scroll', scrollHandle) - } - }, []) - - useLayoutEffect(() => { - if (showPreview) { - previewScrollRef.current?.addEventListener('scroll', previewScrollHandle) - return () => { - previewScrollRef.current?.removeEventListener('scroll', previewScrollHandle) - } - } - }, [showPreview]) - useEffect(() => { if (indexingType === IndexingType.ECONOMICAL && docForm === DocForm.QA) setDocForm(DocForm.TEXT) @@ -620,12 +573,10 @@ const StepTwo = ({ useEffect(() => { if (segmentationType === SegmentType.AUTO) { setAutomaticFileIndexingEstimate(null) - !isMobile && setShowPreview() fetchFileIndexingEstimate() setPreviewSwitched(false) } else { - hidePreview() setCustomFileIndexingEstimate(null) setPreviewSwitched(false) } @@ -659,7 +610,7 @@ const StepTwo = ({ onClick={() => setSegmentationType(SegmentType.AUTO)} actions={ <> - @@ -714,7 +665,7 @@ const StepTwo = ({ onClick={() => setSegmentationType(SegmentType.CUSTOM)} actions={ <> - @@ -910,7 +861,7 @@ const StepTwo = ({ @@ -1000,11 +951,10 @@ const StepTwo = ({ { }} footer={null}> - {showPreview &&
-
+
{t('datasetCreation.stepTwo.previewTitle')}
@@ -1012,9 +962,6 @@ const StepTwo = ({ )}
-
- -
{docForm === DocForm.QA && !previewSwitched && (
@@ -1049,21 +996,7 @@ const StepTwo = ({
)}
-
} - {!showPreview && ( -
-
- -
{t('datasetCreation.stepTwo.sideTipTitle')}
-
-

{t('datasetCreation.stepTwo.sideTipP1')}

-

{t('datasetCreation.stepTwo.sideTipP2')}

-

{t('datasetCreation.stepTwo.sideTipP3')}

-

{t('datasetCreation.stepTwo.sideTipP4')}

-
-
-
- )} +
)