您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import EmbedModal from '@/components/api-service/embed-modal';
  2. import { useShowEmbedModal } from '@/components/api-service/hooks';
  3. import { SharedFrom } from '@/constants/chat';
  4. import { useTranslate } from '@/hooks/common-hooks';
  5. import { useFetchFlow } from '@/hooks/flow-hooks';
  6. import { ArrowLeftOutlined } from '@ant-design/icons';
  7. import { Button, Flex, Space } from 'antd';
  8. import { useCallback } from 'react';
  9. import { Link, useParams } from 'umi';
  10. import {
  11. useGetBeginNodeDataQuery,
  12. useGetBeginNodeDataQueryIsSafe,
  13. } from '../hooks/use-get-begin-query';
  14. import {
  15. useSaveGraph,
  16. useSaveGraphBeforeOpeningDebugDrawer,
  17. useWatchAgentChange,
  18. } from '../hooks/use-save-graph';
  19. import { BeginQuery } from '../interface';
  20. import {
  21. HistoryVersionModal,
  22. useHistoryVersionModal,
  23. } from '../history-version-modal';
  24. import styles from './index.less';
  25. interface IProps {
  26. showChatDrawer(): void;
  27. chatDrawerVisible: boolean;
  28. }
  29. const FlowHeader = ({ showChatDrawer, chatDrawerVisible }: IProps) => {
  30. const { saveGraph } = useSaveGraph();
  31. const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer);
  32. const { data } = useFetchFlow();
  33. const { t } = useTranslate('flow');
  34. const { id } = useParams();
  35. const time = useWatchAgentChange(chatDrawerVisible);
  36. const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
  37. const { showEmbedModal, hideEmbedModal, embedVisible, beta } =
  38. useShowEmbedModal();
  39. const isBeginNodeDataQuerySafe = useGetBeginNodeDataQueryIsSafe();
  40. const { setVisibleHistoryVersionModal, visibleHistoryVersionModal } =
  41. useHistoryVersionModal();
  42. const handleShowEmbedModal = useCallback(() => {
  43. showEmbedModal();
  44. }, [showEmbedModal]);
  45. const handleRunAgent = useCallback(() => {
  46. const query: BeginQuery[] = getBeginNodeDataQuery();
  47. if (query.length > 0) {
  48. showChatDrawer();
  49. } else {
  50. handleRun();
  51. }
  52. }, [getBeginNodeDataQuery, handleRun, showChatDrawer]);
  53. const showListVersion = useCallback(() => {
  54. setVisibleHistoryVersionModal(true);
  55. }, [setVisibleHistoryVersionModal]);
  56. return (
  57. <>
  58. <Flex
  59. align="center"
  60. justify={'space-between'}
  61. gap={'large'}
  62. className={styles.flowHeader}
  63. >
  64. <Space size={'large'}>
  65. <Link to={`/flow`}>
  66. <ArrowLeftOutlined />
  67. </Link>
  68. <div className="flex flex-col">
  69. <span className="font-semibold text-[18px]">{data.title}</span>
  70. <span className="font-normal text-sm">
  71. {t('autosaved')} {time}
  72. </span>
  73. </div>
  74. </Space>
  75. <Space size={'large'}>
  76. <Button onClick={handleRunAgent}>
  77. <b>{t('run')}</b>
  78. </Button>
  79. <Button type="primary" onClick={() => saveGraph()}>
  80. <b>{t('save')}</b>
  81. </Button>
  82. <Button
  83. type="primary"
  84. onClick={handleShowEmbedModal}
  85. disabled={!isBeginNodeDataQuerySafe}
  86. >
  87. <b>{t('embedIntoSite', { keyPrefix: 'common' })}</b>
  88. </Button>
  89. <Button type="primary" onClick={showListVersion}>
  90. <b>{t('historyversion')}</b>
  91. </Button>
  92. </Space>
  93. </Flex>
  94. {embedVisible && (
  95. <EmbedModal
  96. visible={embedVisible}
  97. hideModal={hideEmbedModal}
  98. token={id!}
  99. form={SharedFrom.Agent}
  100. beta={beta}
  101. isAgent
  102. ></EmbedModal>
  103. )}
  104. {visibleHistoryVersionModal && (
  105. <HistoryVersionModal
  106. id={id || ''}
  107. visible={visibleHistoryVersionModal}
  108. hideModal={() => setVisibleHistoryVersionModal(false)}
  109. ></HistoryVersionModal>
  110. )}
  111. </>
  112. );
  113. };
  114. export default FlowHeader;