fleet/frontend/pages/SoftwarePage/components/SoftwareVulnerabilitiesTable/SoftwareVulnerabilitiesTableConfig.tsx

228 lines
6.2 KiB
TypeScript
Raw Normal View History

2022-06-08 19:01:38 +00:00
import React from "react";
import { formatSeverity } from "utilities/helpers";
import { ISoftwareVulnerability } from "interfaces/software";
2022-06-08 19:01:38 +00:00
import paths from "router/paths";
2022-06-08 19:01:38 +00:00
import HeaderCell from "components/TableContainer/DataTable/HeaderCell/HeaderCell";
import TextCell from "components/TableContainer/DataTable/TextCell";
import TooltipWrapper from "components/TooltipWrapper";
Fix certain datetimes to display "Never" when they are prior to Fleet's launch date (#14487) # Checklist for submitter - [x] Added/updated tests - [x] Manual QA for all new/changed functionality > [!NOTE] > For the reviewer, you won't hurt my feelings at all if you have a better implementation in mind and want to close this out! I'll be upfront that I'm much more of a Go dev than a frontend dev. I'm just using this issue as an opportunity to become more familiar with Fleet, since I'm a fan of what y'all are doing and have been looking for a project to spend some spare-time contributing to 😄 > > You should also have edit access to this branch, so feel free to commandeer it as you see fit. # Summary This PR aims to fix a regression identified in #14353 in which certain "zero" datetimes are displayed as "54 years ago" instead of the preferred "Never". The "zero" datetimes are commonly used [as a proxy to indicate](https://github.com/fleetdm/fleet/blob/5cb8051a409df9e82178d9cbe67e7d2370016db2/server/datastore/mysql/hosts.go#L1649) that a date wasn't set, e.g. when a host hasn't had its details fetched yet. We don't want to apply this treatment to _all_ datetimes, since some (like vulnerability data) have valid dates before Fleet was created. To support both use cases, I: * Added an optional boolean, `cutoffBeforeFleetLaunch`, to indicate that dates should be cutoff prior to the hardcoded Fleet launch date. This is set to `false` in `HumanTimeDiffWithDateTip` for backwards-compatibility. * Created `HumanTimeDiffWithFleetLaunchCutoff` which is a drop-in replacement for `HumanTimeDiffWithDateTip` that sets the `cutoffBeforeFleetLaunch` flag to `true`. I then used `HumanTimeDiffWithFleetLaunchCutoff` in the various host related fields I could find. It's possible I missed some, so please double-check me! I'm still getting my bearings on the codebase. Here's a screenshot showing the host table with a host that I had deleted and waited to appear again: <img width="1381" alt="Screenshot 2023-10-11 at 11 27 29 PM" src="https://github.com/fleetdm/fleet/assets/1317288/3cd23879-3233-409f-91a0-8b5e02d09deb"> You may find it helpful to review this commit-by-commit. Closes #14353
2023-10-16 15:43:47 +00:00
import { HumanTimeDiffWithDateTip } from "components/HumanTimeDiffWithDateTip";
import PremiumFeatureIconWithTooltip from "components/PremiumFeatureIconWithTooltip";
import ProbabilityOfExploit from "components/ProbabilityOfExploit/ProbabilityOfExploit";
import ViewAllHostsLink from "components/ViewAllHostsLink";
import LinkCell from "components/TableContainer/DataTable/LinkCell";
2022-06-08 19:01:38 +00:00
interface IHeaderProps {
column: {
title: string;
isSortedDesc: boolean;
};
}
interface ICellProps {
cell: {
value: number | string | string[];
};
row: {
original: ISoftwareVulnerability;
2022-06-08 19:01:38 +00:00
index: number;
};
}
interface ITextCellProps extends ICellProps {
cell: {
value: string | number;
};
}
interface IDataColumn {
title: string;
Header: ((props: IHeaderProps) => JSX.Element) | string;
accessor: string;
Cell: (props: ITextCellProps) => JSX.Element;
disableHidden?: boolean;
disableSortBy?: boolean;
sortType?: string;
}
const generateTableConfig = (
isPremiumTier: boolean,
isSandboxMode: boolean
): IDataColumn[] => {
2022-06-08 19:01:38 +00:00
const tableHeaders: IDataColumn[] = [
{
title: "Vunerability",
accessor: "cve",
disableSortBy: true,
Header: "Vulnerability",
Cell: ({ cell: { value } }: ITextCellProps) => {
const cveName = value.toString();
2022-06-08 19:01:38 +00:00
return (
<LinkCell
value={cveName}
path={paths.SOFTWARE_VULNERABILITY_DETAILS(cveName)}
/>
2022-06-08 19:01:38 +00:00
);
},
},
];
const premiumHeaders: IDataColumn[] = [
{
title: "Severity",
accessor: "cvss_score",
disableSortBy: false,
Header: (headerProps: IHeaderProps): JSX.Element => {
const titleWithToolTip = (
<TooltipWrapper
2023-11-07 21:15:49 +00:00
tipContent={
<>
The worst case impact across different environments (CVSS base
score).
</>
}
2022-06-08 19:01:38 +00:00
>
Severity
</TooltipWrapper>
);
return (
<>
<HeaderCell
value={titleWithToolTip}
isSortedDesc={headerProps.column.isSortedDesc}
/>
{isSandboxMode && <PremiumFeatureIconWithTooltip />}
</>
2022-06-08 19:01:38 +00:00
);
},
Cell: ({ cell: { value } }: ITextCellProps): JSX.Element => (
<TextCell formatter={formatSeverity} value={value} />
),
},
{
title: "Probability of exploit",
accessor: "epss_probability",
2022-06-08 19:01:38 +00:00
disableSortBy: false,
Header: (headerProps: IHeaderProps): JSX.Element => {
const titleWithToolTip = (
<TooltipWrapper
className="epss_probability"
2023-11-07 21:15:49 +00:00
tipContent={
<>
The probability that this vulnerability will be exploited in the
next 30 days (EPSS probability). <br />
This data is reported by FIRST.org.
2023-11-07 21:15:49 +00:00
</>
}
2022-06-08 19:01:38 +00:00
>
Probability of exploit
2022-06-08 19:01:38 +00:00
</TooltipWrapper>
);
return (
<>
<HeaderCell
value={titleWithToolTip}
isSortedDesc={headerProps.column.isSortedDesc}
/>
{isSandboxMode && <PremiumFeatureIconWithTooltip />}
</>
2022-06-08 19:01:38 +00:00
);
},
Cell: (cellProps: ICellProps): JSX.Element => (
<ProbabilityOfExploit
probabilityOfExploit={cellProps.row.original.epss_probability}
cisaKnownExploit={cellProps.row.original.cisa_known_exploit}
/>
2022-06-08 19:01:38 +00:00
),
},
{
title: "Published",
accessor: "cve_published",
disableSortBy: false,
Header: (headerProps: IHeaderProps): JSX.Element => {
const titleWithToolTip = (
<TooltipWrapper
2023-11-07 21:15:49 +00:00
tipContent={
<>
The date this vulnerability was published in the National
Vulnerability Database (NVD).
</>
}
>
Published
</TooltipWrapper>
);
return (
<>
<HeaderCell
value={titleWithToolTip}
isSortedDesc={headerProps.column.isSortedDesc}
/>
{isSandboxMode && <PremiumFeatureIconWithTooltip />}
</>
);
},
Cell: ({ cell: { value } }: ITextCellProps): JSX.Element => {
const valString = typeof value === "number" ? value.toString() : value;
return (
<TextCell
value={valString ? { timeString: valString } : undefined}
formatter={valString ? HumanTimeDiffWithDateTip : undefined}
/>
);
},
},
{
title: "Detected",
accessor: "created_at",
disableSortBy: false,
Header: (headerProps: IHeaderProps): JSX.Element => {
return (
<>
<HeaderCell
value="Detected"
isSortedDesc={headerProps.column.isSortedDesc}
/>
{isSandboxMode && <PremiumFeatureIconWithTooltip />}
</>
);
},
Cell: (cellProps: ICellProps): JSX.Element => {
const createdAt = cellProps.row.original.created_at || "";
return (
<TextCell
value={{ timeString: createdAt }}
formatter={HumanTimeDiffWithDateTip}
/>
);
},
},
{
title: "",
Header: "",
accessor: "linkToFilteredHosts",
disableSortBy: true,
Cell: (cellProps: ICellProps) => {
return (
<>
{cellProps.row.original && (
<ViewAllHostsLink
queryParams={{
vulnerability: cellProps.row.original.cve,
}}
className="vulnerabilities-link"
rowHover
/>
)}
</>
);
},
},
2022-06-08 19:01:38 +00:00
];
return isPremiumTier ? tableHeaders.concat(premiumHeaders) : tableHeaders;
};
export default generateTableConfig;