fix: add spin to parsing status icon of dataset table (#649)
### What problem does this PR solve? fix: add spin to parsing status icon of dataset table #648 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -2,7 +2,9 @@ import { useSetModalState, useTranslate } from '@/hooks/commonHooks';
|
||||
import {
|
||||
useCreateDocument,
|
||||
useFetchDocumentList,
|
||||
useRunDocument,
|
||||
useSaveDocumentName,
|
||||
useSelectRunDocumentLoading,
|
||||
useSetDocumentParser,
|
||||
useUploadDocument,
|
||||
} from '@/hooks/documentHooks';
|
||||
@@ -283,3 +285,36 @@ export const useHandleUploadDocument = () => {
|
||||
showDocumentUploadModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useHandleRunDocumentByIds = (id: string) => {
|
||||
const loading = useSelectRunDocumentLoading();
|
||||
const runDocumentByIds = useRunDocument();
|
||||
const [currentId, setCurrentId] = useState<string>('');
|
||||
const isLoading = loading && currentId !== '' && currentId === id;
|
||||
|
||||
const handleRunDocumentByIds = async (
|
||||
documentId: string,
|
||||
knowledgeBaseId: string,
|
||||
isRunning: boolean,
|
||||
) => {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
setCurrentId(documentId);
|
||||
try {
|
||||
await runDocumentByIds({
|
||||
doc_ids: [documentId],
|
||||
run: isRunning ? 2 : 1,
|
||||
knowledgeBaseId,
|
||||
});
|
||||
setCurrentId('');
|
||||
} catch (error) {
|
||||
setCurrentId('');
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
handleRunDocumentByIds,
|
||||
loading: isLoading,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user