fleet/frontend/components/StatusIndicatorWithIcon/StatusIndicatorWithIcon.tsx
jacobshandling e25c1c3728
UI: Add ability to run a script on all hosts that match a set of supported filters; Add UI to view batch run summaries (#29025)
_Only merge to `main` after [back
end](https://github.com/fleetdm/fleet/pull/29149) and [back end
extension](https://github.com/fleetdm/fleet/pull/29312)_

## For #28699, #29143, #29281

- Run scripts by filter
- View batch script run summary via activity feed
- Code clean up

### Run scripts by filter:
<img width="1280" alt="Screenshot 2025-05-09 at 5 21 51 PM"
src="https://github.com/user-attachments/assets/bcf2e275-f229-461b-8411-0e99c34af5bf"
/>
<img width="1280" alt="Screenshot 2025-05-09 at 5 22 47 PM"
src="https://github.com/user-attachments/assets/d4882ed3-cfa6-4952-acbe-89c60d65d482"
/>

### View script run summary:

![ezgif-4ebaf9c57d6e57](https://github.com/user-attachments/assets/4201ff85-04e3-473f-8a82-969f85e59558)

- [x] Changes file added for user-visible changes in `changes/`
- [x] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-05-22 16:45:43 -07:00

87 lines
2.1 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import { IconNames } from "components/icons";
import Icon from "components/Icon";
import TooltipWrapper from "components/TooltipWrapper";
const baseClass = "status-indicator-with-icon";
export type IndicatorStatus =
| "success"
| "successPartial"
| "pending"
| "pendingPartial"
| "error"
| "failure"
| "actionRequired";
interface IStatusIndicatorWithIconProps {
/** Determines which icon to display */
status: IndicatorStatus;
/** The text to be displayed */
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-outline",
pending: "pending",
pendingPartial: "pending-outline",
error: "error",
failure: "error-outline",
actionRequired: "error",
};
const StatusIndicatorWithIcon = ({
status,
value,
tooltip,
layout = "horizontal",
className,
valueClassName,
}: IStatusIndicatorWithIconProps) => {
const classNames = classnames(baseClass, className);
const valueClasses = classnames(`${baseClass}__value`, valueClassName, {
[`${baseClass}__value-vertical`]: layout === "vertical",
});
const valueContent = (
<span className={valueClasses}>
<Icon
name={statusIconNameMapping[status]}
color={status === "failure" ? "ui-fleet-black-50" : undefined}
/>
<span>{value}</span>
</span>
);
const indicatorContent = tooltip ? (
<TooltipWrapper
className={`${baseClass}__tooltip`}
tooltipClass="indicator-tip-text"
position="top"
tipContent={tooltip.tooltipText}
tipOffset={10}
showArrow
underline={false}
fixedPositionStrategy
>
{valueContent}
</TooltipWrapper>
) : (
<span>{valueContent}</span>
);
return <div className={classNames}>{indicatorContent}</div>;
};
export default StatusIndicatorWithIcon;