mirror of
https://github.com/fleetdm/fleet
synced 2026-04-22 22:17:21 +00:00
relates to #27567 this adds two columns to the certificates table on host details and my device pages; the issuer cell and the issued cell. This also makes a change to TooltipTruncateTextCell that set the value as `---` if the provided value is undefined, null, or empty string. This still allows the number `0` to be provided <img width="1205" height="540" alt="image" src="https://github.com/user-attachments/assets/b712ccda-b5be-422d-9489-612ccdacab79" /> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added "Issuer" and "Issued" columns to the certificates table on host details and my device pages, providing more certificate information. * **Style** * Improved table styling with horizontal scrolling for overflowing content and consistent sizing for status indicators. * **Bug Fixes** * Ensured empty or missing table cell values are consistently displayed with a default placeholder. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
100 lines
3.2 KiB
TypeScript
100 lines
3.2 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;
|
|
/** @deprecated use the prop `className` in order to add custom classes to this component */
|
|
classes?: string;
|
|
className?: string;
|
|
/** Content does not get truncated */
|
|
prefix?: React.ReactNode;
|
|
/** Content does not get truncated */
|
|
suffix?: React.ReactNode;
|
|
}
|
|
|
|
const baseClass = "tooltip-truncated-cell";
|
|
|
|
const TooltipTruncatedTextCell = ({
|
|
value,
|
|
tooltip,
|
|
tooltipBreakOnWord = false,
|
|
classes = "w250",
|
|
className,
|
|
prefix,
|
|
suffix,
|
|
}: ITooltipTruncatedTextCellProps): JSX.Element => {
|
|
const classNames = classnames(baseClass, classes, 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}
|
|
>
|
|
<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;
|