mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-04-21 11:17:45 +08:00
### What problem does this PR solve? Feat: Cancel a running data flow test #9869 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { useSendMessageBySSE } from '@/hooks/use-send-message';
|
|
import api from '@/utils/api';
|
|
import { get } from 'lodash';
|
|
import { useCallback, useContext } from 'react';
|
|
import { useParams } from 'umi';
|
|
import { LogContext } from '../context';
|
|
import { useSaveGraphBeforeOpeningDebugDrawer } from './use-save-graph';
|
|
|
|
export function useRunDataflow(
|
|
showLogSheet: () => void,
|
|
hideRunOrChatDrawer: () => void,
|
|
) {
|
|
const { send } = useSendMessageBySSE(api.runCanvas);
|
|
const { id } = useParams();
|
|
const { setMessageId } = useContext(LogContext);
|
|
|
|
const { handleRun: saveGraph, loading } =
|
|
useSaveGraphBeforeOpeningDebugDrawer(showLogSheet!);
|
|
|
|
const run = useCallback(
|
|
async (fileResponseData: Record<string, any>) => {
|
|
const success = await saveGraph();
|
|
if (!success) return;
|
|
const res = await send({
|
|
id,
|
|
query: '',
|
|
session_id: null,
|
|
files: [fileResponseData.file],
|
|
});
|
|
|
|
if (res && res?.response.status === 200 && get(res, 'data.code') === 0) {
|
|
// fetch canvas
|
|
hideRunOrChatDrawer();
|
|
|
|
const msgId = get(res, 'data.data.message_id');
|
|
if (msgId) {
|
|
setMessageId(msgId);
|
|
}
|
|
|
|
return msgId;
|
|
}
|
|
},
|
|
[hideRunOrChatDrawer, id, saveGraph, send, setMessageId],
|
|
);
|
|
|
|
return { run, loading: loading };
|
|
}
|
|
|
|
export type RunDataflowType = ReturnType<typeof useRunDataflow>;
|