From 36de8f31b580521c0da4808ca62158c4e53ae60d Mon Sep 17 00:00:00 2001 From: sijumoncy <72241997+sijumoncy@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:50:05 +0530 Subject: [PATCH] added loggs --- .../EditorPage/Reference/OBS/ObsTn.js | 3 ++ .../Reference/OBS/ObsTsvToChapterLevel.js | 35 ++++++++++--------- .../EditorPage/Reference/OBS/TsvToJson.js | 7 ++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/renderer/src/components/EditorPage/Reference/OBS/ObsTn.js b/renderer/src/components/EditorPage/Reference/OBS/ObsTn.js index 279f1ef5..20fd0675 100644 --- a/renderer/src/components/EditorPage/Reference/OBS/ObsTn.js +++ b/renderer/src/components/EditorPage/Reference/OBS/ObsTn.js @@ -54,10 +54,13 @@ function ObsTnCard({ const projectName = `${offlineResource.data?.value?.meta?.name}_${offlineResource.data?.value?.meta?.owner}_${offlineResource.data?.value?.meta?.release?.tag_name}`; if (fs.existsSync(path.join(folder, projectName))) { if (offlineResource.data?.value?.dublin_core?.format?.toLowerCase() === 'text/tsv') { + logger.debug('inside OBS TN offline TSV resource'); const tsvFileName = offlineResource.data?.value?.projects[0]?.path; const obsTsvData = await fs.readFileSync(path.join(folder, projectName, tsvFileName), 'utf8'); const obsTsvJson = obsTsvData && await tsvJSON(obsTsvData); + logger.debug('inside OBS TN offline TSV resource : created TSV JSON'); await ObsTsvToChapterLevelMd(obsTsvJson, chapter).then((chapterTsvData) => { + logger.debug('inside OBS TN offline TSV resource : generated chapter Md level occurencenot Array'); setItems(chapterTsvData); }); } else { diff --git a/renderer/src/components/EditorPage/Reference/OBS/ObsTsvToChapterLevel.js b/renderer/src/components/EditorPage/Reference/OBS/ObsTsvToChapterLevel.js index f1469d00..badc71a0 100644 --- a/renderer/src/components/EditorPage/Reference/OBS/ObsTsvToChapterLevel.js +++ b/renderer/src/components/EditorPage/Reference/OBS/ObsTsvToChapterLevel.js @@ -1,25 +1,28 @@ // filter current chapter data from whole TSV JSON and generate array of notes of md content // based on reference of tsv +import * as logger from '../../../../logger'; export default async function ObsTsvToChapterLevelMd(tsvJSON, chapter) { return new Promise((resolve) => { + logger.debug('in ObsTsvToChapterLevel.js : in promise'); const filteredData = tsvJSON.filter((data) => data.Reference.split(':')[0].toString() === chapter.toString()); - const chapterTsvData = []; - const notesObj = {}; - filteredData.forEach((tsvObj) => { - let mdstring = ''; - mdstring += `# ${ tsvObj.Quote }\n\n${ tsvObj.Note }\n`; - if (tsvObj.Reference.split(':')[1] in notesObj) { - notesObj[tsvObj.Reference.split(':')[1]].OccurrenceNote += mdstring; - } else { - notesObj[tsvObj.Reference.split(':')[1]] = { OccurrenceNote: mdstring }; + const chapterTsvData = []; + const notesObj = {}; + filteredData.forEach((tsvObj) => { + let mdstring = ''; + mdstring += `# ${ tsvObj.Quote }\n\n${ tsvObj.Note }\n`; + if (tsvObj.Reference.split(':')[1] in notesObj) { + notesObj[tsvObj.Reference.split(':')[1]].OccurrenceNote += mdstring; + } else { + notesObj[tsvObj.Reference.split(':')[1]] = { OccurrenceNote: mdstring }; + } + }); + Object.values(notesObj).forEach((value) => { + chapterTsvData.push(value); + }); + if (chapterTsvData?.length > 0) { + logger.debug('in ObsTsvToChapterLevel.js : finished tsv md array resolved'); + resolve(chapterTsvData); } }); - Object.values(notesObj).forEach((value) => { - chapterTsvData.push(value); - }); - if (chapterTsvData?.length > 0) { - resolve(chapterTsvData); - } - }); } diff --git a/renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js b/renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js index cbff3d81..d7fab8dc 100644 --- a/renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js +++ b/renderer/src/components/EditorPage/Reference/OBS/TsvToJson.js @@ -1,6 +1,9 @@ +// convert TSV to line by line json +import * as logger from '../../../../logger'; + export default async function tsvJSON(tsv) { const lines = tsv.split('\n'); - + logger.debug('in TsvToJson.js : in convert function'); const result = []; const headers = lines[0].split('\t'); @@ -15,6 +18,6 @@ export default async function tsvJSON(tsv) { result.push(obj); } - + logger.debug('in TsvToJson.js : in convert function , Finished'); return result; }