Feat: Allow users to parse documents directly after uploading files #3221 (#9633)

### What problem does this PR solve?

Feat: Allow users to parse documents directly after uploading files
#3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-08-21 16:56:22 +08:00
committed by GitHub
parent d482173c9b
commit fbdde0259a
8 changed files with 120 additions and 34 deletions

View File

@ -111,6 +111,7 @@ export default function Dataset() {
hideModal={hideDocumentUploadModal}
onOk={onDocumentUploadOk}
loading={documentUploadLoading}
showParseOnCreation
></FileUploadDialog>
)}
{createVisible && (

View File

@ -1,5 +1,9 @@
import { UploadFormSchemaType } from '@/components/file-upload-dialog';
import { useSetModalState } from '@/hooks/common-hooks';
import { useUploadNextDocument } from '@/hooks/use-document-request';
import {
useRunDocument,
useUploadNextDocument,
} from '@/hooks/use-document-request';
import { getUnSupportedFilesCount } from '@/utils/document-util';
import { useCallback } from 'react';
@ -10,14 +14,24 @@ export const useHandleUploadDocument = () => {
showModal: showDocumentUploadModal,
} = useSetModalState();
const { uploadDocument, loading } = useUploadNextDocument();
const { runDocumentByIds } = useRunDocument();
const onDocumentUploadOk = useCallback(
async (fileList: File[]): Promise<number | undefined> => {
async ({ fileList, parseOnCreation }: UploadFormSchemaType) => {
if (fileList.length > 0) {
const ret: any = await uploadDocument(fileList);
const ret = await uploadDocument(fileList);
if (typeof ret?.message !== 'string') {
return;
}
if (ret.code === 0 && parseOnCreation) {
runDocumentByIds({
documentIds: ret.data.map((x) => x.id),
run: 1,
shouldDelete: false,
});
}
const count = getUnSupportedFilesCount(ret?.message);
/// 500 error code indicates that some file types are not supported
let code = ret?.code;
@ -31,7 +45,7 @@ export const useHandleUploadDocument = () => {
return code;
}
},
[uploadDocument, hideDocumentUploadModal],
[uploadDocument, runDocumentByIds, hideDocumentUploadModal],
);
return {

View File

@ -1,4 +1,4 @@
import { Button } from '@/components/ui/button';
import { ButtonLoading } from '@/components/ui/button';
import {
Dialog,
DialogContent,
@ -74,7 +74,11 @@ export function InputForm({ onOk }: IModalProps<any>) {
);
}
export function DatasetCreatingDialog({ hideModal, onOk }: IModalProps<any>) {
export function DatasetCreatingDialog({
hideModal,
onOk,
loading,
}: IModalProps<any>) {
const { t } = useTranslation();
return (
@ -85,9 +89,9 @@ export function DatasetCreatingDialog({ hideModal, onOk }: IModalProps<any>) {
</DialogHeader>
<InputForm onOk={onOk}></InputForm>
<DialogFooter>
<Button type="submit" form={FormId}>
<ButtonLoading type="submit" form={FormId} loading={loading}>
{t('common.save')}
</Button>
</ButtonLoading>
</DialogFooter>
</DialogContent>
</Dialog>

View File

@ -1,3 +1,4 @@
import { UploadFormSchemaType } from '@/components/file-upload-dialog';
import { useSetModalState } from '@/hooks/common-hooks';
import { useUploadFile } from '@/hooks/use-file-request';
import { useCallback } from 'react';
@ -13,7 +14,7 @@ export const useHandleUploadFile = () => {
const id = useGetFolderId();
const onFileUploadOk = useCallback(
async (fileList: File[]): Promise<number | undefined> => {
async ({ fileList }: UploadFormSchemaType): Promise<number | undefined> => {
if (fileList.length > 0) {
const ret: number = await uploadFile({ fileList, parentId: id });
if (ret === 0) {