fix(datasets): Resolve issue where selected list is not updated when deleting a single file (#26502)

This commit is contained in:
HyaCinth 2025-09-30 23:22:43 +08:00 committed by GitHub
parent 19936d23d1
commit dd71625f52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -418,6 +418,8 @@ const DocumentList: FC<IDocumentListProps> = ({
</td> </td>
<td> <td>
<Operations <Operations
selectedIds={selectedIds}
onSelectedIdChange={onSelectedIdChange}
embeddingAvailable={embeddingAvailable} embeddingAvailable={embeddingAvailable}
datasetId={datasetId} datasetId={datasetId}
detail={pick(doc, ['name', 'enabled', 'archived', 'id', 'data_source_type', 'doc_form', 'display_status'])} detail={pick(doc, ['name', 'enabled', 'archived', 'id', 'data_source_type', 'doc_form', 'display_status'])}

View File

@ -35,7 +35,7 @@ import {
} from '@remixicon/react' } from '@remixicon/react'
import CustomPopover from '../../base/popover' import CustomPopover from '../../base/popover'
import s from './style.module.css' import s from './style.module.css'
import { DataSourceType } from '@/models/datasets' import { DataSourceType, DocumentActionType } from '@/models/datasets'
import Confirm from '../../base/confirm' import Confirm from '../../base/confirm'
import RenameModal from './rename-modal' import RenameModal from './rename-modal'
@ -50,6 +50,8 @@ type OperationsProps = {
doc_form: string doc_form: string
display_status?: string display_status?: string
} }
selectedIds?: string[]
onSelectedIdChange?: (ids: string[]) => void
datasetId: string datasetId: string
onUpdate: (operationName?: string) => void onUpdate: (operationName?: string) => void
scene?: 'list' | 'detail' scene?: 'list' | 'detail'
@ -60,6 +62,8 @@ const Operations = ({
embeddingAvailable, embeddingAvailable,
datasetId, datasetId,
detail, detail,
selectedIds,
onSelectedIdChange,
onUpdate, onUpdate,
scene = 'list', scene = 'list',
className = '', className = '',
@ -116,17 +120,20 @@ const Operations = ({
const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>) const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: id }) as Promise<CommonResponse>)
if (!e) { if (!e) {
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
// If it is a delete operation, need to update the selectedIds state
if (selectedIds && onSelectedIdChange && operationName === DocumentActionType.delete)
onSelectedIdChange(selectedIds.filter(selectedId => selectedId !== id))
onUpdate(operationName) onUpdate(operationName)
} }
else { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) } else { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
if (operationName === 'delete') if (operationName === DocumentActionType.delete)
setDeleting(false) setDeleting(false)
} }
const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => { const { run: handleSwitch } = useDebounceFn((operationName: OperationName) => {
if (operationName === 'enable' && enabled) if (operationName === DocumentActionType.enable && enabled)
return return
if (operationName === 'disable' && !enabled) if (operationName === DocumentActionType.disable && !enabled)
return return
onOperate(operationName) onOperate(operationName)
}, { wait: 500 }) }, { wait: 500 })