-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for long texts in alert history page
- Loading branch information
1 parent
74c994f
commit a5ff59d
Showing
5 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 22 additions & 3 deletions
25
frontend/src/periscope/components/KeyValueLabel/KeyValueLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
6 changes: 6 additions & 0 deletions
6
frontend/src/periscope/components/LineClampedText/LineClampedText.styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.line-clamped-text { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} |
52 changes: 52 additions & 0 deletions
52
frontend/src/periscope/components/LineClampedText/LineClampedText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
30 changes: 30 additions & 0 deletions
30
frontend/src/periscope/components/TrimmedText/TrimmedText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |