import React from "react"; import { InjectedRouter } from "react-router"; import ReactTooltip from "react-tooltip"; import { uniqueId } from "lodash"; import Icon from "components/Icon"; import { IconNames } from "components/icons"; import SoftwareIcon from "pages/SoftwarePage/components/icons/SoftwareIcon"; import LinkCell from "../LinkCell"; const baseClass = "software-name-cell"; type InstallType = | "manual" | "selfService" | "automatic" | "automaticSelfService"; interface installIconConfig { iconName: IconNames; tooltip: JSX.Element; } const installIconMap: Record = { manual: { iconName: "install", tooltip: <>Software can be installed on Host details page., }, selfService: { iconName: "user", tooltip: ( <> End users can install from Fleet Desktop {">"} Self-service. ), }, automatic: { iconName: "refresh", tooltip: <>Software will be automatically installed on each host., }, automaticSelfService: { iconName: "automatic-self-service", tooltip: ( <> Software will be automatically installed on each host. End users can reinstall from Fleet Desktop {">"} Self-service. ), }, }; interface IInstallIconWithTooltipProps { isSelfService: boolean; installType?: "manual" | "automatic"; } const InstallIconWithTooltip = ({ isSelfService, installType, }: IInstallIconWithTooltipProps) => { let iconType: InstallType = "manual"; if (installType === "automatic") { iconType = isSelfService ? "automaticSelfService" : "automatic"; } else if (isSelfService) { iconType = "selfService"; } const tooltipId = uniqueId(); return (
{installIconMap[iconType].tooltip}
); }; interface ISoftwareNameCellProps { name?: string; source?: string; /** pass in a `path` that this cell will link to */ path?: string; router?: InjectedRouter; hasPackage?: boolean; isSelfService?: boolean; installType?: "manual" | "automatic"; iconUrl?: string; } const SoftwareNameCell = ({ name, source, path, router, hasPackage = false, isSelfService = false, installType, iconUrl, }: ISoftwareNameCellProps) => { // NO path or router means it's not clickable. return // a non-clickable cell early if (!router || !path) { return (
{name}
); } const onClickSoftware = (e: React.MouseEvent) => { // Allows for button to be clickable in a clickable row e.stopPropagation(); router.push(path); }; return ( {name} {hasPackage && ( )} } /> ); }; export default SoftwareNameCell;