Skip to content

Commit b5ea739

Browse files
authored
Merge pull request #625 from nexB/improve/depth-based-tableview-sort
Sorts the files in tableview by their depth in directory tree
2 parents 49e7126 + ef4febc commit b5ea739

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/pages/TableView/TableView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const TableView = () => {
7373
],
7474
},
7575
},
76+
order: ["level", "id"],
7677
})
7778
)
7879
.then((fileModels) => fileModels.map((fileModel) => fileModel.toJSON()))

src/pages/TableView/columnDefs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ interface COLUMNS_LIST {
5555
[key: string]: ColDef;
5656

5757
// Rest for IDE intellisense in column groups
58-
5958
path: ColDef;
6059
type: ColDef;
6160
name: ColDef;
@@ -112,7 +111,7 @@ export const ALL_COLUMNS: COLUMNS_LIST = {
112111
field: "type",
113112
colId: "type",
114113
headerName: "Type",
115-
initialWidth: 120,
114+
initialWidth: 85,
116115
},
117116
name: {
118117
field: "name",

src/services/models/flatFile.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import path from "path";
1818
import { Sequelize, DataTypes, Model } from "sequelize";
1919
import { jsonDataType, parentPath } from "./databaseUtils";
2020
import { LicensePolicy, Resource } from "../importedJsonTypes";
21+
import { getPathDepth } from "../../utils/paths";
2122

2223
export interface InfoFlatFileAttributes {
2324
type: string;
@@ -110,6 +111,7 @@ export interface FlatFileAttributes
110111
id: number;
111112
fileId: number;
112113
path: string;
114+
level: number;
113115
parent: string;
114116
}
115117

@@ -129,6 +131,7 @@ export default function flatFileModel(sequelize: Sequelize) {
129131
unique: true,
130132
allowNull: false,
131133
},
134+
level: DataTypes.INTEGER,
132135
parent: { type: DataTypes.STRING, defaultValue: "" },
133136
copyright_statements: jsonDataType("copyright_statements", []),
134137
copyright_holders: jsonDataType("copyright_holders", []),
@@ -245,6 +248,7 @@ interface FlattenedFile {
245248
fileId: number;
246249
path: string;
247250
parent: string;
251+
level: number;
248252
copyright_statements: unknown[];
249253
copyright_holders: unknown[];
250254
copyright_authors: unknown[];
@@ -314,11 +318,13 @@ interface FlattenedFile {
314318
package_data_dependencies: unknown[];
315319
package_data_related_packages: unknown[];
316320
}
321+
317322
export function flattenFile(file: Resource): FlattenedFile {
318323
return {
319324
id: file.id,
320325
fileId: file.id,
321326
path: file.path,
327+
level: getPathDepth(file.path),
322328
parent: parentPath(file.path),
323329
copyright_statements: getCopyrightValues(file.copyrights, "copyright"),
324330
copyright_holders: getCopyrightValues(file.holders, "holder"),

src/utils/paths.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
export const figureOutDefaultSqliteFilePath = (jsonFilePath: string) =>
22
jsonFilePath.substring(0, jsonFilePath.lastIndexOf(".")) + ".sqlite";
3+
4+
export function getPathDepth(filePath: string) {
5+
const separatorRegExp = /[\\/]/g;
6+
const depth = (filePath.match(separatorRegExp) || []).length;
7+
return depth;
8+
}

0 commit comments

Comments
 (0)