Skip to content

Commit

Permalink
Added level field to flatfiles for sorting
Browse files Browse the repository at this point in the history
Signed-off-by: Omkar Phansopkar <[email protected]>
  • Loading branch information
OmkarPh committed Dec 26, 2023
1 parent 99a1525 commit fcc4532
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/pages/TableView/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const TableView = () => {
],
},
},
order: ["level", "id"],
// order: ["id"],
})
)
.then((fileModels) => fileModels.map((fileModel) => fileModel.toJSON()))
Expand Down
10 changes: 8 additions & 2 deletions src/pages/TableView/columnDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ interface COLUMNS_LIST {
[key: string]: ColDef;

// Rest for IDE intellisense in column groups

path: ColDef;
level: ColDef;
type: ColDef;
name: ColDef;
extension: ColDef;
Expand Down Expand Up @@ -108,11 +108,17 @@ export const ALL_COLUMNS: COLUMNS_LIST = {
// Note - Path width is also calculated after import in TableView.tsx
// ALL_COLUMNS.path.width = calculatedColumnWidth;
},
level: {
field: "level",
colId: "level",
headerName: "Level",
initialWidth: 120,
},
type: {
field: "type",
colId: "type",
headerName: "Type",
initialWidth: 120,
initialWidth: 85,
},
name: {
field: "name",
Expand Down
1 change: 1 addition & 0 deletions src/pages/TableView/columnGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const SET_FILTERED_COLUMNS = new Set<string>([
]);

const FILE_COLUMN_GROUP: ColDef[] = [
ALL_COLUMNS.level,
ALL_COLUMNS.type,
ALL_COLUMNS.name,
ALL_COLUMNS.extension,
Expand Down
6 changes: 6 additions & 0 deletions src/services/models/flatFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import path from "path";
import { Sequelize, DataTypes, Model } from "sequelize";
import { jsonDataType, parentPath } from "./databaseUtils";
import { LicensePolicy, Resource } from "../importedJsonTypes";
import { getPathDepth } from "../../utils/paths";

export interface InfoFlatFileAttributes {
type: string;
Expand Down Expand Up @@ -110,6 +111,7 @@ export interface FlatFileAttributes
id: number;
fileId: number;
path: string;
level: number;
parent: string;
}

Expand All @@ -129,6 +131,7 @@ export default function flatFileModel(sequelize: Sequelize) {
unique: true,
allowNull: false,
},
level: DataTypes.INTEGER,
parent: { type: DataTypes.STRING, defaultValue: "" },
copyright_statements: jsonDataType("copyright_statements", []),
copyright_holders: jsonDataType("copyright_holders", []),
Expand Down Expand Up @@ -242,6 +245,7 @@ interface FlattenedFile {
fileId: number;
path: string;
parent: string;
level: number;
copyright_statements: unknown[];
copyright_holders: unknown[];
copyright_authors: unknown[];
Expand Down Expand Up @@ -311,11 +315,13 @@ interface FlattenedFile {
package_data_dependencies: unknown[];
package_data_related_packages: unknown[];
}

export function flattenFile(file: Resource): FlattenedFile {
return {
id: file.id,
fileId: file.id,
path: file.path,
level: getPathDepth(file.path),
parent: parentPath(file.path),
copyright_statements: getCopyrightValues(file.copyrights, "copyright"),
copyright_holders: getCopyrightValues(file.holders, "holder"),
Expand Down
6 changes: 6 additions & 0 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
export const figureOutDefaultSqliteFilePath = (jsonFilePath: string) =>
jsonFilePath.substring(0, jsonFilePath.lastIndexOf(".")) + ".sqlite";

export function getPathDepth(filePath: string) {
const separatorRegExp = /[\\/]/g;
const depth = (filePath.match(separatorRegExp) || []).length;
return depth;
}

0 comments on commit fcc4532

Please sign in to comment.