fleet/frontend/components/StatusIndicatorWithIcon/StatusIndicatorWithIcon.tsx
Gabriel Hernandez db8c79aa2a
add windows bitlocker to mdm controls page (#13953)
relates to #12926

This implements the changes to the Controls page that add the windows
Bitlocker functionality.
There is some work that needs to be complete when the API is done. For
now we are mocking the new disk encryption API response

**new column for windows hosts:**


![image](https://github.com/fleetdm/fleet/assets/1153709/39adb0fa-c59f-483f-a2c3-45a2b95492aa)

also includes various other changes behind the scenes that include
windows hosts into the disk encryption as well as changes to the
profiles status summary to use StatusIndicatorWithIcon

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality
2023-09-18 15:22:18 +01:00

84 lines
2 KiB
TypeScript

import React from "react";
import ReactTooltip from "react-tooltip";
import { uniqueId } from "lodash";
import classnames from "classnames";
import { IconNames } from "components/icons";
import Icon from "components/Icon";
import { COLORS } from "styles/var/colors";
const baseClass = "status-indicator-with-icon";
export type IndicatorStatus =
| "success"
| "successPartial"
| "pending"
| "pendingPartial"
| "error";
interface IStatusIndicatorWithIconProps {
status: IndicatorStatus;
value: string;
tooltip?: {
tooltipText: string | JSX.Element;
position?: "top" | "bottom";
};
layout?: "horizontal" | "vertical";
className?: string;
/** Classname to add to the value text */
valueClassName?: string;
}
const statusIconNameMapping: Record<IndicatorStatus, IconNames> = {
success: "success",
successPartial: "success-partial",
pending: "pending",
pendingPartial: "pending-partial",
error: "error",
};
const StatusIndicatorWithIcon = ({
status,
value,
tooltip,
layout = "horizontal",
className,
valueClassName,
}: IStatusIndicatorWithIconProps) => {
const classNames = classnames(baseClass, className);
const id = `status-${uniqueId()}`;
const valueClasses = classnames(`${baseClass}__value`, valueClassName, {
[`${baseClass}__value-vertical`]: layout === "vertical",
});
const valueContent = (
<span className={valueClasses}>
<Icon name={statusIconNameMapping[status]} />
<span>{value}</span>
</span>
);
const indicatorContent = tooltip ? (
<>
<span data-tip data-for={id}>
{valueContent}
</span>
<ReactTooltip
className={`${baseClass}__tooltip`}
place={tooltip?.position ? tooltip.position : "top"}
type="dark"
effect="solid"
id={id}
backgroundColor={COLORS["tooltip-bg"]}
>
{tooltip.tooltipText}
</ReactTooltip>
</>
) : (
<span>{valueContent}</span>
);
return <div className={classNames}>{indicatorContent}</div>;
};
export default StatusIndicatorWithIcon;