baseData={
let pc_root=[];
let pc_tab=[];
let pc_group=[];
let pc_link=[];
rawData.map((row, i)=>{
if (i==0) {
pc_root.length=0;
pc_tab.length=0;
pc_group.length=0;
pc_link.length=0;
}
const r ={Level: "Root", pId: undefined, cId: "Root", pName: undefined, cName: "Root", name: "Root", title:"Root", Active: "1"}
const t ={Level: "Tab", pId: "Root", cId: row.TabKey, pName: "Root", cName: row.Tab, name: row.Tab, title: row.Tab, Active: row.Active};
const g ={Level: "Group", pId: row.TabKey, cId: row.GroupKey, pName: row.Tab, cName: row.Group, name: row.Group, title: row.Group, Active: row.Active};
const l ={Level: "Link", pId: row.GroupKey, cId: row.LinkKey, pName: row.Group, cName: row.Link, name: row.Link, title: row.Link, cUrl: row.Url, Active: row.Active};
const r_found = pc_root.find(el => { if (el.cId == r.cId) return true; return false;})
if (!r_found) {
pc_root.push(r);
}
const t_found = pc_tab.find(el => { if (el.cId == t.cId ) return true; return false;})
if (!t_found) {
pc_tab.push(t);
console.log('found:', t);
}
const g_found = pc_group.find(el => { if (el.cId == g.cId ) return true; return false;})
if (!g_found) {
pc_group.push(g);
}
const l_found = pc_link.find(el => { if (el.cId == l.cId ) return true; return false;})
if (!l_found) {
pc_link.push(l);
}
});
let resultData = null;
let flatData = [...pc_root, ...pc_tab, ...pc_group, ...pc_link];
if (activeOnly)
resultData = flatData.filter(f => f.Active=='1' );
else resultData = flatData;
let TabSearchResult = {Level: "Tab", pId: "Root", cId: "SearchResult", pName: "Root", cName: "SearchResult", name: "SearchResult", title: "SearchResult", Active: "1"}
resultData.push(TabSearchResult);
return resultData;
}