mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
refactor(knowledge-fs): split document workflow notices
This commit is contained in:
parent
ac3a1d1b77
commit
8c7b9fbbdd
@ -1,46 +1,27 @@
|
||||
import type { RefObject } from 'react'
|
||||
import type { DocumentProcessingTask } from '../models'
|
||||
import { Button } from '@langgenius/dify-ui/button'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useDocumentTaskWorkflow, useDocumentWriteAccess } from './workflow-context'
|
||||
|
||||
export function DocumentDetailStatus({
|
||||
continueLookup,
|
||||
isLookingUpTask,
|
||||
latestTask,
|
||||
lookupExhausted,
|
||||
permissionRecoveryBusy,
|
||||
permissionRecoveryNeeded,
|
||||
refetchTasks,
|
||||
retryWritePermission,
|
||||
reindexInProgress,
|
||||
tasksError,
|
||||
export function DocumentTaskNotices({
|
||||
titleRef,
|
||||
onViewTasks,
|
||||
}: {
|
||||
continueLookup: () => void
|
||||
isLookingUpTask: boolean
|
||||
latestTask?: DocumentProcessingTask
|
||||
lookupExhausted: boolean
|
||||
permissionRecoveryBusy: boolean
|
||||
permissionRecoveryNeeded: boolean
|
||||
refetchTasks: () => void
|
||||
retryWritePermission: () => Promise<boolean>
|
||||
reindexInProgress: boolean
|
||||
tasksError: boolean
|
||||
titleRef: RefObject<HTMLHeadingElement | null>
|
||||
onViewTasks: () => void
|
||||
}) {
|
||||
const { t } = useTranslation('dataset')
|
||||
const { t: tCommon } = useTranslation('common')
|
||||
const permissionRetryRef = useRef<HTMLButtonElement>(null)
|
||||
const permissionRecoveryWasNeededRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (permissionRecoveryNeeded && !permissionRecoveryWasNeededRef.current)
|
||||
requestAnimationFrame(() => permissionRetryRef.current?.focus())
|
||||
permissionRecoveryWasNeededRef.current = permissionRecoveryNeeded
|
||||
}, [permissionRecoveryNeeded])
|
||||
const {
|
||||
continueLookup,
|
||||
isLookingUp: isLookingUpTask,
|
||||
latestTask,
|
||||
lookupExhausted,
|
||||
refetch,
|
||||
reindexInProgress,
|
||||
tasksError,
|
||||
} = useDocumentTaskWorkflow()
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -82,29 +63,7 @@ export function DocumentDetailStatus({
|
||||
role="alert"
|
||||
>
|
||||
<span>{t(($) => $['newKnowledge.tasksErrorDescription'])}</span>
|
||||
<Button onClick={refetchTasks}>{tCommon(($) => $['operation.retry'])}</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{permissionRecoveryNeeded && (
|
||||
<div
|
||||
className="mt-4 flex flex-wrap items-center justify-between gap-2 rounded-lg bg-state-warning-hover px-3 py-2 system-xs-regular text-text-warning"
|
||||
role="alert"
|
||||
>
|
||||
<span>{t(($) => $['newKnowledge.documentPermissionRestricted'])}</span>
|
||||
<Button
|
||||
ref={permissionRetryRef}
|
||||
disabled={permissionRecoveryBusy}
|
||||
loading={permissionRecoveryBusy}
|
||||
onClick={() =>
|
||||
void retryWritePermission().then((recovered) => {
|
||||
if (recovered) titleRef.current?.focus()
|
||||
else permissionRetryRef.current?.focus()
|
||||
})
|
||||
}
|
||||
>
|
||||
{tCommon(($) => $['operation.retry'])}
|
||||
</Button>
|
||||
<Button onClick={() => void refetch()}>{tCommon(($) => $['operation.retry'])}</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@ -139,3 +98,46 @@ export function DocumentDetailStatus({
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function DocumentPermissionRecoveryNotice({
|
||||
titleRef,
|
||||
}: {
|
||||
titleRef: RefObject<HTMLHeadingElement | null>
|
||||
}) {
|
||||
const { t } = useTranslation('dataset')
|
||||
const { t: tCommon } = useTranslation('common')
|
||||
const { permissionRecoveryBusy, permissionRecoveryNeeded, retryWritePermission } =
|
||||
useDocumentWriteAccess()
|
||||
const permissionRetryRef = useRef<HTMLButtonElement>(null)
|
||||
const permissionRecoveryWasNeededRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (permissionRecoveryNeeded && !permissionRecoveryWasNeededRef.current)
|
||||
requestAnimationFrame(() => permissionRetryRef.current?.focus())
|
||||
permissionRecoveryWasNeededRef.current = permissionRecoveryNeeded
|
||||
}, [permissionRecoveryNeeded])
|
||||
|
||||
if (!permissionRecoveryNeeded) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mt-4 flex flex-wrap items-center justify-between gap-2 rounded-lg bg-state-warning-hover px-3 py-2 system-xs-regular text-text-warning"
|
||||
role="alert"
|
||||
>
|
||||
<span>{t(($) => $['newKnowledge.documentPermissionRestricted'])}</span>
|
||||
<Button
|
||||
ref={permissionRetryRef}
|
||||
disabled={permissionRecoveryBusy}
|
||||
loading={permissionRecoveryBusy}
|
||||
onClick={() =>
|
||||
void retryWritePermission().then((recovered) => {
|
||||
if (recovered) titleRef.current?.focus()
|
||||
else permissionRetryRef.current?.focus()
|
||||
})
|
||||
}
|
||||
>
|
||||
{tCommon(($) => $['operation.retry'])}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import { consoleQuery } from '@/service/client'
|
||||
import { logicalDocumentListFromApi } from '../models'
|
||||
import { ProcessingTasksDrawer } from '../tasks/drawer'
|
||||
import { createTaskProgressStore } from '../tasks/progress-store'
|
||||
import { DocumentDetailStatus } from './status'
|
||||
import { DocumentPermissionRecoveryNotice, DocumentTaskNotices } from './status'
|
||||
import { useDocumentTaskWorkflow, useDocumentWriteAccess } from './workflow-context'
|
||||
|
||||
export function DocumentTasksSurface({
|
||||
@ -25,23 +25,17 @@ export function DocumentTasksSurface({
|
||||
}) {
|
||||
const { t } = useTranslation('dataset')
|
||||
const {
|
||||
continueLookup,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchNextPageError,
|
||||
isFetching,
|
||||
isFetchingNextPage,
|
||||
isLookingUp,
|
||||
isPending,
|
||||
latestTask,
|
||||
lookupExhausted,
|
||||
refetch,
|
||||
reindexInProgress,
|
||||
tasks,
|
||||
tasksError,
|
||||
} = useDocumentTaskWorkflow()
|
||||
const { canEdit, permissionRecoveryBusy, permissionRecoveryNeeded, retryWritePermission } =
|
||||
useDocumentWriteAccess()
|
||||
const { canEdit, permissionRecoveryBusy, retryWritePermission } = useDocumentWriteAccess()
|
||||
const [open, setOpen] = useState(false)
|
||||
const taskProgressStoreRef = useRef<ReturnType<typeof createTaskProgressStore> | null>(null)
|
||||
if (!taskProgressStoreRef.current) taskProgressStoreRef.current = createTaskProgressStore()
|
||||
@ -72,20 +66,8 @@ export function DocumentTasksSurface({
|
||||
|
||||
return (
|
||||
<>
|
||||
<DocumentDetailStatus
|
||||
continueLookup={continueLookup}
|
||||
isLookingUpTask={isLookingUp}
|
||||
latestTask={latestTask}
|
||||
lookupExhausted={lookupExhausted}
|
||||
permissionRecoveryBusy={permissionRecoveryBusy}
|
||||
permissionRecoveryNeeded={permissionRecoveryNeeded}
|
||||
refetchTasks={() => void refetch()}
|
||||
reindexInProgress={reindexInProgress}
|
||||
retryWritePermission={retryWritePermission}
|
||||
tasksError={Boolean(tasksError)}
|
||||
titleRef={titleRef}
|
||||
onViewTasks={() => setOpen(true)}
|
||||
/>
|
||||
<DocumentTaskNotices titleRef={titleRef} onViewTasks={() => setOpen(true)} />
|
||||
<DocumentPermissionRecoveryNotice titleRef={titleRef} />
|
||||
<ProcessingTasksDrawer
|
||||
actionResultsValid
|
||||
canEdit={canEdit}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user