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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import ChunkMethodModal from '@/components/chunk-method-modal';
  2. import SvgIcon from '@/components/svg-icon';
  3. import {
  4. useSelectDocumentList,
  5. useSetDocumentStatus,
  6. } from '@/hooks/document-hooks';
  7. import { useSetSelectedRecord } from '@/hooks/logic-hooks';
  8. import { useSelectParserList } from '@/hooks/user-setting-hooks';
  9. import { IKnowledgeFile } from '@/interfaces/database/knowledge';
  10. import { getExtension } from '@/utils/documentUtils';
  11. import { Divider, Flex, Switch, Table, Typography } from 'antd';
  12. import type { ColumnsType } from 'antd/es/table';
  13. import { useTranslation } from 'react-i18next';
  14. import CreateFileModal from './create-file-modal';
  15. import DocumentToolbar from './document-toolbar';
  16. import {
  17. useChangeDocumentParser,
  18. useCreateEmptyDocument,
  19. useFetchDocumentListOnMount,
  20. useGetPagination,
  21. useGetRowSelection,
  22. useHandleUploadDocument,
  23. useHandleWebCrawl,
  24. useNavigateToOtherPage,
  25. useRenameDocument,
  26. } from './hooks';
  27. import ParsingActionCell from './parsing-action-cell';
  28. import ParsingStatusCell from './parsing-status-cell';
  29. import RenameModal from './rename-modal';
  30. import WebCrawlModal from './web-crawl-modal';
  31. import FileUploadModal from '@/components/file-upload-modal';
  32. import { formatDate } from '@/utils/date';
  33. import styles from './index.less';
  34. const { Text } = Typography;
  35. const KnowledgeFile = () => {
  36. const data = useSelectDocumentList();
  37. const { fetchDocumentList } = useFetchDocumentListOnMount();
  38. const parserList = useSelectParserList();
  39. const { pagination } = useGetPagination(fetchDocumentList);
  40. const onChangeStatus = useSetDocumentStatus();
  41. const { toChunk } = useNavigateToOtherPage();
  42. const { currentRecord, setRecord } = useSetSelectedRecord();
  43. const {
  44. renameLoading,
  45. onRenameOk,
  46. renameVisible,
  47. hideRenameModal,
  48. showRenameModal,
  49. } = useRenameDocument(currentRecord.id);
  50. const {
  51. createLoading,
  52. onCreateOk,
  53. createVisible,
  54. hideCreateModal,
  55. showCreateModal,
  56. } = useCreateEmptyDocument();
  57. const {
  58. changeParserLoading,
  59. onChangeParserOk,
  60. changeParserVisible,
  61. hideChangeParserModal,
  62. showChangeParserModal,
  63. } = useChangeDocumentParser(currentRecord.id);
  64. const {
  65. documentUploadVisible,
  66. hideDocumentUploadModal,
  67. showDocumentUploadModal,
  68. onDocumentUploadOk,
  69. documentUploadLoading,
  70. } = useHandleUploadDocument();
  71. const {
  72. webCrawlUploadVisible,
  73. hideWebCrawlUploadModal,
  74. showWebCrawlUploadModal,
  75. onWebCrawlUploadOk,
  76. webCrawlUploadLoading,
  77. } = useHandleWebCrawl();
  78. const { t } = useTranslation('translation', {
  79. keyPrefix: 'knowledgeDetails',
  80. });
  81. const rowSelection = useGetRowSelection();
  82. const columns: ColumnsType<IKnowledgeFile> = [
  83. {
  84. title: t('name'),
  85. dataIndex: 'name',
  86. key: 'name',
  87. fixed: 'left',
  88. render: (text: any, { id, thumbnail, name }) => (
  89. <div className={styles.toChunks} onClick={() => toChunk(id)}>
  90. <Flex gap={10} align="center">
  91. {thumbnail ? (
  92. <img className={styles.img} src={thumbnail} alt="" />
  93. ) : (
  94. <SvgIcon
  95. name={`file-icon/${getExtension(name)}`}
  96. width={24}
  97. ></SvgIcon>
  98. )}
  99. <Text ellipsis={{ tooltip: text }} className={styles.nameText}>
  100. {text}
  101. </Text>
  102. </Flex>
  103. </div>
  104. ),
  105. },
  106. {
  107. title: t('chunkNumber'),
  108. dataIndex: 'chunk_num',
  109. key: 'chunk_num',
  110. },
  111. {
  112. title: t('uploadDate'),
  113. dataIndex: 'create_time',
  114. key: 'create_time',
  115. render(value) {
  116. return formatDate(value);
  117. },
  118. },
  119. {
  120. title: t('chunkMethod'),
  121. dataIndex: 'parser_id',
  122. key: 'parser_id',
  123. render: (text) => {
  124. return parserList.find((x) => x.value === text)?.label;
  125. },
  126. },
  127. {
  128. title: t('enabled'),
  129. key: 'status',
  130. dataIndex: 'status',
  131. render: (_, { status, id }) => (
  132. <>
  133. <Switch
  134. checked={status === '1'}
  135. onChange={(e) => {
  136. onChangeStatus(e, id);
  137. }}
  138. />
  139. </>
  140. ),
  141. },
  142. {
  143. title: t('parsingStatus'),
  144. dataIndex: 'run',
  145. key: 'run',
  146. render: (text, record) => {
  147. return <ParsingStatusCell record={record}></ParsingStatusCell>;
  148. },
  149. },
  150. {
  151. title: t('action'),
  152. key: 'action',
  153. render: (_, record) => (
  154. <ParsingActionCell
  155. setCurrentRecord={setRecord}
  156. showRenameModal={showRenameModal}
  157. showChangeParserModal={showChangeParserModal}
  158. record={record}
  159. ></ParsingActionCell>
  160. ),
  161. },
  162. ];
  163. const finalColumns = columns.map((x) => ({
  164. ...x,
  165. className: `${styles.column}`,
  166. }));
  167. return (
  168. <div className={styles.datasetWrapper}>
  169. <h3>{t('dataset')}</h3>
  170. <p>{t('datasetDescription')}</p>
  171. <Divider></Divider>
  172. <DocumentToolbar
  173. selectedRowKeys={rowSelection.selectedRowKeys as string[]}
  174. showCreateModal={showCreateModal}
  175. showWebCrawlModal={showWebCrawlUploadModal}
  176. showDocumentUploadModal={showDocumentUploadModal}
  177. ></DocumentToolbar>
  178. <Table
  179. rowKey="id"
  180. columns={finalColumns}
  181. dataSource={data}
  182. // loading={loading}
  183. pagination={pagination}
  184. rowSelection={rowSelection}
  185. className={styles.documentTable}
  186. scroll={{ scrollToFirstRowOnChange: true, x: 1300 }}
  187. />
  188. <CreateFileModal
  189. visible={createVisible}
  190. hideModal={hideCreateModal}
  191. loading={createLoading}
  192. onOk={onCreateOk}
  193. />
  194. <ChunkMethodModal
  195. documentId={currentRecord.id}
  196. parserId={currentRecord.parser_id}
  197. parserConfig={currentRecord.parser_config}
  198. documentExtension={getExtension(currentRecord.name)}
  199. onOk={onChangeParserOk}
  200. visible={changeParserVisible}
  201. hideModal={hideChangeParserModal}
  202. loading={changeParserLoading}
  203. />
  204. <RenameModal
  205. visible={renameVisible}
  206. onOk={onRenameOk}
  207. loading={renameLoading}
  208. hideModal={hideRenameModal}
  209. initialName={currentRecord.name}
  210. ></RenameModal>
  211. <FileUploadModal
  212. visible={documentUploadVisible}
  213. hideModal={hideDocumentUploadModal}
  214. loading={documentUploadLoading}
  215. onOk={onDocumentUploadOk}
  216. ></FileUploadModal>
  217. <WebCrawlModal
  218. visible={webCrawlUploadVisible}
  219. hideModal={hideWebCrawlUploadModal}
  220. loading={webCrawlUploadLoading}
  221. onOk={onWebCrawlUploadOk}
  222. ></WebCrawlModal>
  223. </div>
  224. );
  225. };
  226. export default KnowledgeFile;