Skip to content

Commit

Permalink
IItem to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-Singh-MS committed Jul 10, 2024
1 parent 060b13b commit ecfded0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
43 changes: 24 additions & 19 deletions src/common/TreeStructure/CovertIItemToJson.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@

import { IItem } from './TreeView/Types/Entity/IItem';

const componentTypeMap: { [key: string]: string } = {
'08': 'web-temmplates',
'07': 'content-snippets',
'015': 'basic-forms',
'017': 'lists',
'019': 'advanced-forms'
};

export function generateJsonFromIItem(item: IItem): any {
const generateGUID = (): string => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
console.log(item);
const result: any = {
type: item.title,
label: item.label,
GUID: generateGUID(),
children: [],
parentList: item.parentList.map(parent => ({
type: parent.title,
label: parent.label,
GUID: generateGUID(),
}))
label: item.label
};

if (item.children && item.children.length > 0) {
result.children=item.children.map(child => generateJsonFromIItem(child));
result.children = item.children.map(child => {
const childResult = generateJsonFromIItem(child);
if (item.label === 'References') {
childResult['type'] = componentTypeMap[child.component];
}
return childResult;
});
}

if (item.parentList && item.parentList.length > 0) {
result.parentList = item.parentList.map(parent => ({
type: parent.title,
label: parent.label,
}));
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/common/TreeStructure/DataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ function processEntity(sourceDep: IItem, parent: IItem, targetIItem: IItem, enti
}
});
if (exist == false) {
const item = createItem(`${fileNameOrID} Not Used`, `${fileNameOrID}`, `${entity.tagName}`, true, vscode.Uri.parse(``), '', [], '', '');
const item = createItem(`${fileNameOrID} Not Used`, `${fileNameOrID}`, `${entity.tagName}`, true, vscode.Uri.parse(``), comp, [], '', '');
let fileNameAlready = sourceDep.children.find(child => child.label === `${fileNameOrID} Not Used`);
if (!fileNameAlready) {
sourceDep.children.push(item);
Expand Down

0 comments on commit ecfded0

Please sign in to comment.