File size: 2,135 Bytes
4086c42
 
 
 
362ec6c
 
 
6b8fc2c
 
fad2ec7
362ec6c
 
 
fad2ec7
362ec6c
 
 
 
 
 
 
 
 
06526fb
 
4086c42
6b8fc2c
362ec6c
 
 
6b8fc2c
362ec6c
 
 
 
 
 
 
 
6b8fc2c
362ec6c
 
 
 
 
 
 
 
6b8fc2c
06526fb
 
 
 
362ec6c
 
 
 
 
 
 
 
 
4086c42
362ec6c
 
 
 
 
 
06526fb
362ec6c
 
06526fb
 
 
362ec6c
06526fb
362ec6c
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
  useFetchTenantInfo,
  useSelectParserList,
} from '@/hooks/userSettingHook';
import { Modal, Space, Tag } from 'antd';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'umi';
import styles from './index.less';
const { CheckableTag } = Tag;
interface kFProps {
  getKfList: () => void;
  parser_id: string;
  doc_id: string;
}
const SegmentSetModal: React.FC<kFProps> = ({

  getKfList,

  parser_id,

  doc_id,

}) => {
  const dispatch = useDispatch();
  const kFModel = useSelector((state: any) => state.kFModel);
  const [selectedTag, setSelectedTag] = useState('');
  const { isShowSegmentSetModal } = kFModel;
  const parserList = useSelectParserList();

  useFetchTenantInfo();

  useEffect(() => {
    setSelectedTag(parser_id);
  }, [parser_id]);

  const handleCancel = () => {
    dispatch({
      type: 'kFModel/updateState',
      payload: {
        isShowSegmentSetModal: false,
      },
    });
  };

  const handleOk = async () => {
    const retcode = await dispatch<any>({
      type: 'kFModel/document_change_parser',
      payload: {
        parser_id: selectedTag,
        doc_id,
      },
    });

    if (retcode === 0 && getKfList) {
      getKfList();
      handleCancel();
    }
  };

  const handleChange = (tag: string, checked: boolean) => {
    const nextSelectedTag = checked ? tag : selectedTag;
    setSelectedTag(nextSelectedTag);
  };

  return (
    <Modal

      title="Category"

      open={isShowSegmentSetModal}

      onOk={handleOk}

      onCancel={handleCancel}

    >

      <Space size={[0, 8]} wrap>

        <div className={styles.tags}>

          {parserList.map((x) => {

            return (

              <CheckableTag

                key={x.value}

                checked={selectedTag === x.value}

                onChange={(checked) => handleChange(x.value, checked)}

              >

                {x.label}

              </CheckableTag>

            );

          })}

        </div>

      </Space>

    </Modal>
  );
};
export default SegmentSetModal;