You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { useShowDeleteConfirm, useTranslate } from '@/hooks/commonHooks';
  2. import { useRemoveDocument } from '@/hooks/documentHooks';
  3. import { IKnowledgeFile } from '@/interfaces/database/knowledge';
  4. import { api_host } from '@/utils/api';
  5. import { downloadFile } from '@/utils/fileUtil';
  6. import {
  7. DeleteOutlined,
  8. DownloadOutlined,
  9. EditOutlined,
  10. ToolOutlined,
  11. } from '@ant-design/icons';
  12. import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd';
  13. import { isParserRunning } from '../utils';
  14. import styles from './index.less';
  15. interface IProps {
  16. record: IKnowledgeFile;
  17. setCurrentRecord: (record: IKnowledgeFile) => void;
  18. showRenameModal: () => void;
  19. showChangeParserModal: () => void;
  20. }
  21. const ParsingActionCell = ({
  22. record,
  23. setCurrentRecord,
  24. showRenameModal,
  25. showChangeParserModal,
  26. }: IProps) => {
  27. const documentId = record.id;
  28. const isRunning = isParserRunning(record.run);
  29. const { t } = useTranslate('knowledgeDetails');
  30. const removeDocument = useRemoveDocument(documentId);
  31. const showDeleteConfirm = useShowDeleteConfirm();
  32. const onRmDocument = () => {
  33. if (!isRunning) {
  34. showDeleteConfirm({ onOk: removeDocument });
  35. }
  36. };
  37. const onDownloadDocument = () => {
  38. downloadFile({
  39. url: `${api_host}/document/get/${documentId}`,
  40. filename: record.name,
  41. });
  42. };
  43. const setRecord = () => {
  44. setCurrentRecord(record);
  45. };
  46. const onShowRenameModal = () => {
  47. setRecord();
  48. showRenameModal();
  49. };
  50. const onShowChangeParserModal = () => {
  51. setRecord();
  52. showChangeParserModal();
  53. };
  54. const chunkItems: MenuProps['items'] = [
  55. {
  56. key: '1',
  57. label: (
  58. <div>
  59. <Button type="link" onClick={onShowChangeParserModal}>
  60. {t('chunkMethod')}
  61. </Button>
  62. </div>
  63. ),
  64. },
  65. ];
  66. return (
  67. <Space size={0}>
  68. <Dropdown
  69. menu={{ items: chunkItems }}
  70. trigger={['click']}
  71. disabled={isRunning}
  72. >
  73. <Button type="text" className={styles.iconButton}>
  74. <ToolOutlined size={20} />
  75. </Button>
  76. </Dropdown>
  77. <Tooltip title={t('rename', { keyPrefix: 'common' })}>
  78. <Button
  79. type="text"
  80. disabled={isRunning}
  81. onClick={onShowRenameModal}
  82. className={styles.iconButton}
  83. >
  84. <EditOutlined size={20} />
  85. </Button>
  86. </Tooltip>
  87. <Button
  88. type="text"
  89. disabled={isRunning}
  90. onClick={onRmDocument}
  91. className={styles.iconButton}
  92. >
  93. <DeleteOutlined size={20} />
  94. </Button>
  95. <Button
  96. type="text"
  97. disabled={isRunning}
  98. onClick={onDownloadDocument}
  99. className={styles.iconButton}
  100. >
  101. <DownloadOutlined size={20} />
  102. </Button>
  103. </Space>
  104. );
  105. };
  106. export default ParsingActionCell;