|
@@ -42,12 +42,20 @@ import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '
|
|
|
import type { Props as PaginationProps } from '@/app/components/base/pagination'
|
|
|
import Pagination from '@/app/components/base/pagination'
|
|
|
import Checkbox from '@/app/components/base/checkbox'
|
|
|
-import { useDocumentArchive, useDocumentDelete, useDocumentDisable, useDocumentEnable, useDocumentUnArchive, useSyncDocument, useSyncWebsite } from '@/service/knowledge/use-document'
|
|
|
+import {
|
|
|
+ useDocumentArchive,
|
|
|
+ useDocumentCheckFail,
|
|
|
+ useDocumentDelete,
|
|
|
+ useDocumentDisable,
|
|
|
+ useDocumentEnable,
|
|
|
+ useDocumentUnArchive,
|
|
|
+ useSyncDocument,
|
|
|
+ useSyncWebsite,
|
|
|
+} from '@/service/knowledge/use-document'
|
|
|
import { extensionToFileType } from '@/app/components/datasets/hit-testing/utils/extension-to-file-type'
|
|
|
import useBatchEditDocumentMetadata from '../metadata/hooks/use-batch-edit-document-metadata'
|
|
|
import EditMetadataBatchModal from '@/app/components/datasets/metadata/edit-metadata-batch/modal'
|
|
|
import { useAppContext } from '@/context/app-context'
|
|
|
-import { applyExamine, handleExamine } from '@/service/common'
|
|
|
|
|
|
export const useIndexStatus = () => {
|
|
|
const { t } = useTranslation()
|
|
@@ -169,7 +177,7 @@ export const StatusItem: FC<{
|
|
|
</div>
|
|
|
}
|
|
|
|
|
|
-type OperationName = 'delete' | 'archive' | 'enable' | 'disable' | 'sync' | 'un_archive'
|
|
|
+type OperationName = 'delete' | 'archive' | 'enable' | 'disable' | 'sync' | 'un_archive' | 'check_fail'
|
|
|
|
|
|
// operation action for list and detail
|
|
|
export const OperationAction: FC<{
|
|
@@ -181,6 +189,7 @@ export const OperationAction: FC<{
|
|
|
id: string
|
|
|
data_source_type: string
|
|
|
doc_form: string
|
|
|
+ check_status: number
|
|
|
}
|
|
|
datasetId: string
|
|
|
onUpdate: (operationName?: string) => void
|
|
@@ -273,28 +282,21 @@ export const OperationAction: FC<{
|
|
|
setShowNotDelModal(true)
|
|
|
}
|
|
|
const [showApplyExamine, setShowApplyExamine] = useState<boolean>(false)
|
|
|
+ const appContext = useAppContext()
|
|
|
const beforeHandleSwitch = () => {
|
|
|
- if (false) { // 待审核
|
|
|
+ if (detail.check_status === 1) { // 待审核
|
|
|
setShowNotSwitchModal(true)
|
|
|
return false
|
|
|
}
|
|
|
- if (true) { // 提交审批
|
|
|
+ if (!['owner', 'admin'].includes(appContext.currentWorkspace.role)) { // 提交审批
|
|
|
setShowApplyExamine(true)
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
- const onApplyExamine = useCallback(async () => {
|
|
|
- try {
|
|
|
- const { result }: any = await applyExamine({
|
|
|
- url: '/workspaces/123123',
|
|
|
- body: { id: detail.id, enabled: !detail.enabled },
|
|
|
- })
|
|
|
- onUpdate?.()
|
|
|
- setShowApplyExamine(false)
|
|
|
- }
|
|
|
- catch (e) { }
|
|
|
- }, [detail, onUpdate, setShowApplyExamine])
|
|
|
+ const onApplyExamine = () => {
|
|
|
+ handleSwitch(enabled ? 'disable' : 'enable')
|
|
|
+ }
|
|
|
|
|
|
return <div className='flex items-center' onClick={e => e.stopPropagation()}>
|
|
|
{isListScene && !embeddingAvailable && (
|
|
@@ -552,6 +554,7 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
const { mutateAsync: enableDocument } = useDocumentEnable()
|
|
|
const { mutateAsync: disableDocument } = useDocumentDisable()
|
|
|
const { mutateAsync: deleteDocument } = useDocumentDelete()
|
|
|
+ const { mutateAsync: checkFailDocument } = useDocumentCheckFail()
|
|
|
|
|
|
const handleAction = (actionName: DocumentActionType) => {
|
|
|
return async () => {
|
|
@@ -579,6 +582,11 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
else { Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
|
|
|
}
|
|
|
}
|
|
|
+ const ExamineMap = {
|
|
|
+ 1: '待审核',
|
|
|
+ 2: '审核不通过',
|
|
|
+ 3: '无',
|
|
|
+ }
|
|
|
const appContext = useAppContext()
|
|
|
const [row, setRow] = useState<any>({})
|
|
|
const [showConfirmExamineResult, setShowConfirmExamineResult] = useState(false)
|
|
@@ -586,17 +594,36 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
const [showConfirmExamineHandle, setShowConfirmExamineHandle] = useState(false)
|
|
|
const [confirmExamineHandleTitle, setConfirmExamineHandleTitle] = useState('')
|
|
|
const [confirmExamineHandleContent, setConfirmExamineHandleContent] = useState('')
|
|
|
- const onHandleExamine = useCallback(async () => {
|
|
|
- try {
|
|
|
- const { result }: any = await handleExamine({
|
|
|
- url: '/workspaces/123123',
|
|
|
- body: { id: row.id, enabled: !row.enabled },
|
|
|
- })
|
|
|
- onUpdate?.()
|
|
|
- setShowConfirmExamineHandle(false)
|
|
|
+ const { notify } = useContext(ToastContext)
|
|
|
+
|
|
|
+ const onOperate = async (operationName: OperationName) => {
|
|
|
+ let opApi = checkFailDocument
|
|
|
+ switch (operationName) {
|
|
|
+ case 'check_fail':
|
|
|
+ opApi = checkFailDocument
|
|
|
+ break
|
|
|
+ case 'enable':
|
|
|
+ opApi = enableDocument
|
|
|
+ break
|
|
|
+ case 'disable':
|
|
|
+ opApi = disableDocument
|
|
|
+ break
|
|
|
}
|
|
|
- catch (e) { }
|
|
|
- }, [row, onUpdate, setShowConfirmExamineHandle])
|
|
|
+ const [e] = await asyncRunSafe<CommonResponse>(opApi({ datasetId, documentId: row.id }) as Promise<CommonResponse>)
|
|
|
+ if (!e) {
|
|
|
+ notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
|
|
+ onUpdate()
|
|
|
+ }
|
|
|
+ else { notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) }
|
|
|
+ onUpdate()
|
|
|
+ setShowConfirmExamineHandle(false)
|
|
|
+ }
|
|
|
+ const onHandleExamine = (flag: boolean) => {
|
|
|
+ if (flag)
|
|
|
+ onOperate(row.enabled ? 'disable' : 'enable')
|
|
|
+ else
|
|
|
+ onOperate('check_fail')
|
|
|
+ }
|
|
|
return (
|
|
|
<div className='relative flex h-full w-full flex-col'>
|
|
|
<div className='relative grow overflow-x-auto'>
|
|
@@ -643,7 +670,7 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
key={doc.id}
|
|
|
className={'h-8 cursor-pointer border-b border-divider-subtle hover:bg-background-default-hover'}
|
|
|
onClick={() => {
|
|
|
- router.push(`/datasets/${datasetId}/documents/${doc.id}`)
|
|
|
+ (doc.check_status === 2 || doc.check_status === 3) && router.push(`/datasets/${datasetId}/documents/${doc.id}`)
|
|
|
}}>
|
|
|
<td className='text-left align-middle text-xs text-text-tertiary'>
|
|
|
<div className='flex items-center' onClick={e => e.stopPropagation()}>
|
|
@@ -706,46 +733,43 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
}
|
|
|
</td>
|
|
|
<td>
|
|
|
- {/* { */}
|
|
|
- {/* true && ( */}
|
|
|
- {/* <div className="cursor text-[#155aef]" onClick={e => { */}
|
|
|
- {/* e.stopPropagation() */}
|
|
|
- {/* setConfirmExamineResultContent(`用户“${doc.name}”不同意将该知识上线!`) */}
|
|
|
- {/* setShowConfirmExamineResult(true) */}
|
|
|
- {/* }}>审核不通过</div> */}
|
|
|
- {/* ) */}
|
|
|
- {/* } */}
|
|
|
{
|
|
|
- true && (
|
|
|
+ doc.check_status === 1 && (
|
|
|
['owner', 'admin'].includes(appContext.currentWorkspace.role)
|
|
|
? <div className="cursor-pointer text-[#155aef]" onClick={(e) => {
|
|
|
e.stopPropagation()
|
|
|
setRow(doc)
|
|
|
setConfirmExamineHandleTitle(`${doc.enabled ? '下线' : '上线'}审核`)
|
|
|
- setConfirmExamineHandleContent(`用户“${doc.name}”申请将该知识${doc.enabled ? '下线' : '上线'},请审核!`)
|
|
|
+ setConfirmExamineHandleContent(`用户“${doc.enable_application}”申请将该知识${doc.enabled ? '下线' : '上线'},请审核!`)
|
|
|
setShowConfirmExamineHandle(true)
|
|
|
- }}>待审核</div>
|
|
|
- : <div>待审核</div>
|
|
|
+ }}>{ExamineMap[doc.check_status]}</div>
|
|
|
+ : <div>{ExamineMap[doc.check_status]}</div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ {
|
|
|
+ doc.check_status === 2 && (
|
|
|
+ <div className="cursor text-[#155aef]" onClick={(e) => {
|
|
|
+ e.stopPropagation()
|
|
|
+ setConfirmExamineResultContent(`用户“${doc.check_by}”不同意将该知识上线!`)
|
|
|
+ setShowConfirmExamineResult(true)
|
|
|
+ }}>{ExamineMap[doc.check_status]}</div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ {
|
|
|
+ doc.check_status === 3 && (
|
|
|
+ <div>{ExamineMap[doc.check_status]}</div>
|
|
|
)
|
|
|
}
|
|
|
- {/* { */}
|
|
|
- {/* index === 2 && ( */}
|
|
|
- {/* <div className="cursor text-[#155aef]" onClick={(e) => { */}
|
|
|
- {/* e.stopPropagation() */}
|
|
|
- {/* setConfirmExamineResultContent(`用户“${doc.name}”不同意将该知识上线!`) */}
|
|
|
- {/* setShowConfirmExamineResult(true) */}
|
|
|
- {/* }}>无</div> */}
|
|
|
- {/* ) */}
|
|
|
- {/* } */}
|
|
|
-
|
|
|
</td>
|
|
|
<td>
|
|
|
- <OperationAction
|
|
|
- embeddingAvailable={embeddingAvailable}
|
|
|
- datasetId={datasetId}
|
|
|
- detail={pick(doc, ['name', 'enabled', 'archived', 'id', 'data_source_type', 'doc_form'])}
|
|
|
- onUpdate={onUpdate}
|
|
|
- />
|
|
|
+ {
|
|
|
+ (doc.check_status === 2 || doc.check_status === 3) && (<OperationAction
|
|
|
+ embeddingAvailable={embeddingAvailable}
|
|
|
+ datasetId={datasetId}
|
|
|
+ detail={pick(doc, ['name', 'enabled', 'archived', 'id', 'data_source_type', 'doc_form', 'check_status'])}
|
|
|
+ onUpdate={onUpdate}
|
|
|
+ />)
|
|
|
+ }
|
|
|
</td>
|
|
|
</tr>
|
|
|
})}
|
|
@@ -813,8 +837,8 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|
|
title={confirmExamineHandleTitle}
|
|
|
content={confirmExamineHandleContent}
|
|
|
isShow={showConfirmExamineHandle}
|
|
|
- onConfirm={() => onHandleExamine()}
|
|
|
- onCancel={() => setShowConfirmExamineHandle(false)}
|
|
|
+ onConfirm={() => onHandleExamine(true)}
|
|
|
+ onCancel={() => onHandleExamine(false)}
|
|
|
confirmText="同意"
|
|
|
cancelText="不同意"
|
|
|
/>
|