fleet/frontend/pages/SoftwarePage/components/EmptySoftwareTable/EmptySoftwareTable.tsx
Jahziel Villasana-Espinoza 57fa67c8c0
fix: filter by vulnerable software (#20241)
> Related issue: #20050

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-07-09 10:02:49 -04:00

85 lines
2.5 KiB
TypeScript

// This component is used on DashboardPage.tsx > Software.tsx,
// Host Details / Device User > Software.tsx, and SoftwarePage.tsx
import React from "react";
import CustomLink from "components/CustomLink";
import EmptyTable from "components/EmptyTable";
import { IEmptyTableProps } from "interfaces/empty_table";
import { ISoftwareDropdownFilterVal } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/helpers";
export interface IEmptySoftwareTableProps {
softwareFilter?: ISoftwareDropdownFilterVal;
/** tableName is displayed in the search empty state */
tableName?: string;
isSoftwareDisabled?: boolean;
/** isNotDetectingSoftware renders empty states when no search string is present */
isNotDetectingSoftware?: boolean;
/** isCollectingSoftware is only used on the Dashboard page with a TODO to revisit */
isCollectingSoftware?: boolean;
isFilterVulnerable?: boolean;
}
const generateTypeText = (
tableName: string,
softwareFilter?: ISoftwareDropdownFilterVal
) => {
if (softwareFilter === "installableSoftware") {
return "installable software";
}
if (softwareFilter === "vulnerableSoftware") {
return "vulnerable software";
}
return tableName;
};
const EmptySoftwareTable = ({
softwareFilter = "allSoftware",
tableName = "software",
isSoftwareDisabled,
isNotDetectingSoftware,
isCollectingSoftware,
isFilterVulnerable,
}: IEmptySoftwareTableProps): JSX.Element => {
const softwareTypeText = generateTypeText(tableName, softwareFilter);
const emptySoftware: IEmptyTableProps = {
header: "No items match the current search criteria",
info: `Expecting to see ${softwareTypeText}? Check back later.`,
};
if (isNotDetectingSoftware && softwareFilter === "allSoftware") {
emptySoftware.header = "No software detected";
}
if (isCollectingSoftware) {
emptySoftware.header = "No software detected";
emptySoftware.info =
"This report is updated every hour to protect the performance of your devices.";
}
if (isSoftwareDisabled) {
emptySoftware.header = "Software inventory disabled";
emptySoftware.info = (
<>
Users with the admin role can{" "}
<CustomLink
url="https://fleetdm.com/docs/using-fleet/vulnerability-processing#configuration"
text="turn on software inventory"
newTab
/>
.
</>
);
}
return (
<EmptyTable
graphicName="empty-software"
header={emptySoftware.header}
info={emptySoftware.info}
/>
);
};
export default EmptySoftwareTable;