Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Boolean cell renderer, refactored renderers, hidden license text for directories #627

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/pages/TableView/CustomCellRenderers/BooleanCellRenderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

interface BooleanCellRendererProps {
value: boolean;
}
const BooleanCellRenderer: React.FunctionComponent<BooleanCellRendererProps> = (
props
) => {
return props.value ? "Yes" : "No";
};

export default BooleanCellRenderer;
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -24,7 +26,7 @@ const FileLicenseCluesRenderer = (props: FileLicenseCluesRendererProps) => {

if (!parsedValue) return <></>;

if (!Array.isArray(parsedValue)) return value;
if (!Array.isArray(parsedValue)) return <>{value}</>;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -26,7 +26,7 @@ const FileLicenseDetectionsRenderer = (

if (!parsedValue) return <></>;

if (!Array.isArray(parsedValue)) return value;
if (!Array.isArray(parsedValue)) return <>{value}</>;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ interface FilePathRendererProps {
iconComponent?: React.ReactNode;
}

const FilePathRenderer = (props: FilePathRendererProps) => {
const FilePathRenderer: React.FunctionComponent<FilePathRendererProps> = (
props
) => {
const { value, iconComponent } = props;
const { goToFileInTableView } = useWorkbenchDB();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ interface RegionLinesRendererProps {
};
}

const RegionLinesRenderer = (props: RegionLinesRendererProps) => {
const RegionLinesRenderer: React.FunctionComponent<RegionLinesRendererProps> = (
props
) => {
const { data } = props;
return (
<span>
Expand Down
10 changes: 4 additions & 6 deletions src/pages/TableView/CustomCellRenderers/ListCellRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ interface ListCellRendererProps {
value: string;
}

const ListCellRenderer = (props: ListCellRendererProps) => {
const ListCellRenderer: React.FunctionComponent<ListCellRendererProps> = (
props
) => {
const parsedValue: string[][] | string[] | string = useMemo(() => {
if (Array.isArray(props.value)) return props.value;

Expand All @@ -30,11 +32,7 @@ const ListCellRenderer = (props: ListCellRendererProps) => {
? parsedValue.map((subValues, i) => (
<span key={i}>
{Array.isArray(subValues)
? subValues.map((value, j) => (
<span key={j}>
{value}
</span>
))
? subValues.map((value, j) => <span key={j}>{value}</span>)
: subValues}
<br />
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TableView/CustomCellRenderers/TickRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface TickRendererProps {
data: unknown;
}

const TickRenderer = (props: TickRendererProps) => {
const TickRenderer: React.FunctionComponent<TickRendererProps> = (props) => {
const { value } = props;

const icon = value ? faCheck : faX;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -12,7 +12,7 @@ interface UrlListCellRendererProps {
customDisplayTextFieldFallback?: string;
data: any;
}
const UrlListCellRenderer: FunctionComponent<UrlListCellRendererProps> = (
const UrlListCellRenderer: React.FunctionComponent<UrlListCellRendererProps> = (
props
) => {
const {
Expand Down Expand Up @@ -123,7 +123,7 @@ interface ListComponentProps {
urlSuffix?: string;
customDisplayText?: string;
}
const LinkComponent: FunctionComponent<ListComponentProps> = (props) => {
const LinkComponent: React.FunctionComponent<ListComponentProps> = (props) => {
const { value, routerLink, urlPrefix, urlSuffix, customDisplayText } = props;
const URL = (urlPrefix || "") + value + (urlSuffix || "");

Expand Down
16 changes: 9 additions & 7 deletions src/pages/TableView/CustomCellRenderers/index.tsx
Original file line number Diff line number Diff line change
@@ -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,
};
28 changes: 14 additions & 14 deletions src/pages/TableView/columnDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ import { ColDef, IFilterOptionDef } from "ag-grid-community";
import { ROUTES } from "../../constants/routes";
import { QUERY_KEYS } from "./../../constants/params";
import {
BooleanCellRenderer,
FileLicenseDetectionsRenderer,
FileLicenseCluesRenderer,
ListCellRenderer,
UrlListCellRenderer,
} 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, React.FunctionComponent> = {
[CustomComponentKeys.BooleanCellRenderer]: BooleanCellRenderer,
[CustomComponentKeys.FileLicenseDetectionsRenderer]:
FileLicenseDetectionsRenderer,
[CustomComponentKeys.FileLicenseCluesRenderer]: FileLicenseCluesRenderer,
[CustomComponentKeys.ListCellRenderer]: ListCellRenderer,
[CustomComponentKeys.UrlListCellRenderer]: UrlListCellRenderer,
};

export type ISimpleFilterModelType =
Expand All @@ -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;
Expand Down Expand Up @@ -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,
},

Expand Down
8 changes: 6 additions & 2 deletions src/services/models/flatFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", []),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/test-scans/licenses/expectedLicenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down