JSFiddle - React, Tailwind, and code Playground

by Arvind Pal

JavaScript

let json = [
{
    "name": "Document to test all updated action",
    "description": "Document to test all updated action",
    "id": "816920332",
    "_id": "Thread/816920332",
    "type": "DOCUMENT", 
    "documentStatus": "DRAFT",
    "__typename": "Document",
    "parent": "Execution/9614Fni3j",
    "realtion": "workflow"
}, {
    "name": "Document to test all updated action after some changes",
    "description": "Document to test all updated action after some changes",
    "id": "816920333",
    "_id": "Thread/816920333",
    "type": "DOCUMENT", 
    "documentStatus": "INITIATED",
    "__typename": "Document",
    "parent": "Thread/816920334",
    "realtion": "linked"
}, {
    "name": "Document to capture the action and fields for history report-update",
    "description": "Document to capture the action and fields for history report",
    "id": "816920334",
    "_id": "Thread/816920334",
    "type": "DOCUMENT", 
    "documentStatus": "INITIATED",
    "__typename": "Document",
    "parent": "Tags/37107036",
    "realtion": "tag"
}, {
    "id": "41954865",
    "_id": "ThreadInput/41954865",
    "type": "TEXT",
    "order": 90000,
    "name": "A section with word action", 
    "__typename": "Text",
    "parent": "Thread/816920332",
    "realtion": "threadInput"
}];

let links = [];
for(let i=0; i<json.length; i++){
let targetValue =i;
	 for(let j=0;j<json.length; j++){
   	if(json[j]._id === json[i].parent){
    targetValue = j
    }
   }
	links.push({ 
    source: i,
    target:targetValue,
    value: 1
  });
}

console.log("links", JSON.stringify(links,null,2))