fixed prettier issues with FileExplorer files
Signed-off-by: Jeremy Guarini <jguarini@paloaltonetworks.com>
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2021 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { groupByPath } from './FileExplorer';
|
||||
|
||||
const dummyFiles = [
|
||||
@@ -23,8 +38,8 @@ const dummyFiles = [
|
||||
coverage: 1,
|
||||
missing: 1,
|
||||
tracked: 1,
|
||||
path: ''
|
||||
}
|
||||
path: '',
|
||||
},
|
||||
];
|
||||
|
||||
const dummyDataGroupedByPath = {
|
||||
@@ -35,7 +50,7 @@ const dummyDataGroupedByPath = {
|
||||
coverage: 1,
|
||||
missing: 1,
|
||||
tracked: 1,
|
||||
path: ''
|
||||
path: '',
|
||||
},
|
||||
{
|
||||
filename: 'dir1/file2',
|
||||
@@ -43,8 +58,8 @@ const dummyDataGroupedByPath = {
|
||||
coverage: 1,
|
||||
missing: 1,
|
||||
tracked: 1,
|
||||
path: ''
|
||||
}
|
||||
path: '',
|
||||
},
|
||||
],
|
||||
dir2: [
|
||||
{
|
||||
@@ -53,13 +68,13 @@ const dummyDataGroupedByPath = {
|
||||
coverage: 1,
|
||||
missing: 1,
|
||||
tracked: 1,
|
||||
path: ''
|
||||
}
|
||||
]
|
||||
path: '',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('groupByPath function', () => {
|
||||
it('should group files by their root directory,as per their filename', () => {
|
||||
expect(groupByPath(dummyFiles)).toBe(dummyDataGroupedByPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,12 +53,10 @@ type CoverageTableRow = {
|
||||
|
||||
export const groupByPath = (files: CoverageTableRow[]) => {
|
||||
const acc: FileStructureObject = {};
|
||||
files.forEach (file => {
|
||||
files.forEach(file => {
|
||||
const filename = file.filename;
|
||||
if (!file.filename) return;
|
||||
const pathArray = filename?.split('/').filter(
|
||||
el => el !== ''
|
||||
);
|
||||
const pathArray = filename?.split('/').filter(el => el !== '');
|
||||
if (pathArray) {
|
||||
if (!acc.hasOwnProperty(pathArray[0])) {
|
||||
acc[pathArray[0]] = [];
|
||||
@@ -69,11 +67,14 @@ export const groupByPath = (files: CoverageTableRow[]) => {
|
||||
return acc;
|
||||
};
|
||||
|
||||
const removeVisitedPathGroup = (files: CoverageTableRow[], pathGroup: string) => {
|
||||
const removeVisitedPathGroup = (
|
||||
files: CoverageTableRow[],
|
||||
pathGroup: string,
|
||||
) => {
|
||||
return files.map(file => {
|
||||
return {
|
||||
...file,
|
||||
filename: file.filename
|
||||
filename: file.filename
|
||||
? file.filename.substring(
|
||||
file.filename?.indexOf(pathGroup) + pathGroup.length + 1,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user