mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Add history version save - Allows users to view and download agent files by version revision history  _Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR._ ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
121 lines
3.7 KiB
TypeScript
121 lines
3.7 KiB
TypeScript
import EmbedModal from '@/components/api-service/embed-modal';
|
|
import { useShowEmbedModal } from '@/components/api-service/hooks';
|
|
import { SharedFrom } from '@/constants/chat';
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
import { useFetchFlow } from '@/hooks/flow-hooks';
|
|
import { ArrowLeftOutlined } from '@ant-design/icons';
|
|
import { Button, Flex, Space } from 'antd';
|
|
import { useCallback } from 'react';
|
|
import { Link, useParams } from 'umi';
|
|
import {
|
|
useGetBeginNodeDataQuery,
|
|
useGetBeginNodeDataQueryIsSafe,
|
|
} from '../hooks/use-get-begin-query';
|
|
import {
|
|
useSaveGraph,
|
|
useSaveGraphBeforeOpeningDebugDrawer,
|
|
useWatchAgentChange,
|
|
} from '../hooks/use-save-graph';
|
|
import { BeginQuery } from '../interface';
|
|
|
|
import {
|
|
HistoryVersionModal,
|
|
useHistoryVersionModal,
|
|
} from '../history-version-modal';
|
|
import styles from './index.less';
|
|
|
|
interface IProps {
|
|
showChatDrawer(): void;
|
|
chatDrawerVisible: boolean;
|
|
}
|
|
|
|
const FlowHeader = ({ showChatDrawer, chatDrawerVisible }: IProps) => {
|
|
const { saveGraph } = useSaveGraph();
|
|
const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer);
|
|
const { data } = useFetchFlow();
|
|
const { t } = useTranslate('flow');
|
|
const { id } = useParams();
|
|
const time = useWatchAgentChange(chatDrawerVisible);
|
|
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
|
|
const { showEmbedModal, hideEmbedModal, embedVisible, beta } =
|
|
useShowEmbedModal();
|
|
const isBeginNodeDataQuerySafe = useGetBeginNodeDataQueryIsSafe();
|
|
const { setVisibleHistoryVersionModal, visibleHistoryVersionModal } =
|
|
useHistoryVersionModal();
|
|
const handleShowEmbedModal = useCallback(() => {
|
|
showEmbedModal();
|
|
}, [showEmbedModal]);
|
|
|
|
const handleRunAgent = useCallback(() => {
|
|
const query: BeginQuery[] = getBeginNodeDataQuery();
|
|
if (query.length > 0) {
|
|
showChatDrawer();
|
|
} else {
|
|
handleRun();
|
|
}
|
|
}, [getBeginNodeDataQuery, handleRun, showChatDrawer]);
|
|
|
|
const showListVersion = useCallback(() => {
|
|
setVisibleHistoryVersionModal(true);
|
|
}, [setVisibleHistoryVersionModal]);
|
|
return (
|
|
<>
|
|
<Flex
|
|
align="center"
|
|
justify={'space-between'}
|
|
gap={'large'}
|
|
className={styles.flowHeader}
|
|
>
|
|
<Space size={'large'}>
|
|
<Link to={`/flow`}>
|
|
<ArrowLeftOutlined />
|
|
</Link>
|
|
<div className="flex flex-col">
|
|
<span className="font-semibold text-[18px]">{data.title}</span>
|
|
<span className="font-normal text-sm">
|
|
{t('autosaved')} {time}
|
|
</span>
|
|
</div>
|
|
</Space>
|
|
<Space size={'large'}>
|
|
<Button onClick={handleRunAgent}>
|
|
<b>{t('run')}</b>
|
|
</Button>
|
|
<Button type="primary" onClick={() => saveGraph()}>
|
|
<b>{t('save')}</b>
|
|
</Button>
|
|
<Button
|
|
type="primary"
|
|
onClick={handleShowEmbedModal}
|
|
disabled={!isBeginNodeDataQuerySafe}
|
|
>
|
|
<b>{t('embedIntoSite', { keyPrefix: 'common' })}</b>
|
|
</Button>
|
|
<Button type="primary" onClick={showListVersion}>
|
|
<b>{t('historyversion')}</b>
|
|
</Button>
|
|
</Space>
|
|
</Flex>
|
|
{embedVisible && (
|
|
<EmbedModal
|
|
visible={embedVisible}
|
|
hideModal={hideEmbedModal}
|
|
token={id!}
|
|
form={SharedFrom.Agent}
|
|
beta={beta}
|
|
isAgent
|
|
></EmbedModal>
|
|
)}
|
|
{visibleHistoryVersionModal && (
|
|
<HistoryVersionModal
|
|
id={id || ''}
|
|
visible={visibleHistoryVersionModal}
|
|
hideModal={() => setVisibleHistoryVersionModal(false)}
|
|
></HistoryVersionModal>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default FlowHeader;
|