fleet/frontend/pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTitlesTableConfig.tsx

198 lines
5.9 KiB
TypeScript
Raw Normal View History

import React from "react";
2024-03-13 19:09:16 +00:00
import { CellProps, Column } from "react-table";
import { InjectedRouter } from "react-router";
import {
ISoftwareTitle,
formatSoftwareType,
isIpadOrIphoneSoftwareSource,
} from "interfaces/software";
import PATHS from "router/paths";
2024-03-13 19:09:16 +00:00
import { buildQueryStringFromParams } from "utilities/url";
2024-03-13 19:09:16 +00:00
import { IHeaderProps, IStringCellProps } from "interfaces/datatable_config";
import HeaderCell from "components/TableContainer/DataTable/HeaderCell";
import TextCell from "components/TableContainer/DataTable/TextCell";
import ViewAllHostsLink from "components/ViewAllHostsLink";
import SoftwareNameCell from "components/TableContainer/DataTable/SoftwareNameCell";
import VersionCell from "../../components/VersionCell";
import VulnerabilitiesCell from "../../components/VulnerabilitiesCell";
// NOTE: cellProps come from react-table
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
type ISoftwareTitlesTableConfig = Column<ISoftwareTitle>;
type ITableStringCellProps = IStringCellProps<ISoftwareTitle>;
type IVersionsCellProps = CellProps<ISoftwareTitle, ISoftwareTitle["versions"]>;
2024-03-13 19:09:16 +00:00
type IVulnerabilitiesCellProps = IVersionsCellProps;
type IHostCountCellProps = CellProps<
ISoftwareTitle,
ISoftwareTitle["hosts_count"]
2024-03-13 19:09:16 +00:00
>;
type IViewAllHostsLinkProps = CellProps<ISoftwareTitle>;
type ITableHeaderProps = IHeaderProps<ISoftwareTitle>;
export const getVulnerabilities = <
T extends { vulnerabilities: string[] | null }
>(
versions: T[]
) => {
if (!versions) {
return [];
}
const vulnerabilities = versions.reduce((acc: string[], currentVersion) => {
if (
currentVersion.vulnerabilities &&
currentVersion.vulnerabilities.length !== 0
) {
acc.push(...currentVersion.vulnerabilities);
}
return acc;
}, []);
return vulnerabilities;
};
/**
* Gets the data needed to render the software name cell.
*/
const getSoftwareNameCellData = (
softwareTitle: ISoftwareTitle,
teamId?: number
) => {
const teamQueryParam = buildQueryStringFromParams({ team_id: teamId });
const softwareTitleDetailsPath = `${PATHS.SOFTWARE_TITLE_DETAILS(
softwareTitle.id.toString()
)}?${teamQueryParam}`;
const { software_package, app_store_app } = softwareTitle;
let hasPackage = false;
let isSelfService = false;
let iconUrl: string | null = null;
if (software_package) {
hasPackage = true;
isSelfService = software_package.self_service;
} else if (app_store_app) {
hasPackage = true;
isSelfService = app_store_app.self_service;
iconUrl = app_store_app.icon_url;
}
const isAllTeams = teamId === undefined;
return {
name: softwareTitle.name,
source: softwareTitle.source,
path: softwareTitleDetailsPath,
hasPackage: hasPackage && !isAllTeams,
isSelfService,
iconUrl,
};
};
const generateTableHeaders = (
router: InjectedRouter,
teamId?: number
2024-03-13 19:09:16 +00:00
): ISoftwareTitlesTableConfig[] => {
const softwareTableHeaders: ISoftwareTitlesTableConfig[] = [
{
2024-03-13 19:09:16 +00:00
Header: (cellProps: ITableHeaderProps) => (
<HeaderCell value="Name" isSortedDesc={cellProps.column.isSortedDesc} />
),
disableSortBy: false,
accessor: "name",
2024-03-13 19:09:16 +00:00
Cell: (cellProps: ITableStringCellProps) => {
const nameCellData = getSoftwareNameCellData(
cellProps.row.original,
teamId
);
return (
<SoftwareNameCell
name={nameCellData.name}
source={nameCellData.source}
path={nameCellData.path}
router={router}
hasPackage={nameCellData.hasPackage}
isSelfService={nameCellData.isSelfService}
iconUrl={nameCellData.iconUrl ?? undefined}
/>
);
},
sortType: "caseInsensitive",
},
{
Header: "Version",
disableSortBy: true,
accessor: "versions",
Cell: (cellProps: IVersionsCellProps) => (
<VersionCell versions={cellProps.cell.value} />
),
},
UI – Add VPP features for iPadOS and iOS (#20755) ## Addresses #20467 – part 2 ### Aggregate software: #### Software titles <img width="1616" alt="sw-titles-updated" src="https://github.com/user-attachments/assets/0b9922c7-e36e-4d2f-b204-95c3cdf9b602"> #### Software versions <img width="1616" alt="Screenshot 2024-07-29 at 6 14 21 PM" src="https://github.com/user-attachments/assets/5a097700-cd6c-45b1-a21f-9d76a733f0ae"> #### Host software <img width="1616" alt="Screenshot 2024-07-29 at 6 23 01 PM" src="https://github.com/user-attachments/assets/84e18695-f47a-4022-bd53-7f5d37ce452a"> ### Add software modal (VPP) _screenshots use mocked data - UI is flexible enough to display cleanly before and after backend is in place:_ <img width="1339" alt="happy" src="https://github.com/user-attachments/assets/8900aa93-316c-4a09-8e5a-1a1e45b0c458"> #### No apps: <img width="1572" alt="Screenshot 2024-07-29 at 6 35 03 PM" src="https://github.com/user-attachments/assets/466b9b6c-4d3d-49dd-94a9-94e395d89cb7"> #### Not enabled: <img width="1572" alt="Screenshot 2024-07-29 at 6 37 45 PM" src="https://github.com/user-attachments/assets/9bcfd480-8741-4d95-ba3b-550dee4dc673"> #### Error: <img width="1572" alt="Screenshot 2024-07-29 at 6 39 39 PM" src="https://github.com/user-attachments/assets/e944dd40-676e-4aba-9cd9-49ff319bf402"> ### Vuln support – Not supported for now: _see above screenshots for `list` endpoints_ #### Software title detail <img width="1616" alt="Screenshot 2024-07-29 at 6 47 29 PM" src="https://github.com/user-attachments/assets/2e30fd0a-21e4-4d19-bf9b-71a994bfd0e7"> #### Software version and OS detail: <img width="1616" alt="Screenshot 2024-07-29 at 6 48 28 PM" src="https://github.com/user-attachments/assets/e8fec769-ba97-4b6b-b10c-9bb4c973c732"> <img width="1616" alt="Screenshot 2024-07-29 at 6 50 25 PM" src="https://github.com/user-attachments/assets/0ac15727-e0cb-447c-8758-c58b79656d1a"> - [x] Changes file added for user-visible changes in `changes/`, - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-07-30 17:14:25 +00:00
{
Header: "Type",
disableSortBy: true,
accessor: "source",
Cell: (cellProps: ITableStringCellProps) => (
<TextCell value={formatSoftwareType(cellProps.row.original)} />
),
},
// the "vulnerabilities" accessor is used but the data is actually coming
// from the version attribute. We do this as we already have a "versions"
// attribute used for the "Version" column and we cannot reuse. This is a
// limitation of react-table.
// With the versions data, we can sum up the vulnerabilities to get the
// total number of vulnerabilities for the software title
{
Header: "Vulnerabilities",
disableSortBy: true,
2024-03-13 19:09:16 +00:00
Cell: (cellProps: IVulnerabilitiesCellProps) => {
if (isIpadOrIphoneSoftwareSource(cellProps.row.original.source)) {
UI – Add VPP features for iPadOS and iOS (#20755) ## Addresses #20467 – part 2 ### Aggregate software: #### Software titles <img width="1616" alt="sw-titles-updated" src="https://github.com/user-attachments/assets/0b9922c7-e36e-4d2f-b204-95c3cdf9b602"> #### Software versions <img width="1616" alt="Screenshot 2024-07-29 at 6 14 21 PM" src="https://github.com/user-attachments/assets/5a097700-cd6c-45b1-a21f-9d76a733f0ae"> #### Host software <img width="1616" alt="Screenshot 2024-07-29 at 6 23 01 PM" src="https://github.com/user-attachments/assets/84e18695-f47a-4022-bd53-7f5d37ce452a"> ### Add software modal (VPP) _screenshots use mocked data - UI is flexible enough to display cleanly before and after backend is in place:_ <img width="1339" alt="happy" src="https://github.com/user-attachments/assets/8900aa93-316c-4a09-8e5a-1a1e45b0c458"> #### No apps: <img width="1572" alt="Screenshot 2024-07-29 at 6 35 03 PM" src="https://github.com/user-attachments/assets/466b9b6c-4d3d-49dd-94a9-94e395d89cb7"> #### Not enabled: <img width="1572" alt="Screenshot 2024-07-29 at 6 37 45 PM" src="https://github.com/user-attachments/assets/9bcfd480-8741-4d95-ba3b-550dee4dc673"> #### Error: <img width="1572" alt="Screenshot 2024-07-29 at 6 39 39 PM" src="https://github.com/user-attachments/assets/e944dd40-676e-4aba-9cd9-49ff319bf402"> ### Vuln support – Not supported for now: _see above screenshots for `list` endpoints_ #### Software title detail <img width="1616" alt="Screenshot 2024-07-29 at 6 47 29 PM" src="https://github.com/user-attachments/assets/2e30fd0a-21e4-4d19-bf9b-71a994bfd0e7"> #### Software version and OS detail: <img width="1616" alt="Screenshot 2024-07-29 at 6 48 28 PM" src="https://github.com/user-attachments/assets/e8fec769-ba97-4b6b-b10c-9bb4c973c732"> <img width="1616" alt="Screenshot 2024-07-29 at 6 50 25 PM" src="https://github.com/user-attachments/assets/0ac15727-e0cb-447c-8758-c58b79656d1a"> - [x] Changes file added for user-visible changes in `changes/`, - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-07-30 17:14:25 +00:00
return <TextCell value="Not supported" grey />;
}
const vulnerabilities = getVulnerabilities(
cellProps.row.original.versions ?? []
);
return <VulnerabilitiesCell vulnerabilities={vulnerabilities} />;
},
},
{
2024-03-13 19:09:16 +00:00
Header: (cellProps: ITableHeaderProps) => (
<HeaderCell
2024-03-13 19:09:16 +00:00
value="Hosts"
disableSortBy={false}
isSortedDesc={cellProps.column.isSortedDesc}
/>
),
disableSortBy: false,
accessor: "hosts_count",
2024-03-13 19:09:16 +00:00
Cell: (cellProps: IHostCountCellProps) => (
<TextCell value={cellProps.cell.value} />
),
},
{
Header: "",
id: "view-all-hosts",
disableSortBy: true,
2024-03-13 19:09:16 +00:00
Cell: (cellProps: IViewAllHostsLinkProps) => {
return (
<ViewAllHostsLink
queryParams={{
software_title_id: cellProps.row.original.id,
team_id: teamId, // TODO: do we need team id here?
}}
className="software-link"
rowHover
/>
);
},
},
];
return softwareTableHeaders;
};
export default generateTableHeaders;