**Related issue:** Resolves https://github.com/fleetdm/fleet/issues/46818 and https://github.com/fleetdm/fleet/issues/48524. # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually ## fleetd/orbit/Fleet Desktop - [x] Verified compatibility with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)) - [x] If the change applies to only one platform, confirmed that `runtime.GOOS` is used as needed to isolate changes - [x] Verified that fleetd runs on macOS, Linux and Windows - [x] Verified auto-update works from the released version of component to the new version (see [tools/tuf/test](../tools/tuf/test/README.md)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Host lists and Host details now show human‑readable Apple hardware marketing names (macOS, iOS, iPadOS) where available (e.g., "MacBook Pro (16‑inch, 2021)"), replacing raw model identifiers. * Hardware model displays fall back to the original model identifier for non‑Apple or unmapped devices. * **Bug Fixes / CSV** * Exported host CSVs now align with the UI by using the marketing name for Apple devices when available. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Lucas Manuel Rodriguez <lucas@fleetdm.com>
105 lines
3.3 KiB
TypeScript
105 lines
3.3 KiB
TypeScript
import React, { useState, useRef, useLayoutEffect } from "react";
|
|
import { uniqueId } from "lodash";
|
|
import classnames from "classnames";
|
|
|
|
import ReactTooltip from "react-tooltip";
|
|
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
|
|
import { COLORS } from "styles/var/colors";
|
|
|
|
interface ITooltipTruncatedTextCellProps {
|
|
value: React.ReactNode;
|
|
/** Tooltip to display. If this is provided then this will be rendered as the tooltip content. If
|
|
* not, the value will be displayed as the tooltip content. Default: undefined */
|
|
tooltip?: React.ReactNode;
|
|
/** If set to `true` the text inside the tooltip will break on words instead of any character.
|
|
* By default the tooltip text breaks on any character. Default: false */
|
|
tooltipBreakOnWord?: boolean;
|
|
className?: string;
|
|
/** Content does not get truncated */
|
|
prefix?: React.ReactNode;
|
|
/** Content does not get truncated */
|
|
suffix?: React.ReactNode;
|
|
/** When `true`, show the tooltip even when the text is not truncated. Use
|
|
* when the tooltip carries supplemental info (e.g. a raw identifier behind a
|
|
* friendlier display value) rather than just the truncated text. */
|
|
alwaysShowTooltip?: boolean;
|
|
}
|
|
|
|
const baseClass = "tooltip-truncated-cell";
|
|
|
|
const TooltipTruncatedTextCell = ({
|
|
value,
|
|
tooltip,
|
|
tooltipBreakOnWord = false,
|
|
className,
|
|
prefix,
|
|
suffix,
|
|
alwaysShowTooltip = false,
|
|
}: ITooltipTruncatedTextCellProps): JSX.Element => {
|
|
const classNames = classnames(baseClass, className, {
|
|
"tooltip-break-on-word": tooltipBreakOnWord,
|
|
});
|
|
|
|
// Tooltip visibility logic: Enable only when text is truncated
|
|
const ref = useRef<HTMLSpanElement>(null);
|
|
const [tooltipDisabled, setTooltipDisabled] = useState(true);
|
|
|
|
useLayoutEffect(() => {
|
|
if (ref?.current !== null) {
|
|
const scrollWidth = ref.current.scrollWidth;
|
|
const offsetWidth = ref.current.offsetWidth;
|
|
setTooltipDisabled(scrollWidth <= offsetWidth);
|
|
}
|
|
}, [ref]);
|
|
// End
|
|
|
|
const tooltipId = uniqueId();
|
|
value =
|
|
value === null || value === undefined || value === ""
|
|
? DEFAULT_EMPTY_CELL_VALUE
|
|
: value;
|
|
const isDefaultValue = value === DEFAULT_EMPTY_CELL_VALUE;
|
|
|
|
return (
|
|
<div className={classNames}>
|
|
{prefix && <span className="data-table__prefix">{prefix}</span>}
|
|
<div
|
|
className="data-table__tooltip-truncated-text-container"
|
|
data-tip
|
|
data-for={tooltipId}
|
|
data-tip-disable={
|
|
isDefaultValue || (tooltipDisabled && !alwaysShowTooltip)
|
|
}
|
|
>
|
|
<span
|
|
ref={ref}
|
|
className={`data-table__tooltip-truncated-text ${
|
|
isDefaultValue ? "text-muted" : ""
|
|
} ${tooltipDisabled ? "" : "truncated"}`}
|
|
>
|
|
{value}
|
|
</span>
|
|
</div>
|
|
<ReactTooltip
|
|
place="top"
|
|
effect="solid"
|
|
backgroundColor={COLORS["tooltip-bg"]}
|
|
id={tooltipId}
|
|
data-html
|
|
className="truncated-tooltip" // responsive widths
|
|
clickable
|
|
delayHide={200} // need delay set to hover using clickable
|
|
>
|
|
<>
|
|
{tooltip ?? value}
|
|
<div className="safari-hack"> </div>
|
|
{/* Fixes triple click selecting next element in Safari */}
|
|
</>
|
|
</ReactTooltip>
|
|
{suffix && <span className="data-table__suffix">{suffix}</span>}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default TooltipTruncatedTextCell;
|