componentDidMount()

in src/routes/Plugin/Discovery/ProxySelectorModal.js [55:101]


  componentDidMount() {
    const { isAdd, isSetConfig, tcpType, data, pluginId, dispatch } = this.props;
    const { discoveryDicts } = this.state;
    const { props } = this.props.data || {};

    if (!isAdd || isSetConfig) {
      this.setState({configPropsJson: isSetConfig === true? {} : JSON.parse(data.discovery.props)})
      dispatch({
        type: 'discovery/saveGlobalType',
        payload: {
          chosenType: tcpType
        }
      });
    }else{
      let configProps = discoveryDicts.filter(item => item.dictName === 'zookeeper');
      let propsEntries = JSON.parse(configProps[0]?.dictValue || "{}");
      this.setState({configPropsJson: propsEntries})
      dispatch({
        type: 'discovery/saveGlobalType',
        payload: {
          chosenType: ''
        }
      });
    }

    let type = 1;
    dispatch({
      type: "pluginHandle/fetchByPluginId",
      payload: {
        pluginId,
        type,
        handle: Object.keys(props).length === 0 ? '' : props,
        isHandleArray: false,
        callBack: (pluginHandles) => {
          if  (Object.keys(pluginHandles).length > 0) {
            const filteredArray = pluginHandles[0].filter(item => item.field !== 'discoveryHandler');
            const handlerArray = pluginHandles[0].filter(item => item.field === 'discoveryHandler');
            pluginHandles[0] = filteredArray;
            this.setState({discoveryHandler: handlerArray});
            this.setState({ pluginHandleList: pluginHandles });
            let defaultValue = handlerArray[0].defaultValue;
            this.setState({ defaultValueList: defaultValue.split(",")  });
          }
        }
      }
    });
  }