yangdx
commited on
Commit
·
d760937
1
Parent(s):
a1fbc3d
feat(ui): Improve document list refresh mechanism in ClearDocumentsDialog
Browse files- Replace direct API call with callback pattern for document list refresh
- Ensure document list updates regardless of operation success/failure
- Improve component decoupling between ClearDocumentsDialog and DocumentManager
lightrag_webui/src/components/documents/ClearDocumentsDialog.tsx
CHANGED
@@ -13,7 +13,7 @@ import Input from '@/components/ui/Input'
|
|
13 |
import Checkbox from '@/components/ui/Checkbox'
|
14 |
import { toast } from 'sonner'
|
15 |
import { errorMessage } from '@/lib/utils'
|
16 |
-
import { clearDocuments, clearCache
|
17 |
import { useBackendState } from '@/stores/state'
|
18 |
|
19 |
import { EraserIcon, AlertTriangleIcon } from 'lucide-react'
|
@@ -35,7 +35,11 @@ const Label = ({
|
|
35 |
</label>
|
36 |
)
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
39 |
const { t } = useTranslation()
|
40 |
const [open, setOpen] = useState(false)
|
41 |
const [confirmText, setConfirmText] = useState('')
|
@@ -55,10 +59,8 @@ export default function ClearDocumentsDialog() {
|
|
55 |
if (!isConfirmEnabled) return
|
56 |
|
57 |
try {
|
58 |
-
// 清空文档
|
59 |
const result = await clearDocuments()
|
60 |
|
61 |
-
// 如果选择了清空缓存,则清空缓存
|
62 |
if (clearCacheOption) {
|
63 |
try {
|
64 |
await clearCache()
|
@@ -70,23 +72,28 @@ export default function ClearDocumentsDialog() {
|
|
70 |
|
71 |
if (result.status === 'success') {
|
72 |
toast.success(t('documentPanel.clearDocuments.success'))
|
73 |
-
|
74 |
-
// 刷新文档列表和后端状态
|
75 |
-
try {
|
76 |
-
await getDocuments()
|
77 |
-
check()
|
78 |
-
} catch (refreshErr) {
|
79 |
-
console.error('Error refreshing documents:', refreshErr)
|
80 |
-
}
|
81 |
-
|
82 |
-
setOpen(false)
|
83 |
} else {
|
84 |
toast.error(t('documentPanel.clearDocuments.failed', { message: result.message }))
|
85 |
}
|
86 |
} catch (err) {
|
87 |
toast.error(t('documentPanel.clearDocuments.error', { error: errorMessage(err) }))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
}
|
89 |
-
}, [isConfirmEnabled, clearCacheOption, setOpen, t, check])
|
90 |
|
91 |
return (
|
92 |
<Dialog open={open} onOpenChange={setOpen}>
|
|
|
13 |
import Checkbox from '@/components/ui/Checkbox'
|
14 |
import { toast } from 'sonner'
|
15 |
import { errorMessage } from '@/lib/utils'
|
16 |
+
import { clearDocuments, clearCache } from '@/api/lightrag'
|
17 |
import { useBackendState } from '@/stores/state'
|
18 |
|
19 |
import { EraserIcon, AlertTriangleIcon } from 'lucide-react'
|
|
|
35 |
</label>
|
36 |
)
|
37 |
|
38 |
+
interface ClearDocumentsDialogProps {
|
39 |
+
onDocumentsCleared?: () => Promise<void>
|
40 |
+
}
|
41 |
+
|
42 |
+
export default function ClearDocumentsDialog({ onDocumentsCleared }: ClearDocumentsDialogProps) {
|
43 |
const { t } = useTranslation()
|
44 |
const [open, setOpen] = useState(false)
|
45 |
const [confirmText, setConfirmText] = useState('')
|
|
|
59 |
if (!isConfirmEnabled) return
|
60 |
|
61 |
try {
|
|
|
62 |
const result = await clearDocuments()
|
63 |
|
|
|
64 |
if (clearCacheOption) {
|
65 |
try {
|
66 |
await clearCache()
|
|
|
72 |
|
73 |
if (result.status === 'success') {
|
74 |
toast.success(t('documentPanel.clearDocuments.success'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
} else {
|
76 |
toast.error(t('documentPanel.clearDocuments.failed', { message: result.message }))
|
77 |
}
|
78 |
} catch (err) {
|
79 |
toast.error(t('documentPanel.clearDocuments.error', { error: errorMessage(err) }))
|
80 |
+
} finally {
|
81 |
+
// Execute these operations regardless of success or failure
|
82 |
+
try {
|
83 |
+
// Update backend state
|
84 |
+
await check()
|
85 |
+
|
86 |
+
// Refresh document list
|
87 |
+
if (onDocumentsCleared) {
|
88 |
+
await onDocumentsCleared()
|
89 |
+
}
|
90 |
+
} catch (refreshErr) {
|
91 |
+
console.error('Error refreshing state:', refreshErr)
|
92 |
+
}
|
93 |
+
|
94 |
+
setOpen(false)
|
95 |
}
|
96 |
+
}, [isConfirmEnabled, clearCacheOption, setOpen, t, check, onDocumentsCleared])
|
97 |
|
98 |
return (
|
99 |
<Dialog open={open} onOpenChange={setOpen}>
|
lightrag_webui/src/features/DocumentManager.tsx
CHANGED
@@ -386,7 +386,7 @@ export default function DocumentManager() {
|
|
386 |
</Button>
|
387 |
</div>
|
388 |
<div className="flex-1" />
|
389 |
-
<ClearDocumentsDialog />
|
390 |
<UploadDocumentsDialog />
|
391 |
<PipelineStatusDialog
|
392 |
open={showPipelineStatus}
|
|
|
386 |
</Button>
|
387 |
</div>
|
388 |
<div className="flex-1" />
|
389 |
+
<ClearDocumentsDialog onDocumentsCleared={fetchDocuments} />
|
390 |
<UploadDocumentsDialog />
|
391 |
<PipelineStatusDialog
|
392 |
open={showPipelineStatus}
|