Skip to content

Commit ef4febc

Browse files
committed
Added level field to flatfiles for sorting
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent 99a1525 commit ef4febc

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", []),
@@ -242,6 +245,7 @@ interface FlattenedFile {
242245
fileId: number;
243246
path: string;
244247
parent: string;
248+
level: number;
245249
copyright_statements: unknown[];
246250
copyright_holders: unknown[];
247251
copyright_authors: unknown[];
@@ -311,11 +315,13 @@ interface FlattenedFile {
311315
package_data_dependencies: unknown[];
312316
package_data_related_packages: unknown[];
313317
}
318+
314319
export function flattenFile(file: Resource): FlattenedFile {
315320
return {
316321
id: file.id,
317322
fileId: file.id,
318323
path: file.path,
324+
level: getPathDepth(file.path),
319325
parent: parentPath(file.path),
320326
copyright_statements: getCopyrightValues(file.copyrights, "copyright"),
321327
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)