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.

segmentSetModal.tsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {
  2. useFetchTenantInfo,
  3. useSelectParserList,
  4. } from '@/hooks/userSettingHook';
  5. import { Modal, Space, Tag } from 'antd';
  6. import React, { useEffect, useState } from 'react';
  7. import { useDispatch, useSelector } from 'umi';
  8. import styles from './index.less';
  9. const { CheckableTag } = Tag;
  10. interface kFProps {
  11. getKfList: () => void;
  12. parser_id: string;
  13. doc_id: string;
  14. }
  15. const SegmentSetModal: React.FC<kFProps> = ({
  16. getKfList,
  17. parser_id,
  18. doc_id,
  19. }) => {
  20. const dispatch = useDispatch();
  21. const kFModel = useSelector((state: any) => state.kFModel);
  22. const [selectedTag, setSelectedTag] = useState('');
  23. const { isShowSegmentSetModal } = kFModel;
  24. const parserList = useSelectParserList();
  25. useFetchTenantInfo();
  26. useEffect(() => {
  27. setSelectedTag(parser_id);
  28. }, [parser_id]);
  29. const handleCancel = () => {
  30. dispatch({
  31. type: 'kFModel/updateState',
  32. payload: {
  33. isShowSegmentSetModal: false,
  34. },
  35. });
  36. };
  37. const handleOk = async () => {
  38. const retcode = await dispatch<any>({
  39. type: 'kFModel/document_change_parser',
  40. payload: {
  41. parser_id: selectedTag,
  42. doc_id,
  43. },
  44. });
  45. if (retcode === 0 && getKfList) {
  46. getKfList();
  47. handleCancel();
  48. }
  49. };
  50. const handleChange = (tag: string, checked: boolean) => {
  51. const nextSelectedTag = checked ? tag : selectedTag;
  52. setSelectedTag(nextSelectedTag);
  53. };
  54. return (
  55. <Modal
  56. title="Category"
  57. open={isShowSegmentSetModal}
  58. onOk={handleOk}
  59. onCancel={handleCancel}
  60. >
  61. <Space size={[0, 8]} wrap>
  62. <div className={styles.tags}>
  63. {parserList.map((x) => {
  64. return (
  65. <CheckableTag
  66. key={x.value}
  67. checked={selectedTag === x.value}
  68. onChange={(checked) => handleChange(x.value, checked)}
  69. >
  70. {x.label}
  71. </CheckableTag>
  72. );
  73. })}
  74. </div>
  75. </Space>
  76. </Modal>
  77. );
  78. };
  79. export default SegmentSetModal;