fleet/frontend/pages/SoftwarePage/components/EmptySoftwareTable/EmptySoftwareTable.tsx
jacobshandling 50ba783a25
UI – Update empty Software versions table when installable software present (#21118)
## Addresses 1a of #21053 
<img width="1498" alt="Screenshot 2024-08-06 at 7 56 38 PM"
src="https://github.com/user-attachments/assets/d2e97e07-acd7-4f0b-a609-b8b9546a742d">

- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-08-07 09:26:39 -07:00

90 lines
2.8 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;
/** noSearchQuery is true when there is no search string filtering the results */
noSearchQuery?: boolean;
/** isCollectingSoftware is only used on the Dashboard page with a TODO to revisit */
isCollectingSoftware?: boolean;
/** true if the team has any software installers or VPP apps available to install on hosts */
installableSoftwareExists?: 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,
noSearchQuery,
isCollectingSoftware,
installableSoftwareExists,
}: 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 (noSearchQuery && softwareFilter === "allSoftware") {
emptySoftware.header = "No software detected";
}
if (softwareFilter === "allSoftware" && installableSoftwareExists) {
emptySoftware.header = "No software detected";
emptySoftware.info = "Install software on your hosts to see versions.";
}
if (isCollectingSoftware) {
emptySoftware.header = "No software detected";
emptySoftware.info = `Expecting to see ${softwareTypeText}? Check back later.`;
}
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;