mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 06:58:58 +08:00
fix: add support for long texts in alert history page (#5895)
This commit is contained in:
parent
41d3342a42
commit
d6b75d76ca
@ -1,5 +1,6 @@
|
||||
import './AlertHeader.styles.scss';
|
||||
|
||||
import LineClampedText from 'periscope/components/LineClampedText/LineClampedText';
|
||||
import { useAlertRule } from 'providers/Alert';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
|
||||
@ -42,7 +43,9 @@ function AlertHeader({ alertDetails }: AlertHeaderProps): JSX.Element {
|
||||
<div className="top-section">
|
||||
<div className="alert-title-wrapper">
|
||||
<AlertState state={isAlertRuleDisabled ? 'disabled' : state} />
|
||||
<div className="alert-title">{alert}</div>
|
||||
<div className="alert-title">
|
||||
<LineClampedText text={alert} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bottom-section">
|
||||
|
@ -1,18 +1,37 @@
|
||||
import './KeyValueLabel.styles.scss';
|
||||
|
||||
type KeyValueLabelProps = { badgeKey: string; badgeValue: string };
|
||||
import { Tooltip } from 'antd';
|
||||
|
||||
import TrimmedText from '../TrimmedText/TrimmedText';
|
||||
|
||||
type KeyValueLabelProps = {
|
||||
badgeKey: string;
|
||||
badgeValue: string;
|
||||
maxCharacters?: number;
|
||||
};
|
||||
|
||||
export default function KeyValueLabel({
|
||||
badgeKey,
|
||||
badgeValue,
|
||||
maxCharacters = 20,
|
||||
}: KeyValueLabelProps): JSX.Element | null {
|
||||
if (!badgeKey || !badgeValue) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className="key-value-label">
|
||||
<div className="key-value-label__key">{badgeKey}</div>
|
||||
<div className="key-value-label__value">{badgeValue}</div>
|
||||
<div className="key-value-label__key">
|
||||
<TrimmedText text={badgeKey} maxCharacters={maxCharacters} />
|
||||
</div>
|
||||
<Tooltip title={badgeValue}>
|
||||
<div className="key-value-label__value">
|
||||
<TrimmedText text={badgeValue} maxCharacters={maxCharacters} />
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
KeyValueLabel.defaultProps = {
|
||||
maxCharacters: 20,
|
||||
};
|
||||
|
@ -0,0 +1,6 @@
|
||||
.line-clamped-text {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import './LineClampedText.styles.scss';
|
||||
|
||||
import { Tooltip } from 'antd';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
function LineClampedText({
|
||||
text,
|
||||
lines,
|
||||
}: {
|
||||
text: string;
|
||||
lines?: number;
|
||||
}): JSX.Element {
|
||||
const [isOverflowing, setIsOverflowing] = useState(false);
|
||||
const textRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const checkOverflow = (): void => {
|
||||
if (textRef.current) {
|
||||
setIsOverflowing(
|
||||
textRef.current.scrollHeight > textRef.current.clientHeight,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
checkOverflow();
|
||||
window.addEventListener('resize', checkOverflow);
|
||||
|
||||
return (): void => {
|
||||
window.removeEventListener('resize', checkOverflow);
|
||||
};
|
||||
}, [text, lines]);
|
||||
|
||||
const content = (
|
||||
<div
|
||||
ref={textRef}
|
||||
className="line-clamped-text"
|
||||
style={{
|
||||
WebkitLineClamp: lines,
|
||||
}}
|
||||
>
|
||||
{text}
|
||||
</div>
|
||||
);
|
||||
|
||||
return isOverflowing ? <Tooltip title={text}>{content}</Tooltip> : content;
|
||||
}
|
||||
|
||||
LineClampedText.defaultProps = {
|
||||
lines: 1,
|
||||
};
|
||||
|
||||
export default LineClampedText;
|
@ -0,0 +1,30 @@
|
||||
import { Tooltip } from 'antd';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
function TrimmedText({
|
||||
text,
|
||||
maxCharacters,
|
||||
}: {
|
||||
text: string;
|
||||
maxCharacters: number;
|
||||
}): JSX.Element {
|
||||
const [displayText, setDisplayText] = useState(text);
|
||||
|
||||
useEffect(() => {
|
||||
if (text.length > maxCharacters) {
|
||||
setDisplayText(`${text.slice(0, maxCharacters)}...`);
|
||||
} else {
|
||||
setDisplayText(text);
|
||||
}
|
||||
}, [text, maxCharacters]);
|
||||
|
||||
return text.length > maxCharacters ? (
|
||||
<Tooltip title={text}>
|
||||
<span>{displayText}</span>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<span>{displayText}</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default TrimmedText;
|
Loading…
x
Reference in New Issue
Block a user