componentDidMount()

in src/routes/Plugin/PluginRuleHandle/ParamPluginRuleHandle.js [52:91]


  componentDidMount() {
    const {value} = this.props;
    const {body} = this.state;
    if (value) {
      const data = {};
      try {
        Object.assign(data, JSON.parse(value));
      } catch (e) {
        // eslint-disable-next-line no-console
        console.error(e)
      }
      const bodyData = [];
      const draftData = [];

      Object.keys(data).forEach(type => {
        if (Array.isArray(data[type])) {
          data[type].forEach(item => {
            if (typeof item === "string") {
              draftData.push({type, key: item});
            } else {
              draftData.push({type, ...item});
            }
          });
        }
        if (Object.prototype.toString.call(data[type]) === "[object Object]") {
          Object.keys(data[type]).forEach(key => {
            draftData.push({type, key, value: data[type][key]});
          });
        }
      });
      draftData.forEach((item, i) => {
        if (TypeKey.body.includes(item.type)) {
          bodyData.push({...item, id: i.toString()});
        }
      });
      this.setState({
        body: bodyData.concat(body),
      });
    }
  }