| import type { FC } from 'react' | import type { FC } from 'react' | ||||
| import React, { useCallback, useMemo, useState } from 'react' | |||||
| import React, { useCallback, useEffect, useMemo, useState } from 'react' | |||||
| import useSWR from 'swr' | import useSWR from 'swr' | ||||
| import { useRouter } from 'next/navigation' | import { useRouter } from 'next/navigation' | ||||
| import { useContext } from 'use-context-selector' | import { useContext } from 'use-context-selector' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| import { omit } from 'lodash-es' | import { omit } from 'lodash-es' | ||||
| import cn from 'classnames' | |||||
| import { ArrowRightIcon } from '@heroicons/react/24/solid' | import { ArrowRightIcon } from '@heroicons/react/24/solid' | ||||
| import { useGetState } from 'ahooks' | |||||
| import cn from 'classnames' | |||||
| import SegmentCard from '../completed/SegmentCard' | import SegmentCard from '../completed/SegmentCard' | ||||
| import { FieldInfo } from '../metadata' | import { FieldInfo } from '../metadata' | ||||
| import style from '../completed/style.module.css' | import style from '../completed/style.module.css' | ||||
| import type { CommonResponse } from '@/models/common' | import type { CommonResponse } from '@/models/common' | ||||
| import { asyncRunSafe } from '@/utils' | import { asyncRunSafe } from '@/utils' | ||||
| import { formatNumber } from '@/utils/format' | import { formatNumber } from '@/utils/format' | ||||
| import { fetchIndexingEstimate, fetchProcessRule, pauseDocIndexing, resumeDocIndexing } from '@/service/datasets' | |||||
| import { fetchIndexingStatus as doFetchIndexingStatus, fetchIndexingEstimate, fetchProcessRule, pauseDocIndexing, resumeDocIndexing } from '@/service/datasets' | |||||
| import DatasetDetailContext from '@/context/dataset-detail' | import DatasetDetailContext from '@/context/dataset-detail' | ||||
| import StopEmbeddingModal from '@/app/components/datasets/create/stop-embedding-modal' | import StopEmbeddingModal from '@/app/components/datasets/create/stop-embedding-modal' | ||||
| } | } | ||||
| const [runId, setRunId, getRunId] = useGetState<any>(null) | const [runId, setRunId, getRunId] = useGetState<any>(null) | ||||
| const stopQueryStatus = () => { | |||||
| clearInterval(getRunId()) | |||||
| } | |||||
| const startQueryStatus = () => { | const startQueryStatus = () => { | ||||
| const runId = setInterval(() => { | const runId = setInterval(() => { | ||||
| const indexingStatusDetail = getIndexingStatusDetail() | const indexingStatusDetail = getIndexingStatusDetail() | ||||
| if (indexingStatusDetail?.indexing_status === 'completed') { | if (indexingStatusDetail?.indexing_status === 'completed') { | ||||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | |||||
| stopQueryStatus() | stopQueryStatus() | ||||
| return | return | ||||
| } | } | ||||
| }, 2500) | }, 2500) | ||||
| setRunId(runId) | setRunId(runId) | ||||
| } | } | ||||
| const stopQueryStatus = () => { | |||||
| clearInterval(getRunId()) | |||||
| } | |||||
| useEffect(() => { | useEffect(() => { | ||||
| fetchIndexingStatus() | fetchIndexingStatus() | ||||
| key={idx} | key={idx} | ||||
| className={cn(s.progressBgItem, isEmbedding ? 'bg-primary-50' : 'bg-gray-100')} | className={cn(s.progressBgItem, isEmbedding ? 'bg-primary-50' : 'bg-gray-100')} | ||||
| />)} | />)} | ||||
| <div className={ | |||||
| cn('rounded-l-md', | |||||
| <div | |||||
| className={cn( | |||||
| 'rounded-l-md', | |||||
| s.progressBar, | s.progressBar, | ||||
| (isEmbedding || isEmbeddingCompleted) && s.barProcessing, | (isEmbedding || isEmbeddingCompleted) && s.barProcessing, | ||||
| (isEmbeddingPaused || isEmbeddingError) && s.barPaused, | (isEmbeddingPaused || isEmbeddingError) && s.barPaused, | ||||
| indexingStatusDetail?.indexing_status === 'completed' && 'rounded-r-md') | |||||
| } | |||||
| style={{ width: `${percent}%` }} | |||||
| indexingStatusDetail?.indexing_status === 'completed' && 'rounded-r-md', | |||||
| )} | |||||
| style={{ width: `${percent}%` }} | |||||
| /> | /> | ||||
| </div> | </div> | ||||
| <div className={s.progressData}> | <div className={s.progressData}> |