Feat: Display the document configuration dialog with shadcn #3221 (#7302)

### What problem does this PR solve?

Feat: Display the document configuration dialog with shadcn #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-04-25 11:15:44 +08:00
committed by GitHub
parent 6e98cd311c
commit 02cc867c06
18 changed files with 980 additions and 104 deletions

View File

@ -1,4 +1,5 @@
import { IDocumentInfo } from '@/interfaces/database/document';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import i18n from '@/locales/config';
import kbService from '@/services/knowledge-service';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
@ -20,6 +21,7 @@ export const enum DocumentApiAction {
RunDocumentByIds = 'runDocumentByIds',
RemoveDocument = 'removeDocument',
SaveDocumentName = 'saveDocumentName',
SetDocumentParser = 'setDocumentParser',
}
export const useUploadNextDocument = () => {
@ -247,3 +249,40 @@ export const useSaveDocumentName = () => {
return { loading, saveName: mutateAsync, data };
};
export const useSetDocumentParser = () => {
const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [DocumentApiAction.SetDocumentParser],
mutationFn: async ({
parserId,
documentId,
parserConfig,
}: {
parserId: string;
documentId: string;
parserConfig: IChangeParserConfigRequestBody;
}) => {
const { data } = await kbService.document_change_parser({
parser_id: parserId,
doc_id: documentId,
parser_config: parserConfig,
});
if (data.code === 0) {
queryClient.invalidateQueries({
queryKey: [DocumentApiAction.FetchDocumentList],
});
message.success(i18n.t('message.modified'));
}
return data.code;
},
});
return { setDocumentParser: mutateAsync, data, loading };
};

View File

@ -1,4 +1,5 @@
import {
IKnowledge,
IKnowledgeResult,
INextTestingResult,
} from '@/interfaces/database/knowledge';
@ -22,6 +23,7 @@ export const enum KnowledgeApiAction {
CreateKnowledge = 'createKnowledge',
DeleteKnowledge = 'deleteKnowledge',
SaveKnowledge = 'saveKnowledge',
FetchKnowledgeDetail = 'fetchKnowledgeDetail',
}
export const useKnowledgeBaseId = () => {
@ -204,3 +206,21 @@ export const useUpdateKnowledge = (shouldFetchList = false) => {
return { data, loading, saveKnowledgeConfiguration: mutateAsync };
};
export const useFetchKnowledgeBaseConfiguration = () => {
const { id } = useParams();
const { data, isFetching: loading } = useQuery<IKnowledge>({
queryKey: [KnowledgeApiAction.FetchKnowledgeDetail],
initialData: {} as IKnowledge,
gcTime: 0,
queryFn: async () => {
const { data } = await kbService.get_kb_detail({
kb_id: id,
});
return data?.data ?? {};
},
});
return { data, loading };
};