From 356f504a5de29ead9f32e61156adb1adf8e8a20f Mon Sep 17 00:00:00 2001 From: Omkar Phansopkar Date: Mon, 22 Jan 2024 11:44:55 +0530 Subject: [PATCH] Fixed Boolean cell renderer & refactored renderers Signed-off-by: Omkar Phansopkar --- .../BooleanCellRenderer.tsx | 12 ++++++++ .../Licenses/DetectionOriginRenderer.tsx | 4 ++- .../Licenses/FileLicenseCluesRenderer.tsx | 6 ++-- .../FileLicenseDetectionsRenderer.tsx | 8 +++--- .../Licenses/FilePathRenderer.tsx | 4 ++- .../Licenses/RegionLinesRenderer.tsx | 4 ++- .../CustomCellRenderers/ListCellRenderer.tsx | 10 +++---- .../CustomCellRenderers/TickRenderer.tsx | 2 +- .../UrlListCellRenderer.tsx | 6 ++-- .../TableView/CustomCellRenderers/index.tsx | 16 ++++++----- src/pages/TableView/columnDefs.ts | 28 +++++++++---------- src/services/models/flatFile.ts | 8 ++++-- tests/test-scans/licenses/expectedLicenses.ts | 2 +- 13 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 src/pages/TableView/CustomCellRenderers/BooleanCellRenderer.tsx diff --git a/src/pages/TableView/CustomCellRenderers/BooleanCellRenderer.tsx b/src/pages/TableView/CustomCellRenderers/BooleanCellRenderer.tsx new file mode 100644 index 00000000..60ea53c5 --- /dev/null +++ b/src/pages/TableView/CustomCellRenderers/BooleanCellRenderer.tsx @@ -0,0 +1,12 @@ +import React from "react"; + +interface BooleanCellRendererProps { + value: boolean; +} +const BooleanCellRenderer: React.FunctionComponent = ( + props +) => { + return props.value ? "Yes" : "No"; +}; + +export default BooleanCellRenderer; diff --git a/src/pages/TableView/CustomCellRenderers/Licenses/DetectionOriginRenderer.tsx b/src/pages/TableView/CustomCellRenderers/Licenses/DetectionOriginRenderer.tsx index 1a65b022..71dcac2d 100644 --- a/src/pages/TableView/CustomCellRenderers/Licenses/DetectionOriginRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/Licenses/DetectionOriginRenderer.tsx @@ -16,7 +16,9 @@ enum ORIGIN { PACKAGE_DATA = "package_data", } -const DetectionOriginRenderer = (props: DetectionOriginRendererProps) => { +const DetectionOriginRenderer: React.FunctionComponent< + DetectionOriginRendererProps +> = (props) => { const { value, data } = props; const { goToFileInTableView, goToPackage } = useWorkbenchDB(); diff --git a/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseCluesRenderer.tsx b/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseCluesRenderer.tsx index eed552bf..3ce6e46a 100644 --- a/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseCluesRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseCluesRenderer.tsx @@ -7,7 +7,9 @@ interface FileLicenseCluesRendererProps { value: LicenseClueDetails[]; } -const FileLicenseCluesRenderer = (props: FileLicenseCluesRendererProps) => { +const FileLicenseCluesRenderer: React.FunctionComponent< + FileLicenseCluesRendererProps +> = (props) => { const { value } = props; const parsedValue: LicenseClueDetails[] = useMemo(() => { @@ -24,7 +26,7 @@ const FileLicenseCluesRenderer = (props: FileLicenseCluesRendererProps) => { if (!parsedValue) return <>; - if (!Array.isArray(parsedValue)) return value; + if (!Array.isArray(parsedValue)) return <>{value}; return ( <> diff --git a/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseDetectionsRenderer.tsx b/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseDetectionsRenderer.tsx index 0a56f67e..fa4a78d1 100644 --- a/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseDetectionsRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/Licenses/FileLicenseDetectionsRenderer.tsx @@ -7,9 +7,9 @@ interface FileLicenseDetectionsRendererProps { value: LicenseDetectionAttributes[]; } -const FileLicenseDetectionsRenderer = ( - props: FileLicenseDetectionsRendererProps -) => { +const FileLicenseDetectionsRenderer: React.FunctionComponent< + FileLicenseDetectionsRendererProps +> = (props) => { const { value } = props; const parsedValue: LicenseDetectionAttributes[] = useMemo(() => { @@ -26,7 +26,7 @@ const FileLicenseDetectionsRenderer = ( if (!parsedValue) return <>; - if (!Array.isArray(parsedValue)) return value; + if (!Array.isArray(parsedValue)) return <>{value}; return ( <> diff --git a/src/pages/TableView/CustomCellRenderers/Licenses/FilePathRenderer.tsx b/src/pages/TableView/CustomCellRenderers/Licenses/FilePathRenderer.tsx index 67bf33cc..1372f2e7 100644 --- a/src/pages/TableView/CustomCellRenderers/Licenses/FilePathRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/Licenses/FilePathRenderer.tsx @@ -7,7 +7,9 @@ interface FilePathRendererProps { iconComponent?: React.ReactNode; } -const FilePathRenderer = (props: FilePathRendererProps) => { +const FilePathRenderer: React.FunctionComponent = ( + props +) => { const { value, iconComponent } = props; const { goToFileInTableView } = useWorkbenchDB(); diff --git a/src/pages/TableView/CustomCellRenderers/Licenses/RegionLinesRenderer.tsx b/src/pages/TableView/CustomCellRenderers/Licenses/RegionLinesRenderer.tsx index 2f300cb3..abe0b228 100644 --- a/src/pages/TableView/CustomCellRenderers/Licenses/RegionLinesRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/Licenses/RegionLinesRenderer.tsx @@ -7,7 +7,9 @@ interface RegionLinesRendererProps { }; } -const RegionLinesRenderer = (props: RegionLinesRendererProps) => { +const RegionLinesRenderer: React.FunctionComponent = ( + props +) => { const { data } = props; return ( diff --git a/src/pages/TableView/CustomCellRenderers/ListCellRenderer.tsx b/src/pages/TableView/CustomCellRenderers/ListCellRenderer.tsx index 1afffada..ebf05b1e 100644 --- a/src/pages/TableView/CustomCellRenderers/ListCellRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/ListCellRenderer.tsx @@ -4,7 +4,9 @@ interface ListCellRendererProps { value: string; } -const ListCellRenderer = (props: ListCellRendererProps) => { +const ListCellRenderer: React.FunctionComponent = ( + props +) => { const parsedValue: string[][] | string[] | string = useMemo(() => { if (Array.isArray(props.value)) return props.value; @@ -30,11 +32,7 @@ const ListCellRenderer = (props: ListCellRendererProps) => { ? parsedValue.map((subValues, i) => ( {Array.isArray(subValues) - ? subValues.map((value, j) => ( - - {value} - - )) + ? subValues.map((value, j) => {value}) : subValues}
diff --git a/src/pages/TableView/CustomCellRenderers/TickRenderer.tsx b/src/pages/TableView/CustomCellRenderers/TickRenderer.tsx index a677235e..6dfc420e 100644 --- a/src/pages/TableView/CustomCellRenderers/TickRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/TickRenderer.tsx @@ -7,7 +7,7 @@ interface TickRendererProps { data: unknown; } -const TickRenderer = (props: TickRendererProps) => { +const TickRenderer: React.FunctionComponent = (props) => { const { value } = props; const icon = value ? faCheck : faX; diff --git a/src/pages/TableView/CustomCellRenderers/UrlListCellRenderer.tsx b/src/pages/TableView/CustomCellRenderers/UrlListCellRenderer.tsx index 13a55f6d..6c2ebb13 100644 --- a/src/pages/TableView/CustomCellRenderers/UrlListCellRenderer.tsx +++ b/src/pages/TableView/CustomCellRenderers/UrlListCellRenderer.tsx @@ -1,4 +1,4 @@ -import React, { FunctionComponent, useMemo } from "react"; +import React, { useMemo } from "react"; import { Link } from "react-router-dom"; import CoreLink from "../../../components/CoreLink/CoreLink"; @@ -12,7 +12,7 @@ interface UrlListCellRendererProps { customDisplayTextFieldFallback?: string; data: any; } -const UrlListCellRenderer: FunctionComponent = ( +const UrlListCellRenderer: React.FunctionComponent = ( props ) => { const { @@ -123,7 +123,7 @@ interface ListComponentProps { urlSuffix?: string; customDisplayText?: string; } -const LinkComponent: FunctionComponent = (props) => { +const LinkComponent: React.FunctionComponent = (props) => { const { value, routerLink, urlPrefix, urlSuffix, customDisplayText } = props; const URL = (urlPrefix || "") + value + (urlSuffix || ""); diff --git a/src/pages/TableView/CustomCellRenderers/index.tsx b/src/pages/TableView/CustomCellRenderers/index.tsx index 0f669194..0e4a3017 100644 --- a/src/pages/TableView/CustomCellRenderers/index.tsx +++ b/src/pages/TableView/CustomCellRenderers/index.tsx @@ -1,19 +1,21 @@ +import BooleanCellRenderer from "./BooleanCellRenderer"; +import DetectionOriginRenderer from "./Licenses/DetectionOriginRenderer"; import FileLicenseDetectionsRenderer from "./Licenses/FileLicenseDetectionsRenderer"; import FileLicenseCluesRenderer from "./Licenses/FileLicenseCluesRenderer"; import FilePathRenderer from "./Licenses/FilePathRenderer"; -import DetectionOriginRenderer from "./Licenses/DetectionOriginRenderer"; -import RegionLinesRenderer from "./Licenses/RegionLinesRenderer"; import ListCellRenderer from "./ListCellRenderer"; -import UrlListCellRenderer from "./UrlListCellRenderer"; +import RegionLinesRenderer from "./Licenses/RegionLinesRenderer"; import TickRenderer from "./TickRenderer"; +import UrlListCellRenderer from "./UrlListCellRenderer"; export { - TickRenderer, - ListCellRenderer, - RegionLinesRenderer, + BooleanCellRenderer, DetectionOriginRenderer, - UrlListCellRenderer, FilePathRenderer, FileLicenseDetectionsRenderer, FileLicenseCluesRenderer, + ListCellRenderer, + RegionLinesRenderer, + TickRenderer, + UrlListCellRenderer, }; diff --git a/src/pages/TableView/columnDefs.ts b/src/pages/TableView/columnDefs.ts index 3a313b61..7441cca9 100644 --- a/src/pages/TableView/columnDefs.ts +++ b/src/pages/TableView/columnDefs.ts @@ -3,6 +3,7 @@ import { ColDef, IFilterOptionDef } from "ag-grid-community"; import { ROUTES } from "../../constants/routes"; import { QUERY_KEYS } from "./../../constants/params"; import { + BooleanCellRenderer, FileLicenseDetectionsRenderer, FileLicenseCluesRenderer, ListCellRenderer, @@ -10,19 +11,20 @@ import { } from "./CustomCellRenderers"; enum CustomComponentKeys { - ListCellRenderer = "ListCellRenderer", - UrlListCellRenderer = "UrlListCellRenderer", - LicenseExpressionRenderer = "LicenseExpressionRenderer", + BooleanCellRenderer = "BooleanCellRenderer", FileLicenseDetectionsRenderer = "FileLicenseDetectionsRenderer", FileLicenseCluesRenderer = "FileLicenseCluesRenderer", + ListCellRenderer = "ListCellRenderer", + UrlListCellRenderer = "UrlListCellRenderer", } -export const frameworkComponents = { - [CustomComponentKeys.ListCellRenderer]: ListCellRenderer, - [CustomComponentKeys.UrlListCellRenderer]: UrlListCellRenderer, +export const frameworkComponents: Record = { + [CustomComponentKeys.BooleanCellRenderer]: BooleanCellRenderer, [CustomComponentKeys.FileLicenseDetectionsRenderer]: FileLicenseDetectionsRenderer, [CustomComponentKeys.FileLicenseCluesRenderer]: FileLicenseCluesRenderer, + [CustomComponentKeys.ListCellRenderer]: ListCellRenderer, + [CustomComponentKeys.UrlListCellRenderer]: UrlListCellRenderer, }; export type ISimpleFilterModelType = @@ -48,8 +50,6 @@ export const FILTER_OPTIONS: FilterOptionsMap = { LIST_FILTERS: ["contains", "notContains"], }; -const BooleanValueRenderer = (value: boolean) => (value ? "Yes" : "No"); - interface COLUMNS_LIST { // Required to update select options by field string [key: string]: ColDef; @@ -154,42 +154,42 @@ export const ALL_COLUMNS: COLUMNS_LIST = { field: "is_binary", colId: "is_binary", headerName: "Binary File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, is_text: { field: "is_text", colId: "is_text", headerName: "Text File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, is_archive: { field: "is_archive", colId: "is_archive", headerName: "Archive File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, is_media: { field: "is_media", colId: "is_media", headerName: "Media File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, is_source: { field: "is_source", colId: "is_source", headerName: "Source File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, is_script: { field: "is_script", colId: "is_script", headerName: "Script File", - cellRenderer: BooleanValueRenderer, + cellRenderer: CustomComponentKeys.BooleanCellRenderer, initialWidth: 100, }, diff --git a/src/services/models/flatFile.ts b/src/services/models/flatFile.ts index b297b896..1fc6d9a2 100644 --- a/src/services/models/flatFile.ts +++ b/src/services/models/flatFile.ts @@ -138,7 +138,10 @@ export default function flatFileModel(sequelize: Sequelize) { detected_license_expression: DataTypes.STRING, detected_license_expression_spdx: DataTypes.STRING, - percentage_of_license_text: DataTypes.NUMBER, + percentage_of_license_text: { + type: DataTypes.NUMBER, + allowNull: true, + }, license_clues: jsonDataType("license_clues", []), license_policy: jsonDataType("license_policy", []), license_detections: jsonDataType("license_detections", []), @@ -325,7 +328,8 @@ export function flattenFile(file: Resource): FlattenedFile { detected_license_expression: file.detected_license_expression, detected_license_expression_spdx: file.detected_license_expression_spdx, - percentage_of_license_text: file.percentage_of_license_text, + percentage_of_license_text: + file?.type === "file" ? file?.percentage_of_license_text : null, license_clues: file.license_clues, license_policy: getLicensePolicyLabel(file.license_policy), license_detections: file.license_detections, diff --git a/tests/test-scans/licenses/expectedLicenses.ts b/tests/test-scans/licenses/expectedLicenses.ts index bf9877e4..ed6126dd 100644 --- a/tests/test-scans/licenses/expectedLicenses.ts +++ b/tests/test-scans/licenses/expectedLicenses.ts @@ -727,7 +727,7 @@ export const LicenseSamples: { license_detections: [], detected_license_expression: null, detected_license_expression_spdx: null, - percentage_of_license_text: 0, + percentage_of_license_text: null, }, { license_clues: [],