fleet/frontend/components/StatusIndicator/StatusIndicator.tsx
Jacob Shandling 53f57c44db
UI - Queries page updates, pt.1 (#12784)
## Addresses #12636 – follow-up work for PR #12713

- Update Platforms column to render the user-selected platforms for a
query if any, otherwise those that are compatible
<img width="686" alt="Screenshot 2023-07-14 at 6 03 06 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/abd1f079-bdfe-45be-b1dd-58eb903672ef">

  - Clean up typing and names around this column 
- Encapsulate logic for query automations column cells into new
QueryAutomationsStatusIndicator component
  - Increase modularity and decrease coupling of StatusIndicator
- Cleanly handle overflowing queries table due to very long query name
<img width="512" alt="Screenshot 2023-07-14 at 6 07 20 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/6e970038-0aac-4f71-b21d-ececfa66b94f">

- Small copy and layout fixes

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

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-07-17 14:09:12 -07:00

73 lines
1.9 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import ReactTooltip from "react-tooltip";
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
import { uniqueId } from "lodash";
import { COLORS } from "styles/var/colors";
interface IStatusIndicatorProps {
value: string;
tooltip?: {
tooltipText: string | JSX.Element;
position?: "top" | "bottom";
};
customIndicatorType?: string;
}
const generateIndicatorStateClassTag = (
rawValue: string,
customIndicatorType?: string
): string => {
if (rawValue === DEFAULT_EMPTY_CELL_VALUE) {
return "indeterminate";
}
const prefix = customIndicatorType ? `${customIndicatorType}-` : "";
return `${prefix}${rawValue.replace(" ", "-").toLowerCase()}`;
};
const StatusIndicator = ({
value,
tooltip,
customIndicatorType,
}: IStatusIndicatorProps): JSX.Element => {
const indicatorStateClassTag = generateIndicatorStateClassTag(
value,
customIndicatorType
);
const indicatorClassNames = classnames(
"status-indicator",
`status-indicator--${indicatorStateClassTag}`,
`status--${indicatorStateClassTag}`
);
let indicatorContent;
if (tooltip) {
const tooltipId = uniqueId();
indicatorContent = (
<>
<span
className="host-status tooltip tooltip__tooltip-icon"
data-tip
data-for={`status-${tooltipId}`}
data-tip-disable={false}
>
{value}
</span>
<ReactTooltip
className="status-tooltip"
place={tooltip?.position ? tooltip.position : "top"}
type="dark"
effect="solid"
id={`status-${tooltipId}`}
backgroundColor={COLORS["tooltip-bg"]}
>
{tooltip.tooltipText}
</ReactTooltip>
</>
);
} else {
indicatorContent = <>{value}</>;
}
return <span className={indicatorClassNames}>{indicatorContent}</span>;
};
export default StatusIndicator;