import type { DocumentProcessingTask } from '@dify/contracts/knowledge-fs/types.gen' import type { RefObject } from 'react' import { Button } from '@langgenius/dify-ui/button' import { useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' export function DocumentDetailStatus({ continueLookup, effectiveRevision, isLookingUpTask, latestTask, locale, lookupExhausted, permissionRecoveryBusy, permissionRecoveryNeeded, recheckTimedOutSubmission, refetchRevisions, refetchTasks, retryTimedOutSubmission, retryWritePermission, revisionHistoryBackgroundError, submissionRecoveryBusy, submissionTimedOut, taskIsActive, tasksError, titleRef, }: { continueLookup: () => void effectiveRevision?: number isLookingUpTask: boolean latestTask?: DocumentProcessingTask locale: string lookupExhausted: boolean permissionRecoveryBusy: boolean permissionRecoveryNeeded: boolean recheckTimedOutSubmission: () => Promise refetchRevisions: () => void refetchTasks: () => void retryTimedOutSubmission: () => Promise retryWritePermission: () => Promise revisionHistoryBackgroundError: boolean submissionRecoveryBusy: boolean submissionTimedOut: boolean taskIsActive: boolean tasksError: boolean titleRef: RefObject }) { const { t } = useTranslation('dataset') const { t: tCommon } = useTranslation('common') const permissionRetryRef = useRef(null) const permissionRecoveryWasNeededRef = useRef(false) useEffect(() => { if (permissionRecoveryNeeded && !permissionRecoveryWasNeededRef.current) requestAnimationFrame(() => permissionRetryRef.current?.focus()) permissionRecoveryWasNeededRef.current = permissionRecoveryNeeded }, [permissionRecoveryNeeded]) return ( <> {taskIsActive && (
{t(($) => $['newKnowledge.documentReindexProgress'], { progress: new Intl.NumberFormat(locale).format(latestTask?.progressPercent ?? 0), })}
)} {latestTask?.state === 'failed' && (

{t(($) => $['newKnowledge.documentReindexFailed'])}

{t(($) => $['newKnowledge.lastReadyRevisionHint'])}

)} {tasksError && (
{t(($) => $['newKnowledge.tasksErrorDescription'])}
)} {permissionRecoveryNeeded && (
{t(($) => $['newKnowledge.documentPermissionRestricted'])}
)} {(lookupExhausted || isLookingUpTask) && (
{isLookingUpTask ? ( {tCommon(($) => $.loading)} ) : ( <> {t(($) => $['newKnowledge.documentTaskLookupIncomplete'])} )}
)} {submissionTimedOut && (
{t(($) => $['newKnowledge.documentReindexConfirmationDelayed'])}
)} {revisionHistoryBackgroundError && effectiveRevision !== undefined && (
{t(($) => $['newKnowledge.documentRevisionsLoadError'])}
)} ) }