diff --git a/web/features/new-rag/documents/detail/state/runtime.ts b/web/features/new-rag/documents/detail/state/runtime.ts index cf2ce3dacd8..accc02d3a8e 100644 --- a/web/features/new-rag/documents/detail/state/runtime.ts +++ b/web/features/new-rag/documents/detail/state/runtime.ts @@ -9,6 +9,10 @@ type DocumentDetailLocationRuntime = { setDocumentLocation: (location: DocumentDetailLocation) => Promise } +type DocumentDetailTitleRuntime = { + focusTitle: () => void +} + const unavailableLocationRuntime = async () => { throw new Error('Document detail location runtime is unavailable') } @@ -17,6 +21,16 @@ export const documentDetailLocationRuntimeAtom = atom({ + focusTitle: () => { + throw new Error('Document detail title runtime is unavailable') + }, +}) + export const selectDocumentChunkAtom = atom(null, (get, _set, chunkId: string) => get(documentDetailLocationRuntimeAtom).setDocumentLocation({ chunk: chunkId }), ) + +export const focusDocumentDetailTitleAtom = atom(null, (get) => { + get(documentDetailTitleRuntimeAtom).focusTitle() +}) diff --git a/web/features/new-rag/documents/detail/status.tsx b/web/features/new-rag/documents/detail/status.tsx index 0db72371d7c..ef03a99a7db 100644 --- a/web/features/new-rag/documents/detail/status.tsx +++ b/web/features/new-rag/documents/detail/status.tsx @@ -1,8 +1,8 @@ -import type { RefObject } from 'react' import { Button } from '@langgenius/dify-ui/button' import { useAtomValue, useSetAtom } from 'jotai' import { useEffect, useRef } from 'react' import { useTranslation } from 'react-i18next' +import { focusDocumentDetailTitleAtom } from './state/runtime' import { continueDocumentTaskLookupAtom, documentLatestTaskAtom, @@ -16,13 +16,7 @@ import { retryDocumentWritePermissionAtom, } from './state/workflow' -export function DocumentTaskNotices({ - titleRef, - onViewTasks, -}: { - titleRef: RefObject - onViewTasks: () => void -}) { +export function DocumentTaskNotices({ onViewTasks }: { onViewTasks: () => void }) { const { t } = useTranslation('dataset') const { t: tCommon } = useTranslation('common') const isLookingUpTask = useAtomValue(documentTaskIsLookingUpAtom) @@ -31,6 +25,7 @@ export function DocumentTaskNotices({ const reindexInProgress = useAtomValue(documentReindexInProgressAtom) const tasksError = useAtomValue(documentTasksQueryErrorAtom) const continueLookup = useSetAtom(continueDocumentTaskLookupAtom) + const focusTitle = useSetAtom(focusDocumentDetailTitleAtom) const retryTasks = useSetAtom(retryDocumentTasksAtom) return ( @@ -96,7 +91,7 @@ export function DocumentTaskNotices({ - - )} {taskQueryError && (

@@ -432,7 +393,7 @@ export function ProcessingTasksDrawer({ }} onClick={() => { queryRetryFocusRequestedRef.current = true - onRetryTaskQuery() + void retryTasks() }} > {tCommon(($) => $['operation.retry'])} @@ -456,7 +417,7 @@ export function ProcessingTasksDrawer({ }} onClick={() => { queryRetryFocusRequestedRef.current = true - onRetryDocumentQuery() + void retryDocuments() }} > {tCommon(($) => $['operation.retry'])} @@ -482,9 +443,6 @@ export function ProcessingTasksDrawer({ ($) => $[`newKnowledge.overview.operation.${task.operation}`], ) const progress = taskProgress(task) - const sourceTitle = task.sourceId - ? sourceNames?.get(task.sourceId) - : undefined const title = task.operation === 'document_processing' && documentTitle ? `${t(($) => $['newKnowledge.addDocument'])} · ${documentTitle}` @@ -494,11 +452,9 @@ export function ProcessingTasksDrawer({ ? `${t(($) => $['newKnowledge.reindexDocuments'])}${progress ? ` · ${progress.total}` : documentTitle ? ` · ${documentTitle}` : ''}` : task.operation === 'document_delete' && documentTitle ? `${operationTitle} · ${documentTitle}` - : sourceTitle - ? `${operationTitle} · ${sourceTitle}` - : progress - ? `${operationTitle} · ${progress.total}` - : operationTitle + : progress + ? `${operationTitle} · ${progress.total}` + : operationTitle const timestamp = Date.parse( taskIsActive(task) ? task.createdAt : taskTime(task), ) @@ -656,8 +612,9 @@ export function ProcessingTasksDrawer({ loadMoreRequestedRef.current = document.activeElement === loadMoreButtonRef.current if (tasks.length <= orderedBaseTasks.length && hasNextTaskPage) - onLoadMoreTasks() - if (hasUnresolvedTaskDocuments && hasNextDocumentPage) onLoadMoreDocuments() + void loadMoreTasks() + if (hasUnresolvedTaskDocuments && hasNextDocumentPage) + void documentsQuery.fetchNextPage() setVisibleTaskLimit((current) => current + TASK_DRAWER_LIMIT) }} >