predefined and custom states operations

by bilbobaggins

JavaScript

let predefinedStates=['rejected', 'consice', 'compact','completed','closed', 'failure','success', 'failure investigation']

let prefinedStateDict=[];

predefinedStates.forEach((item) => {
  let evalpredefined=prefinedStateDict.filter(name => name.id.startsWith(item.charAt(0)))
  if(evalpredefined.length<=0)
  {
  prefinedStateDict.push({id:item,val:item.charAt(0)+1})
  }
  else
  {
  prefinedStateDict.push({id:item, val:item.charAt(0)+(parseInt(evalpredefined.slice(-1)[0].val.toString().replace(/^\D+/g, ''))+1)})
  }
  
  
});


const jsonCanvasData = {
	nodes: [
  { id: 'c1', type: 'text', text: 'completed', x: 200, y: 0, width: 100, height: 50 },
  { id: 'c2', type: 'text', text: 'closed', x: 200, y: 0, width: 100, height: 50 },
  { id: 'c3', type: 'text', text: 'cancel', x: 200, y: 0, width: 100, height: 50 },
              { id: 'r1', type: 'text', text: 'rejected', x: 200, y: 0, width: 100, height: 50 },
              { id: 'f1', type: 'text', text: 'failure', x: 200, y: 0, width: 100, height: 50 },
              { id: 'f2', type: 'text', text: 'failure investigation', x: 200, y: 0, width: 100, height: 50 },
    
    { id: '1', type: 'text', text: 'New', x: 0, y: 0, width: 100, height: 50 },
                { id: '2', type: 'text', text: 'awaiting usertype2', x: 200, y: 0, width: 100, height: 50 },
                { id: '3', type: 'text', text: 'awaiting usertype3', x: 200, y: 0, width: 100, height: 50 },
                { id: '4', type: 'text', text: 'after approval success', x: 200, y: 0, width: 100, height: 50 },
                
	],
	edges: [{ id: 'edge1', fromNode: '1', toNode: 'c3',label:'user cancel' }
,{ id: 'edge2', fromNode: '1', toNode: '2',label:'user submit ' }
,{ id: 'edge3', fromNode: 'c3', toNode: 'c2',label:'Closed ' }
,{ id: 'edge4', fromNode: '2', toNode: 'r1',label:'usertype2 reviews and reject' }
,{ id: 'edge5', fromNode: 'r1', toNode: 'c2',label:'rejected gets closed' }
,{ id: 'edge6', fromNode: '2', toNode: '3',label:'usertype2 reviews...