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

"Score" => "Severity" conversion to be done in the backend and not in the UI #45

Merged
merged 1 commit into from
Mar 9, 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
15 changes: 2 additions & 13 deletions frontend/client/src/app/api/model-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
global_warning_color_100 as moderateColor,
} from "@patternfly/react-tokens";

import { Severity } from "./models";
import { ProgressProps } from "@patternfly/react-core";

import { Severity } from "./models";

type ListType = {
[key in Severity]: {
shieldIconColor: { name: string; value: string; var: string };
Expand All @@ -33,15 +34,3 @@ export const severityList: ListType = {
progressProps: { variant: "danger" },
},
};

export const severityFromNumber = (score: number): Severity => {
if (score >= 9.0) {
return "critical";
} else if (score >= 7.0) {
return "important";
} else if (score >= 4.0) {
return "moderate";
} else {
return "low";
}
};
2 changes: 1 addition & 1 deletion frontend/client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ export interface AdvisoryVulnerability {
title: string;
discovery_date: string;
release_date: string;
score: number;
severity: Severity;
cwe: string;
}
30 changes: 0 additions & 30 deletions frontend/client/src/app/components/SeverityProgressBar.tsx

This file was deleted.

47 changes: 18 additions & 29 deletions frontend/client/src/app/components/SeverityShieldAndText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,33 @@ import React from "react";
import { Flex, FlexItem } from "@patternfly/react-core";
import ShieldIcon from "@patternfly/react-icons/dist/esm/icons/shield-alt-icon";

import { severityFromNumber, severityList } from "@app/api/model-utils";
import { severityList } from "@app/api/model-utils";
import { Severity } from "@app/api/models";

interface SeverityShieldAndTextProps {
value: Severity | number;
showLabel?: boolean;
value: Severity;
hideLabel?: boolean;
}

export const SeverityShieldAndText: React.FC<SeverityShieldAndTextProps> = ({
value,
showLabel,
hideLabel,
}) => {
let severity: Severity;
if (typeof value === "number") {
severity = severityFromNumber(value);
} else {
severity = value;
}

const severityProps = severityList[severity];
const severityProps = severityList[value];

return (
<>
<Flex
spaceItems={{ default: "spaceItemsXs" }}
alignItems={{ default: "alignItemsCenter" }}
flexWrap={{ default: "nowrap" }}
style={{ whiteSpace: "nowrap" }}
>
<FlexItem>
<ShieldIcon color={severityProps.shieldIconColor.value} />
</FlexItem>
{showLabel && (
<FlexItem>
{severity.charAt(0).toUpperCase() + severity.slice(1)}
</FlexItem>
)}
</Flex>
</>
<Flex
spaceItems={{ default: "spaceItemsXs" }}
alignItems={{ default: "alignItemsCenter" }}
flexWrap={{ default: "nowrap" }}
style={{ whiteSpace: "nowrap" }}
>
<FlexItem>
<ShieldIcon color={severityProps.shieldIconColor.value} />
</FlexItem>
{!hideLabel && (
<FlexItem>{value.charAt(0).toUpperCase() + value.slice(1)}</FlexItem>
)}
</Flex>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const AdvisoryDetails: React.FC = () => {
children: (
<SeverityShieldAndText
value={advisory.aggregated_severity}
showLabel
/>
),
isCompact: true,
Expand Down
14 changes: 3 additions & 11 deletions frontend/client/src/app/pages/advisory-details/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const Overview: React.FC<OverviewProps> = ({ advisory }) => {
<DescriptionListDescription>
<SeverityShieldAndText
value={advisory.aggregated_severity}
showLabel
/>
</DescriptionListDescription>
</DescriptionListGroup>
Expand Down Expand Up @@ -156,17 +155,10 @@ export const Overview: React.FC<OverviewProps> = ({ advisory }) => {
</Card>
</GridItem>
<GridItem md={8}>
{/* <Card isFullHeight>
<Card isFullHeight>
<CardTitle>Product info</CardTitle>
<CardBody>
<TreeView
data={productTreeData}
hasGuides={true}
variant="default"
useMemo
/>
</CardBody>
</Card> */}
<CardBody>Remaining to be defined</CardBody>
</Card>
</GridItem>
</Grid>
</StackItem>
Expand Down
1 change: 0 additions & 1 deletion frontend/client/src/app/pages/advisory-details/source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Source: React.FC<SourceProps> = ({ advisoryId }) => {
isLineNumbersVisible
isReadOnly
isMinimapVisible
// isLanguageLabelVisible
code={source ?? ""}
language={Language.json}
height="685px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import dayjs from "dayjs";
import { RENDER_DATE_FORMAT } from "@app/Constants";

import { AdvisoryVulnerability } from "@app/api/models";
import { SeverityShieldAndText } from "@app/components/SeverityShieldAndText";
import {
ConditionalTableBody,
FilterType,
useClientTableBatteries,
} from "@carlosthe19916-latest/react-table-batteries";
import { SeverityProgressBar } from "@app/components/SeverityProgressBar";

interface VulnerabilitiesProps {
vulnerabilities: AdvisoryVulnerability[];
Expand All @@ -35,7 +35,7 @@ export const Vulnerabilities: React.FC<VulnerabilitiesProps> = ({
title: "Title",
discovery: "Discovery",
release: "Release",
score: "Score",
severity: "Severity",
cwe: "CWE",
},
hasActionsColumn: true,
Expand Down Expand Up @@ -110,7 +110,7 @@ export const Vulnerabilities: React.FC<VulnerabilitiesProps> = ({
<Th columnKey="title" />
<Th columnKey="discovery" />
<Th columnKey="release" />
<Th columnKey="score" />
<Th columnKey="severity" />
<Th columnKey="cwe" />
</Tr>
</Thead>
Expand All @@ -136,8 +136,8 @@ export const Vulnerabilities: React.FC<VulnerabilitiesProps> = ({
<Td width={10} columnKey="release">
{dayjs(item.release_date).format(RENDER_DATE_FORMAT)}
</Td>
<Td width={15} columnKey="score">
<SeverityProgressBar value={item.score} />
<Td width={15} columnKey="severity">
<SeverityShieldAndText value={item.severity} />
</Td>
<Td width={10} columnKey="cwe">
{item.cwe}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const VulnerabilitiesCount: React.FC<VulnerabilitiesCountProps> = ({
style={{ whiteSpace: "nowrap" }}
>
<FlexItem>
<SeverityShieldAndText value={severity as Severity} />
<SeverityShieldAndText
value={severity as Severity}
hideLabel
/>
</FlexItem>
<FlexItem>{count}</FlexItem>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ export const useAdvisoryList = () => {
{item.metadata.title}
</Td>
<Td width={10} columnKey="severity">
<SeverityShieldAndText
value={item.aggregated_severity}
showLabel
/>
<SeverityShieldAndText value={item.aggregated_severity} />
</Td>
<Td width={10} modifier="truncate" columnKey="revisionDate">
{dayjs(item.revision_date).format(RENDER_DATE_FORMAT)}
Expand Down
8 changes: 6 additions & 2 deletions frontend/client/src/mocks/stub-new-work/advisories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const mockProjectArray: Advisory[] = [
title: "title1",
discovery_date: new Date().toString(),
release_date: new Date().toString(),
score: 7.5,
severity: "critical",
cwe: "cwe1",
},
],
Expand All @@ -58,7 +58,11 @@ export const handlers = [
}
}),
rest.get(`${AppRest.ADVISORIES}/:id/source`, (req, res, ctx) => {
return res(ctx.json("{}"));
return res(
ctx.json(
"This is Mock data, but the real API should return the advisory JSON file"
)
);
}),
];

Expand Down