2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import classnames from "classnames";
|
2022-11-22 22:15:17 +00:00
|
|
|
import ReactTooltip from "react-tooltip";
|
2021-02-11 16:22:22 +00:00
|
|
|
|
2022-12-13 18:04:07 +00:00
|
|
|
interface IStatusIndicatorProps {
|
2021-03-03 16:51:39 +00:00
|
|
|
value: string;
|
2022-11-22 22:15:17 +00:00
|
|
|
tooltip?: {
|
|
|
|
|
id: number;
|
|
|
|
|
tooltipText: string;
|
|
|
|
|
};
|
2021-03-03 16:51:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-14 09:20:56 +00:00
|
|
|
const generateClassTag = (rawValue: string): string => {
|
2022-04-07 19:12:38 +00:00
|
|
|
if (rawValue === "---") {
|
|
|
|
|
return "indeterminate";
|
|
|
|
|
}
|
2021-04-14 16:52:15 +00:00
|
|
|
return rawValue.replace(" ", "-").toLowerCase();
|
2021-04-14 09:20:56 +00:00
|
|
|
};
|
|
|
|
|
|
2022-12-13 18:04:07 +00:00
|
|
|
const StatusIndicator = ({
|
|
|
|
|
value,
|
|
|
|
|
tooltip,
|
|
|
|
|
}: IStatusIndicatorProps): JSX.Element => {
|
2022-11-22 22:15:17 +00:00
|
|
|
const classTag = generateClassTag(value);
|
2021-02-11 16:22:22 +00:00
|
|
|
const statusClassName = classnames(
|
2022-12-13 18:04:07 +00:00
|
|
|
"status-indicator",
|
|
|
|
|
`status-indicator--${classTag}`,
|
2022-11-22 22:15:17 +00:00
|
|
|
`status--${classTag}`
|
2021-02-11 16:22:22 +00:00
|
|
|
);
|
2022-12-13 18:04:07 +00:00
|
|
|
const indicatorContent = tooltip ? (
|
2022-11-22 22:15:17 +00:00
|
|
|
<>
|
|
|
|
|
<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}</>
|
|
|
|
|
);
|
2022-12-13 18:04:07 +00:00
|
|
|
return <span className={statusClassName}>{indicatorContent}</span>;
|
2021-02-11 16:22:22 +00:00
|
|
|
};
|
|
|
|
|
|
2022-12-13 18:04:07 +00:00
|
|
|
export default StatusIndicator;
|