feat: save graph data before opening the debug drawer #918 (#1387)

### What problem does this PR solve?
feat: save graph data before opening the debug drawer #918

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-07-05 14:16:03 +08:00
committed by GitHub
parent 74ec3bc4d9
commit 472fcba7af
4 changed files with 41 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
import { MessageType } from '@/constants/chat';
import { useFetchFlow, useResetFlow } from '@/hooks/flow-hooks';
import { useFetchFlow } from '@/hooks/flow-hooks';
import {
useHandleMessageInputChange,
useScrollToBottom,
@@ -12,6 +12,7 @@ import { message } from 'antd';
import { useCallback, useEffect, useState } from 'react';
import { useParams } from 'umi';
import { v4 as uuid } from 'uuid';
import { receiveMessageError } from '../utils';
const antMessage = message;
@@ -94,7 +95,6 @@ export const useSendMessage = (
const { id: flowId } = useParams();
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
const { refetch } = useFetchFlow();
const { resetFlow } = useResetFlow();
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
@@ -108,7 +108,7 @@ export const useSendMessage = (
}
const res = await send(params);
if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) {
if (receiveMessageError(res)) {
antMessage.error(res?.data?.retmsg);
// cancel loading
@@ -128,28 +128,12 @@ export const useSendMessage = (
[sendMessage],
);
/**
* Call the reset api before opening the run drawer each time
*/
const resetFlowBeforeFetchingPrologue = useCallback(async () => {
// After resetting, all previous messages will be cleared.
const ret = await resetFlow();
if (ret.retcode === 0) {
// fetch prologue
sendMessage('');
}
}, [resetFlow, sendMessage]);
useEffect(() => {
if (answer.answer) {
addNewestAnswer(answer);
}
}, [answer, addNewestAnswer]);
useEffect(() => {
resetFlowBeforeFetchingPrologue();
}, [resetFlowBeforeFetchingPrologue]);
const handlePressEnter = useCallback(() => {
if (done) {
setValue('');