plugin-module/modeler-plugin-code/client/react/Code/CodeFragment.js
/**
   * Lifecycle react component method for side-effect calls (async)
   */
Lifecycle react component method for side-effect calls (async)
Lifecycle react component method for side - effect calls ( async )
componentDidMount() {
    const {
      subscribe,
      displayNotification,
      triggerAction,
      config,
      log
    } = this.props;
    subscribe('codeEditor.config', async payload => {
      const { modeler } = this.state;
      if (modeler) {
        let editorActions = modeler.get('editorActions');
        let action = {};
        payload.java.forEach((path, index) => {
          let key = 'toggleJDK_' + (index + 1);
          action[key] = function() {
            config.setForPlugin('codeEditor', 'java', path).catch(log.error);
            triggerAction('update-menu');
          };
        });
        editorActions.register(action);
      }
    });
    const saveTab = ({ activeTab }) => {
      if (activeTab.file && activeTab.file.path) {
        triggerAction('save')
          .then(tab => {
            if (!tab) {
              return displayNotification({ title: 'Failed to save' });
            }
          });
      }
    };
    subscribe('bpmn.modeler.created', ({ modeler, tab }) => {
      this._eventBus = modeler.get('eventBus');
      const { tabModeler }
        = this.state;
      this.setState({
        modeler: modeler,
        tabModeler: [...tabModeler, { tabId: tab.id, modeler: modeler }]
      });
      this._eventBus.on(OPEN_CODE_EDITOR, (event) => {
        let inputParams = event['inputParameters'].map(item => {
          return { name: item.name,type:'',value:'' };
        });
        this.setState({
          modalOpen: true,
          element: event.element,
          node: event.node,
          mode: event.mode,
          data: event.data,
          inputParameters: inputParams
        });
      });
    });
    subscribe('app.activeTabChanged', tab => {
      const {
        tabModeler
      } = this.state;
      let activeTabId = tab.activeTab.id;
      const activeModeler = find(tabModeler, { tabId: activeTabId });
      if (activeModeler) {
        this._eventBus = activeModeler.modeler.get('eventBus');
        this.setState({ modeler: activeModeler.modeler });
      }
      saveTab(tab);
    });
    subscribe('close-all-tabs', saveTab);
  }
componentDidMount ( ) { const { subscribe , displayNotification , triggerAction , config , log } = this . props ; subscribe ( 'codeEditor.config' , async payload => { const { modeler } = this . state ; if ( modeler ) { let editorActions = modeler . get ( 'editorActions' ) ; let action = { } ; payload . java . forEach ( ( path , index ) => { let key = 'toggleJDK_' + ( index + 1 ) ; action [ key ] = function ( ) { config . setForPlugin ( 'codeEditor' , 'java' , path ) . catch ( log . error ) ; triggerAction ( 'update-menu' ) ; } ; } ) ; editorActions . register ( action ) ; } } ) ; const saveTab = ( { activeTab } ) => { if ( activeTab . file && activeTab . file . path ) { triggerAction ( 'save' ) . then ( tab => { if ( ! tab ) { return displayNotification ( { title : 'Failed to save' } ) ; } } ) ; } } ; subscribe ( 'bpmn.modeler.created' , ( { modeler , tab } ) => { this . _eventBus = modeler . get ( 'eventBus' ) ; const { tabModeler } = this . state ; this . setState ( { modeler : modeler , tabModeler : [ ... tabModeler , { tabId : tab . id , modeler : modeler } ] } ) ; this . _eventBus . on ( OPEN_CODE_EDITOR , ( event ) => { let inputParams = event [ 'inputParameters' ] . map ( item => { return { name : item . name , type : '' , value : '' } ; } ) ; this . setState ( { modalOpen : true , element : event . element , node : event . node , mode : event . mode , data : event . data , inputParameters : inputParams } ) ; } ) ; } ) ; subscribe ( 'app.activeTabChanged' , tab => { const { tabModeler } = this . state ; let activeTabId = tab . activeTab . id ; const activeModeler = find ( tabModeler , { tabId : activeTabId } ) ; if ( activeModeler ) { this . _eventBus = activeModeler . modeler . get ( 'eventBus' ) ; this . setState ( { modeler : activeModeler . modeler } ) ; } saveTab ( tab ) ; } ) ; subscribe ( 'close-all-tabs' , saveTab ) ; }
Lifecycle react component method for side-effect calls (async)
Lifecycle react component method for side - effect calls ( async )
// trigger a tab save operation // Received command to open the editorModal for documentation