2023-12-12 21:03:33 +00:00
|
|
|
import React from "react";
|
2024-03-13 19:09:16 +00:00
|
|
|
import { CellProps, Column } from "react-table";
|
2023-12-12 21:03:33 +00:00
|
|
|
import { InjectedRouter } from "react-router";
|
|
|
|
|
|
2024-02-14 17:58:40 +00:00
|
|
|
import { buildQueryStringFromParams } from "utilities/url";
|
2023-12-12 21:03:33 +00:00
|
|
|
import {
|
|
|
|
|
formatSoftwareType,
|
|
|
|
|
ISoftwareVersion,
|
|
|
|
|
ISoftwareVulnerability,
|
|
|
|
|
} from "interfaces/software";
|
2024-03-13 19:09:16 +00:00
|
|
|
import { IHeaderProps, IStringCellProps } from "interfaces/datatable_config";
|
2023-12-12 21:03:33 +00:00
|
|
|
import PATHS from "router/paths";
|
|
|
|
|
|
|
|
|
|
import HeaderCell from "components/TableContainer/DataTable/HeaderCell";
|
|
|
|
|
import TextCell from "components/TableContainer/DataTable/TextCell";
|
|
|
|
|
import ViewAllHostsLink from "components/ViewAllHostsLink";
|
2024-05-09 21:44:50 +00:00
|
|
|
import SoftwareNameCell from "components/TableContainer/DataTable/SoftwareNameCell";
|
|
|
|
|
|
2024-01-25 18:03:44 +00:00
|
|
|
import VulnerabilitiesCell from "../../components/VulnerabilitiesCell";
|
2023-12-12 21:03:33 +00:00
|
|
|
|
|
|
|
|
// NOTE: cellProps come from react-table
|
|
|
|
|
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
|
|
|
|
|
|
2024-03-13 19:09:16 +00:00
|
|
|
type ISoftwareVersionsTableConfig = Column<ISoftwareVersion>;
|
|
|
|
|
type ITableStringCellProps = IStringCellProps<ISoftwareVersion>;
|
|
|
|
|
type IVulnerabilitiesCellProps = CellProps<
|
|
|
|
|
ISoftwareVersion,
|
|
|
|
|
ISoftwareVulnerability[] | null
|
|
|
|
|
>;
|
|
|
|
|
type IHostCountCellProps = CellProps<ISoftwareVersion, number | undefined>;
|
2023-12-12 21:03:33 +00:00
|
|
|
|
2024-03-13 19:09:16 +00:00
|
|
|
type ITableHeaderProps = IHeaderProps<ISoftwareVersion>;
|
2023-12-12 21:03:33 +00:00
|
|
|
|
|
|
|
|
const generateTableHeaders = (
|
|
|
|
|
router: InjectedRouter,
|
|
|
|
|
teamId?: number
|
2024-03-13 19:09:16 +00:00
|
|
|
): ISoftwareVersionsTableConfig[] => {
|
|
|
|
|
const softwareTableHeaders: ISoftwareVersionsTableConfig[] = [
|
2023-12-12 21:03:33 +00:00
|
|
|
{
|
2024-03-13 19:09:16 +00:00
|
|
|
Header: (cellProps: ITableHeaderProps) => (
|
|
|
|
|
<HeaderCell value="Name" isSortedDesc={cellProps.column.isSortedDesc} />
|
2023-12-12 21:03:33 +00:00
|
|
|
),
|
|
|
|
|
disableSortBy: false,
|
|
|
|
|
accessor: "name",
|
2024-03-13 19:09:16 +00:00
|
|
|
Cell: (cellProps: ITableStringCellProps) => {
|
2023-12-12 21:03:33 +00:00
|
|
|
const { id, name, source } = cellProps.row.original;
|
|
|
|
|
|
2024-02-14 17:58:40 +00:00
|
|
|
const teamQueryParam = buildQueryStringFromParams({
|
|
|
|
|
team_id: teamId,
|
|
|
|
|
});
|
|
|
|
|
const softwareVersionDetailsPath = `${PATHS.SOFTWARE_VERSION_DETAILS(
|
|
|
|
|
id.toString()
|
|
|
|
|
)}?${teamQueryParam}`;
|
|
|
|
|
|
2023-12-12 21:03:33 +00:00
|
|
|
return (
|
2024-05-09 21:44:50 +00:00
|
|
|
<SoftwareNameCell
|
|
|
|
|
name={name}
|
|
|
|
|
source={source}
|
2024-02-14 17:58:40 +00:00
|
|
|
path={softwareVersionDetailsPath}
|
2024-05-09 21:44:50 +00:00
|
|
|
router={router}
|
2023-12-12 21:03:33 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
sortType: "caseInsensitive",
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-07-30 17:14:25 +00:00
|
|
|
Header: "Version",
|
2023-12-12 21:03:33 +00:00
|
|
|
disableSortBy: true,
|
2024-07-30 17:14:25 +00:00
|
|
|
accessor: "version",
|
2024-03-13 19:09:16 +00:00
|
|
|
Cell: (cellProps: ITableStringCellProps) => (
|
2024-07-30 17:14:25 +00:00
|
|
|
<TextCell value={cellProps.cell.value} />
|
2023-12-12 21:03:33 +00:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-07-30 17:14:25 +00:00
|
|
|
Header: "Type",
|
2023-12-12 21:03:33 +00:00
|
|
|
disableSortBy: true,
|
2024-07-30 17:14:25 +00:00
|
|
|
accessor: "source",
|
2024-03-13 19:09:16 +00:00
|
|
|
Cell: (cellProps: ITableStringCellProps) => (
|
2024-07-30 17:14:25 +00:00
|
|
|
<TextCell value={formatSoftwareType(cellProps.row.original)} />
|
2023-12-12 21:03:33 +00:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Header: "Vulnerabilities",
|
|
|
|
|
disableSortBy: true,
|
|
|
|
|
accessor: "vulnerabilities",
|
2024-07-30 17:14:25 +00:00
|
|
|
Cell: (cellProps: IVulnerabilitiesCellProps) => {
|
|
|
|
|
if (
|
|
|
|
|
["ipados_apps", "ios_apps"].includes(cellProps.row.original.source)
|
|
|
|
|
) {
|
|
|
|
|
return <TextCell value="Not supported" grey />;
|
|
|
|
|
}
|
|
|
|
|
return <VulnerabilitiesCell vulnerabilities={cellProps.cell.value} />;
|
|
|
|
|
},
|
2023-12-12 21:03:33 +00:00
|
|
|
},
|
|
|
|
|
{
|
2024-03-13 19:09:16 +00:00
|
|
|
Header: (cellProps: ITableHeaderProps) => (
|
2023-12-12 21:03:33 +00:00
|
|
|
<HeaderCell
|
2024-03-13 19:09:16 +00:00
|
|
|
value="Hosts"
|
2023-12-12 21:03:33 +00:00
|
|
|
disableSortBy={false}
|
|
|
|
|
isSortedDesc={cellProps.column.isSortedDesc}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
disableSortBy: false,
|
|
|
|
|
accessor: "hosts_count",
|
2024-03-13 19:09:16 +00:00
|
|
|
Cell: (cellProps: IHostCountCellProps) => (
|
2024-02-08 13:54:00 +00:00
|
|
|
<TextCell value={cellProps.cell.value} />
|
2023-12-12 21:03:33 +00:00
|
|
|
),
|
|
|
|
|
},
|
2024-02-08 13:54:00 +00:00
|
|
|
{
|
|
|
|
|
Header: "",
|
2024-03-14 15:57:07 +00:00
|
|
|
id: "view-all-hosts",
|
2024-02-08 13:54:00 +00:00
|
|
|
disableSortBy: true,
|
2024-03-13 19:09:16 +00:00
|
|
|
Cell: (cellProps: ITableStringCellProps) => {
|
2024-02-08 13:54:00 +00:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{cellProps.row.original && (
|
|
|
|
|
<ViewAllHostsLink
|
|
|
|
|
queryParams={{
|
|
|
|
|
software_version_id: cellProps.row.original.id,
|
|
|
|
|
team_id: teamId, // TODO: do we need team id here?
|
|
|
|
|
}}
|
|
|
|
|
className="software-link"
|
|
|
|
|
rowHover
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-12 21:03:33 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return softwareTableHeaders;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default generateTableHeaders;
|