import React from "react"; import { Column } from "react-table"; import { InjectedRouter } from "react-router"; import { buildQueryStringFromParams } from "utilities/url"; import { formatSoftwareType, ISoftwareVersion, ISoftwareVulnerability, } from "interfaces/software"; import PATHS from "router/paths"; import HeaderCell from "components/TableContainer/DataTable/HeaderCell"; import TextCell from "components/TableContainer/DataTable/TextCell"; import LinkCell from "components/TableContainer/DataTable/LinkCell/LinkCell"; import ViewAllHostsLink from "components/ViewAllHostsLink"; import VulnerabilitiesCell from "../../components/VulnerabilitiesCell"; import SoftwareIcon from "../../components/icons/SoftwareIcon"; // NOTE: cellProps come from react-table // more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties interface ICellProps { cell: { value: number | string | ISoftwareVulnerability[]; }; row: { original: ISoftwareVersion; }; } interface IStringCellProps extends ICellProps { cell: { value: string; }; } interface IVersionCellProps extends ICellProps { cell: { value: string; }; } interface INumberCellProps extends ICellProps { cell: { value: number; }; } interface IVulnCellProps extends ICellProps { cell: { value: ISoftwareVulnerability[]; }; } interface IHeaderProps { column: { title: string; isSortedDesc: boolean; }; } const generateTableHeaders = ( router: InjectedRouter, teamId?: number ): Column[] => { const softwareTableHeaders = [ { title: "Name", Header: (cellProps: IHeaderProps): JSX.Element => ( ), disableSortBy: false, accessor: "name", Cell: (cellProps: IStringCellProps): JSX.Element => { const { id, name, source } = cellProps.row.original; const teamQueryParam = buildQueryStringFromParams({ team_id: teamId, }); const softwareVersionDetailsPath = `${PATHS.SOFTWARE_VERSION_DETAILS( id.toString() )}?${teamQueryParam}`; const onClickSoftware = (e: React.MouseEvent) => { // Allows for button to be clickable in a clickable row e.stopPropagation(); router?.push(softwareVersionDetailsPath); }; return ( {name} } /> ); }, sortType: "caseInsensitive", }, { title: "Version", Header: "Version", disableSortBy: true, accessor: "version", Cell: (cellProps: IVersionCellProps): JSX.Element => ( ), }, { title: "Type", Header: "Type", disableSortBy: true, accessor: "source", Cell: (cellProps: ICellProps): JSX.Element => ( ), }, { title: "Vulnerabilities", Header: "Vulnerabilities", disableSortBy: true, accessor: "vulnerabilities", Cell: (cellProps: IVulnCellProps): JSX.Element => ( ), }, { title: "Hosts", Header: (cellProps: IHeaderProps): JSX.Element => ( ), disableSortBy: false, accessor: "hosts_count", Cell: (cellProps: INumberCellProps): JSX.Element => ( ), }, { title: "", Header: "", accessor: "linkToFilteredHosts", disableSortBy: true, Cell: (cellProps: ICellProps) => { return ( <> {cellProps.row.original && ( )} ); }, }, ]; return softwareTableHeaders; }; export default generateTableHeaders;