mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
## Addresses [this missing copy](https://github.com/fleetdm/fleet/issues/15707#issuecomment-1906595805) <img width="1109" alt="image" src="https://github.com/fleetdm/fleet/assets/61553566/a8b8bf17-ec42-401b-ae2c-99b8bbdbd26e"> - [x] Changes file added for user-visible changes in `changes/` - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { uniqueId } from "lodash";
|
|
import React from "react";
|
|
import ReactTooltip from "react-tooltip";
|
|
import { COLORS } from "styles/var/colors";
|
|
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
|
|
|
|
interface ITextCellProps {
|
|
value?: string | number | boolean | { timeString: string } | null;
|
|
formatter?: (val: any) => React.ReactNode; // string, number, or null
|
|
greyed?: boolean;
|
|
classes?: string;
|
|
emptyCellTooltipText?: React.ReactNode;
|
|
}
|
|
|
|
const TextCell = ({
|
|
value,
|
|
formatter = (val) => val, // identity function if no formatter is provided
|
|
greyed,
|
|
classes = "w250",
|
|
emptyCellTooltipText,
|
|
}: ITextCellProps): JSX.Element => {
|
|
let val = value;
|
|
|
|
if (typeof value === "boolean") {
|
|
val = value.toString();
|
|
}
|
|
if (!val) {
|
|
greyed = true;
|
|
}
|
|
|
|
const renderEmptyCell = () => {
|
|
if (emptyCellTooltipText) {
|
|
const tooltipId = uniqueId();
|
|
return (
|
|
<>
|
|
<span data-tip data-for={tooltipId}>
|
|
{DEFAULT_EMPTY_CELL_VALUE}
|
|
</span>
|
|
<ReactTooltip
|
|
place="top"
|
|
effect="solid"
|
|
backgroundColor={COLORS["tooltip-bg"]}
|
|
id={tooltipId}
|
|
>
|
|
{emptyCellTooltipText}
|
|
</ReactTooltip>
|
|
</>
|
|
);
|
|
}
|
|
return DEFAULT_EMPTY_CELL_VALUE;
|
|
};
|
|
|
|
return (
|
|
<span className={`text-cell ${classes} ${greyed && "grey-cell"}`}>
|
|
{formatter(val) || renderEmptyCell()}
|
|
</span>
|
|
);
|
|
};
|
|
|
|
export default TextCell;
|