fleet/frontend/components/TableContainer/DataTable/StatusCell/StatusCell.tsx
Jacob Shandling a568c28124
UI: Add {on|off}line status tooltips and refactor HostSummary to use StatusCell (#8750)
Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
Co-authored-by: Luke Heath <luke@fleetdm.com>
2022-11-22 14:15:17 -08:00

54 lines
1.2 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import ReactTooltip from "react-tooltip";
interface IStatusCellProps {
value: string;
tooltip?: {
id: number;
tooltipText: string;
};
}
const generateClassTag = (rawValue: string): string => {
if (rawValue === "---") {
return "indeterminate";
}
return rawValue.replace(" ", "-").toLowerCase();
};
const StatusCell = ({ value, tooltip }: IStatusCellProps): JSX.Element => {
const classTag = generateClassTag(value);
const statusClassName = classnames(
"data-table__status",
`data-table__status--${classTag}`,
`status--${classTag}`
);
const cellContent = tooltip ? (
<>
<span
className="host-status tooltip tooltip__tooltip-icon"
data-tip
data-for={`status-${tooltip.id}`}
data-tip-disable={false}
>
{value}
</span>
<ReactTooltip
className="status-tooltip"
place="top"
type="dark"
effect="solid"
id={`status-${tooltip.id}`}
backgroundColor="#3e4771"
>
{tooltip.tooltipText}
</ReactTooltip>
</>
) : (
<>{value}</>
);
return <span className={statusClassName}>{cellContent}</span>;
};
export default StatusCell;