2021-09-01 22:08:20 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import classnames from "classnames";
|
2022-12-07 17:59:38 +00:00
|
|
|
import { uniqueId } from "lodash";
|
2021-09-01 22:08:20 +00:00
|
|
|
|
|
|
|
|
import ReactTooltip from "react-tooltip";
|
2023-12-09 00:54:24 +00:00
|
|
|
import { COLORS } from "styles/var/colors";
|
2021-09-01 22:08:20 +00:00
|
|
|
|
2026-01-02 13:06:12 +00:00
|
|
|
import { getPerformanceImpactIndicatorTooltip } from "utilities/helpers";
|
|
|
|
|
import {
|
|
|
|
|
isPerformanceImpactIndicator,
|
|
|
|
|
PerformanceImpactIndicatorValue,
|
|
|
|
|
} from "interfaces/schedulable_query";
|
|
|
|
|
|
2023-12-14 19:49:56 +00:00
|
|
|
interface IPerformanceImpactCellValue {
|
|
|
|
|
indicator: string;
|
|
|
|
|
id?: number;
|
|
|
|
|
}
|
|
|
|
|
interface IPerformanceImpactCellProps {
|
|
|
|
|
value: IPerformanceImpactCellValue;
|
|
|
|
|
isHostSpecific?: boolean;
|
2021-09-29 04:04:58 +00:00
|
|
|
customIdPrefix?: string;
|
2021-09-01 22:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const generateClassTag = (rawValue: string): string => {
|
|
|
|
|
return rawValue.replace(" ", "-").toLowerCase();
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 19:49:56 +00:00
|
|
|
const baseClass = "performance-impact-cell";
|
|
|
|
|
|
|
|
|
|
const PerformanceImpactCell = ({
|
2023-07-19 18:02:53 +00:00
|
|
|
value,
|
2023-12-14 19:49:56 +00:00
|
|
|
isHostSpecific = false,
|
2023-07-19 18:02:53 +00:00
|
|
|
customIdPrefix,
|
2023-12-14 19:49:56 +00:00
|
|
|
}: IPerformanceImpactCellProps): JSX.Element => {
|
2022-12-07 17:59:38 +00:00
|
|
|
const { indicator, id } = value;
|
2021-09-01 22:08:20 +00:00
|
|
|
const pillClassName = classnames(
|
|
|
|
|
"data-table__pill",
|
2022-12-07 17:59:38 +00:00
|
|
|
`data-table__pill--${generateClassTag(indicator || "")}`,
|
2022-07-15 19:10:35 +00:00
|
|
|
"tooltip"
|
2021-09-01 22:08:20 +00:00
|
|
|
);
|
|
|
|
|
|
2023-12-14 19:49:56 +00:00
|
|
|
const disableTooltip = ![
|
|
|
|
|
"Minimal",
|
|
|
|
|
"Considerable",
|
|
|
|
|
"Excessive",
|
|
|
|
|
"Undetermined",
|
|
|
|
|
].includes(indicator);
|
2021-09-01 22:08:20 +00:00
|
|
|
|
2022-12-07 17:59:38 +00:00
|
|
|
const tooltipId = uniqueId();
|
2021-09-01 22:08:20 +00:00
|
|
|
|
2026-01-02 13:06:12 +00:00
|
|
|
const indicatorValue = isPerformanceImpactIndicator(indicator)
|
|
|
|
|
? indicator
|
|
|
|
|
: PerformanceImpactIndicatorValue.UNDETERMINED;
|
|
|
|
|
|
2021-09-01 22:08:20 +00:00
|
|
|
return (
|
2023-12-14 19:49:56 +00:00
|
|
|
<span className={`${baseClass}`}>
|
2021-09-29 04:04:58 +00:00
|
|
|
<span
|
|
|
|
|
data-tip
|
2022-12-07 17:59:38 +00:00
|
|
|
data-for={`${customIdPrefix || "pill"}__${id?.toString() || tooltipId}`}
|
2023-12-14 19:49:56 +00:00
|
|
|
data-tip-disable={disableTooltip}
|
2021-09-29 04:04:58 +00:00
|
|
|
>
|
2026-01-02 13:06:12 +00:00
|
|
|
<span className={pillClassName}>{indicatorValue}</span>
|
2021-09-29 04:04:58 +00:00
|
|
|
</span>
|
2021-09-01 22:08:20 +00:00
|
|
|
<ReactTooltip
|
2023-02-21 14:16:38 +00:00
|
|
|
place="top"
|
2021-09-01 22:08:20 +00:00
|
|
|
effect="solid"
|
2023-12-09 00:54:24 +00:00
|
|
|
backgroundColor={COLORS["tooltip-bg"]}
|
2022-12-07 17:59:38 +00:00
|
|
|
id={`${customIdPrefix || "pill"}__${id?.toString() || tooltipId}`}
|
2021-09-01 22:08:20 +00:00
|
|
|
data-html
|
|
|
|
|
>
|
2022-12-07 17:59:38 +00:00
|
|
|
<span
|
|
|
|
|
className={`tooltip ${generateClassTag(
|
2026-01-02 13:06:12 +00:00
|
|
|
indicatorValue || ""
|
2022-12-07 17:59:38 +00:00
|
|
|
)}__tooltip-text`}
|
|
|
|
|
>
|
2026-01-02 13:06:12 +00:00
|
|
|
{getPerformanceImpactIndicatorTooltip(indicatorValue, isHostSpecific)}
|
2021-09-01 22:08:20 +00:00
|
|
|
</span>
|
|
|
|
|
</ReactTooltip>
|
2023-12-14 19:49:56 +00:00
|
|
|
</span>
|
2021-09-01 22:08:20 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 19:49:56 +00:00
|
|
|
export default PerformanceImpactCell;
|