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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { ReactComponent as RefreshIcon } from '@/assets/svg/refresh.svg';
  2. import { ReactComponent as RunIcon } from '@/assets/svg/run.svg';
  3. import { IKnowledgeFile } from '@/interfaces/database/knowledge';
  4. import { CloseCircleOutlined } from '@ant-design/icons';
  5. import { Badge, DescriptionsProps, Flex, Popover, Space, Tag } from 'antd';
  6. import reactStringReplace from 'react-string-replace';
  7. import { useDispatch } from 'umi';
  8. import { RunningStatus, RunningStatusMap } from '../constant';
  9. import styles from './index.less';
  10. const iconMap = {
  11. [RunningStatus.UNSTART]: RunIcon,
  12. [RunningStatus.RUNNING]: CloseCircleOutlined,
  13. [RunningStatus.CANCEL]: RefreshIcon,
  14. [RunningStatus.DONE]: RefreshIcon,
  15. [RunningStatus.FAIL]: RefreshIcon,
  16. };
  17. interface IProps {
  18. record: IKnowledgeFile;
  19. }
  20. const PopoverContent = ({ record }: IProps) => {
  21. const items: DescriptionsProps['items'] = [
  22. {
  23. key: 'process_begin_at',
  24. label: 'Process Begin At',
  25. children: record.process_begin_at,
  26. },
  27. {
  28. key: 'process_duation',
  29. label: 'Process Duration',
  30. children: record.process_duation,
  31. },
  32. {
  33. key: 'progress_msg',
  34. label: 'Progress Msg',
  35. children: reactStringReplace(
  36. record.progress_msg.trim(),
  37. /(\[ERROR\].+\s)/g,
  38. (match, i) => {
  39. return (
  40. <span key={i} className={styles.popoverContentErrorLabel}>
  41. {match}
  42. </span>
  43. );
  44. },
  45. ),
  46. },
  47. ];
  48. return (
  49. <Flex vertical className={styles.popoverContent}>
  50. {items.map((x, idx) => {
  51. return (
  52. <div key={x.key} className={idx < 2 ? styles.popoverContentItem : ''}>
  53. <b>{x.label}:</b>
  54. <div className={styles.popoverContentText}>{x.children}</div>
  55. </div>
  56. );
  57. })}
  58. </Flex>
  59. );
  60. };
  61. export const ParsingStatusCell = ({ record }: IProps) => {
  62. const dispatch = useDispatch();
  63. const text = record.run;
  64. const runningStatus = RunningStatusMap[text];
  65. const isRunning = text === RunningStatus.RUNNING;
  66. const OperationIcon = iconMap[text];
  67. const handleOperationIconClick = () => {
  68. dispatch({
  69. type: 'kFModel/document_run',
  70. payload: {
  71. doc_ids: [record.id],
  72. run: isRunning ? 2 : 1,
  73. knowledgeBaseId: record.kb_id,
  74. },
  75. });
  76. };
  77. return (
  78. <Flex justify={'space-between'}>
  79. <Popover content={<PopoverContent record={record}></PopoverContent>}>
  80. <Tag color={runningStatus.color}>
  81. {isRunning ? (
  82. <Space>
  83. <Badge color={runningStatus.color} />
  84. {runningStatus.label}
  85. <span>{(record.progress * 100).toFixed(2)}%</span>
  86. </Space>
  87. ) : (
  88. runningStatus.label
  89. )}
  90. </Tag>
  91. </Popover>
  92. <div onClick={handleOperationIconClick} className={styles.operationIcon}>
  93. <OperationIcon />
  94. </div>
  95. </Flex>
  96. );
  97. };
  98. export default ParsingStatusCell;