From 6bfa59e323ca61db813130191a1ed247d5cd33d7 Mon Sep 17 00:00:00 2001 From: N-Shar-ma Date: Tue, 19 Oct 2021 02:13:37 +0530 Subject: [PATCH] Minor tsc check passing fixes Signed-off-by: N-Shar-ma --- .../components/FileExplorer/FileExplorer.tsx | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx index e5627ab2c7..bc36af265d 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileExplorer.tsx @@ -59,23 +59,27 @@ export const groupByPath = (files: CoverageTableRow[]) => { const pathArray = filename?.split('/').filter( el => el !== '' ); - if (!acc.hasOwnProperty(pathArray[0])) { - acc[pathArray[0]] = []; + if (pathArray) { + if (!acc.hasOwnProperty(pathArray[0])) { + acc[pathArray[0]] = []; + } + acc[pathArray[0]].push(file); } - acc[pathArray[0]].push(file); }); return acc; }; -const trimFileNamesAsYouGo = (files: CoverageTableRow[], pathGroup: string) => { +const removeVisitedPathGroup = (files: CoverageTableRow[], pathGroup: string) => { return files.map(file => { return { ...file, - filename: file.filename ? file.filename.substring( - file.filename?.indexOf(pathGroup) + pathGroup.length + 1, - ) : file.filename, + filename: file.filename + ? file.filename.substring( + file.filename?.indexOf(pathGroup) + pathGroup.length + 1, + ) + : file.filename, }; - }) + }); }; const buildFileStructure = (row: CoverageTableRow) => { @@ -84,8 +88,8 @@ const buildFileStructure = (row: CoverageTableRow) => { return buildFileStructure({ path: pathGroup, files: dataGroupedByPath.hasOwnProperty('files') - ? trimFileNamesAsYouGo(dataGroupedByPath.files, pathGroup) - : trimFileNamesAsYouGo(dataGroupedByPath[pathGroup], pathGroup), + ? removeVisitedPathGroup(dataGroupedByPath.files, pathGroup) + : removeVisitedPathGroup(dataGroupedByPath[pathGroup], pathGroup), coverage: dataGroupedByPath[pathGroup].reduce( (acc: number, cur: CoverageTableRow) => acc + cur.coverage,