add truncation and tooltip to host details host with long name (#28547)

For [#27198](https://github.com/fleetdm/fleet/issues/27198)

Adds truncation and conditional tooltip to the host name on the host
details page.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Gabriel Hernandez 2025-04-28 17:09:42 +01:00 committed by GitHub
parent a7967a398c
commit 9ec9995560
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 7 deletions

View file

@ -0,0 +1 @@
- add truncation and a conditional tooltip for long host names on the host details page

View file

@ -114,7 +114,7 @@ const ActivityItem = ({
});
const onShowActivityDetails = (e: React.MouseEvent<HTMLButtonElement>) => {
// added this stopPropagation to as there is some weirdness around the event
// added this stopPropagation as there is some weirdness around the event
// bubbling up and calling the Modals onEnter handler.
e.stopPropagation();
onShowDetails({ type: activity.type, details: activity.details });

View file

@ -62,6 +62,19 @@
.display-name {
font-size: $large;
font-weight: $bold;
@include ellipse-text(300px);
@media (min-width: $break-md) {
@include ellipse-text(500px);
}
@media (min-width: $break-lg) {
@include ellipse-text(800px);
}
@media (min-width: $break-xxl) {
@include ellipse-text(1000px);
}
}
}

View file

@ -1,4 +1,4 @@
import React from "react";
import React, { useRef } from "react";
import ReactTooltip from "react-tooltip";
import classnames from "classnames";
import { formatInTimeZone } from "date-fns-tz";
@ -39,6 +39,7 @@ import {
DATE_FNS_FORMAT_STRINGS,
DEFAULT_EMPTY_CELL_VALUE,
} from "utilities/constants";
import { useCheckTruncatedElement } from "hooks/useCheckTruncatedElement";
import { COLORS } from "styles/var/colors";
import OSSettingsIndicator from "./OSSettingsIndicator";
@ -205,6 +206,9 @@ const HostSummary = ({
osSettings,
hostMdmDeviceStatus,
}: IHostSummaryProps): JSX.Element => {
const hostDisplayName = useRef<HTMLHeadingElement>(null);
const isTruncated = useCheckTruncatedElement(hostDisplayName);
const {
status,
platform,
@ -616,11 +620,23 @@ const HostSummary = ({
<div className="header title">
<div className="title__inner">
<div className="display-name-container">
<h1 className="display-name">
{deviceUser
? "My device"
: summaryData.display_name || DEFAULT_EMPTY_CELL_VALUE}
</h1>
<TooltipWrapper
disableTooltip={!isTruncated}
tipContent={
deviceUser
? "My device"
: summaryData.display_name || DEFAULT_EMPTY_CELL_VALUE
}
underline={false}
position="top"
showArrow
>
<h1 className="display-name" ref={hostDisplayName}>
{deviceUser
? "My device"
: summaryData.display_name || DEFAULT_EMPTY_CELL_VALUE}
</h1>
</TooltipWrapper>
{renderDeviceStatusTag()}