mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
> Related issue: #9956 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Martin Angers <martin.n.angers@gmail.com> Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com> Co-authored-by: Roberto Dip <rroperzh@gmail.com> Co-authored-by: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com> Co-authored-by: Dante Catalfamo <43040593+dantecatalfamo@users.noreply.github.com> Co-authored-by: Roberto Dip <dip.jesusr@gmail.com>
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import React, { ReactNode } from "react";
|
|
import classnames from "classnames";
|
|
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
|
|
import TooltipWrapper from "components/TooltipWrapper";
|
|
import { capitalize } from "lodash";
|
|
|
|
const baseClass = "status-indicator";
|
|
|
|
export type IIndicatorValue = "success" | "warning" | "error" | "indeterminate";
|
|
|
|
interface IStatusIndicatorProps {
|
|
/** Only the first letter of value will be capitalized by the component.
|
|
* NOTE: Do not rely on the value prop to determine the status indicator. Use the
|
|
* `indicator` prop instead.
|
|
*/
|
|
value: string;
|
|
/** The indicator type allows for showing the desired indicator.
|
|
* NOTE: use this instead relying on the `value` prop to determine the indicator.
|
|
*/
|
|
indicator?: IIndicatorValue;
|
|
tooltip?: {
|
|
tooltipText: ReactNode;
|
|
position?: "top" | "bottom";
|
|
};
|
|
/**
|
|
* @deprecated Use `indicator` instead to show the desired indicator.
|
|
*/
|
|
customIndicatorType?: string;
|
|
className?: 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,
|
|
indicator,
|
|
tooltip,
|
|
customIndicatorType,
|
|
className,
|
|
}: IStatusIndicatorProps): JSX.Element => {
|
|
const indicatorStateClassTag = generateIndicatorStateClassTag(
|
|
value,
|
|
customIndicatorType
|
|
);
|
|
|
|
const classes = classnames(
|
|
baseClass,
|
|
className,
|
|
`${baseClass}--${indicatorStateClassTag}`,
|
|
`status--${indicatorStateClassTag}`,
|
|
indicator ? `${baseClass}--${indicator}` : null
|
|
);
|
|
|
|
const capitalizedValue = capitalize(value);
|
|
|
|
const indicatorContent = tooltip ? (
|
|
<TooltipWrapper
|
|
position={tooltip?.position ? tooltip.position : "top"}
|
|
showArrow
|
|
underline={false}
|
|
tipContent={tooltip.tooltipText}
|
|
tipOffset={14}
|
|
>
|
|
{capitalizedValue}
|
|
</TooltipWrapper>
|
|
) : (
|
|
capitalizedValue
|
|
);
|
|
|
|
return <span className={classes}>{indicatorContent}</span>;
|
|
};
|
|
|
|
export default StatusIndicator;
|