2024-08-09 18:59:16 +08:00
|
|
|
import ChatOverviewModal from '@/components/api-service/chat-overview-modal';
|
|
|
|
|
import { useSetModalState, useTranslate } from '@/hooks/common-hooks';
|
2024-06-07 19:27:27 +08:00
|
|
|
import { useFetchFlow } from '@/hooks/flow-hooks';
|
|
|
|
|
import { ArrowLeftOutlined } from '@ant-design/icons';
|
2024-07-08 10:55:10 +08:00
|
|
|
import { Button, Flex, Space } from 'antd';
|
2024-11-15 15:17:23 +08:00
|
|
|
import { useCallback } from 'react';
|
2024-08-09 18:59:16 +08:00
|
|
|
import { Link, useParams } from 'umi';
|
2024-11-04 17:04:35 +08:00
|
|
|
import FlowIdModal from '../flow-id-modal';
|
2024-11-08 17:28:11 +08:00
|
|
|
import {
|
2024-11-15 15:17:23 +08:00
|
|
|
useGetBeginNodeDataQuery,
|
2024-11-08 17:28:11 +08:00
|
|
|
useSaveGraph,
|
|
|
|
|
useSaveGraphBeforeOpeningDebugDrawer,
|
|
|
|
|
useWatchAgentChange,
|
|
|
|
|
} from '../hooks';
|
2024-11-15 15:17:23 +08:00
|
|
|
import { BeginQuery } from '../interface';
|
2024-05-29 10:01:39 +08:00
|
|
|
import styles from './index.less';
|
|
|
|
|
|
2024-06-11 15:46:12 +08:00
|
|
|
interface IProps {
|
|
|
|
|
showChatDrawer(): void;
|
2024-11-12 12:47:36 +08:00
|
|
|
chatDrawerVisible: boolean;
|
2024-06-11 15:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
2024-11-12 12:47:36 +08:00
|
|
|
const FlowHeader = ({ showChatDrawer, chatDrawerVisible }: IProps) => {
|
2024-05-29 10:01:39 +08:00
|
|
|
const { saveGraph } = useSaveGraph();
|
2024-11-15 15:17:23 +08:00
|
|
|
const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer);
|
2024-06-07 19:27:27 +08:00
|
|
|
const { data } = useFetchFlow();
|
2024-07-08 10:55:10 +08:00
|
|
|
const { t } = useTranslate('flow');
|
2024-08-09 18:59:16 +08:00
|
|
|
const {
|
|
|
|
|
visible: overviewVisible,
|
|
|
|
|
hideModal: hideOverviewModal,
|
2024-11-08 17:28:11 +08:00
|
|
|
// showModal: showOverviewModal,
|
2024-08-09 18:59:16 +08:00
|
|
|
} = useSetModalState();
|
2024-11-04 17:04:35 +08:00
|
|
|
const { visible, hideModal, showModal } = useSetModalState();
|
2024-08-09 18:59:16 +08:00
|
|
|
const { id } = useParams();
|
2024-11-12 12:47:36 +08:00
|
|
|
const time = useWatchAgentChange(chatDrawerVisible);
|
2024-11-15 15:17:23 +08:00
|
|
|
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
|
|
|
|
|
|
|
|
|
|
const handleRunAgent = useCallback(() => {
|
|
|
|
|
const query: BeginQuery[] = getBeginNodeDataQuery();
|
|
|
|
|
if (query.length > 0) {
|
|
|
|
|
showChatDrawer();
|
|
|
|
|
} else {
|
|
|
|
|
handleRun();
|
|
|
|
|
}
|
|
|
|
|
}, [getBeginNodeDataQuery, handleRun, showChatDrawer]);
|
2024-05-29 10:01:39 +08:00
|
|
|
|
|
|
|
|
return (
|
2024-06-07 19:27:27 +08:00
|
|
|
<>
|
|
|
|
|
<Flex
|
|
|
|
|
align="center"
|
|
|
|
|
justify={'space-between'}
|
|
|
|
|
gap={'large'}
|
|
|
|
|
className={styles.flowHeader}
|
|
|
|
|
>
|
|
|
|
|
<Space size={'large'}>
|
|
|
|
|
<Link to={`/flow`}>
|
|
|
|
|
<ArrowLeftOutlined />
|
|
|
|
|
</Link>
|
2024-11-08 17:28:11 +08:00
|
|
|
<div className="flex flex-col">
|
|
|
|
|
<span className="font-semibold text-[18px]">{data.title}</span>
|
2024-11-08 18:27:42 +08:00
|
|
|
<span className="font-normal text-sm">
|
|
|
|
|
{t('autosaved')} {time}
|
|
|
|
|
</span>
|
2024-11-08 17:28:11 +08:00
|
|
|
</div>
|
2024-06-07 19:27:27 +08:00
|
|
|
</Space>
|
|
|
|
|
<Space size={'large'}>
|
2024-11-15 15:17:23 +08:00
|
|
|
<Button onClick={handleRunAgent}>
|
2024-07-08 10:55:10 +08:00
|
|
|
<b>{t('run')}</b>
|
2024-06-07 19:27:27 +08:00
|
|
|
</Button>
|
2024-11-15 15:17:23 +08:00
|
|
|
<Button type="primary" onClick={() => saveGraph()}>
|
2024-07-08 10:55:10 +08:00
|
|
|
<b>{t('save')}</b>
|
2024-06-07 19:27:27 +08:00
|
|
|
</Button>
|
2024-11-04 17:04:35 +08:00
|
|
|
{/* <Button type="primary" onClick={showOverviewModal} disabled>
|
2024-08-09 18:59:16 +08:00
|
|
|
<b>{t('publish')}</b>
|
2024-11-04 17:04:35 +08:00
|
|
|
</Button> */}
|
|
|
|
|
<Button type="primary" onClick={showModal}>
|
|
|
|
|
<b>Agent ID</b>
|
2024-08-09 18:59:16 +08:00
|
|
|
</Button>
|
2024-06-07 19:27:27 +08:00
|
|
|
</Space>
|
|
|
|
|
</Flex>
|
2024-08-09 18:59:16 +08:00
|
|
|
{overviewVisible && (
|
|
|
|
|
<ChatOverviewModal
|
|
|
|
|
visible={overviewVisible}
|
|
|
|
|
hideModal={hideOverviewModal}
|
|
|
|
|
id={id!}
|
|
|
|
|
idKey="canvasId"
|
|
|
|
|
></ChatOverviewModal>
|
|
|
|
|
)}
|
2024-11-04 17:04:35 +08:00
|
|
|
{visible && <FlowIdModal hideModal={hideModal}></FlowIdModal>}
|
2024-06-07 19:27:27 +08:00
|
|
|
</>
|
2024-05-29 10:01:39 +08:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default FlowHeader;
|