mirror of
https://github.com/prymitive/karma
synced 2026-05-19 04:26:41 +00:00
feat(ui): truncate silences with long comments
Only show first 2 lines of a silence comment by default, the rest should be visible only when silence details are visible
This commit is contained in:
@@ -15,7 +15,16 @@ exports[`<Silence /> matches snapshot when data is present in alertStore 1`] = `
|
||||
<div class=\\"card mt-1 border-0 p-1\\">
|
||||
<div class=\\"card-text mb-0\\">
|
||||
<span class=\\"text-muted my-1\\">
|
||||
Fake silence
|
||||
<span width=\\"0\\">
|
||||
<span>
|
||||
</span>
|
||||
<span>
|
||||
Fake silence
|
||||
</span>
|
||||
<span style=\\"position: fixed; visibility: hidden; top: 0px; left: 0px;\\">
|
||||
…
|
||||
</span>
|
||||
</span>
|
||||
<span class=\\"blockquote-footer pt-1\\">
|
||||
<span class=\\"float-right cursor-pointer\\">
|
||||
<div class
|
||||
@@ -71,7 +80,16 @@ exports[`<Silence /> matches snapshot with expaned details 1`] = `
|
||||
<div class=\\"card mt-1 border-0 p-1\\">
|
||||
<div class=\\"card-text mb-0\\">
|
||||
<span class=\\"text-muted my-1\\">
|
||||
Fake silence
|
||||
<span width=\\"0\\">
|
||||
<span>
|
||||
</span>
|
||||
<span>
|
||||
Fake silence
|
||||
</span>
|
||||
<span style=\\"position: fixed; visibility: hidden; top: 0px; left: 0px;\\">
|
||||
…
|
||||
</span>
|
||||
</span>
|
||||
<span class=\\"blockquote-footer pt-1\\">
|
||||
<span class=\\"float-right cursor-pointer\\">
|
||||
<div class
|
||||
|
||||
@@ -9,6 +9,8 @@ import hash from "object-hash";
|
||||
import moment from "moment";
|
||||
import Moment from "react-moment";
|
||||
|
||||
import Truncate from "react-truncate";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt";
|
||||
import { faChevronUp } from "@fortawesome/free-solid-svg-icons/faChevronUp";
|
||||
@@ -33,19 +35,25 @@ import { DeleteSilence } from "./DeleteSilence";
|
||||
|
||||
import "./index.css";
|
||||
|
||||
const SilenceComment = ({ silence }) => {
|
||||
const SilenceComment = ({ silence, collapsed }) => {
|
||||
const showLines = 2;
|
||||
if (silence.jiraURL) {
|
||||
return (
|
||||
<a href={silence.jiraURL} target="_blank" rel="noopener noreferrer">
|
||||
<FontAwesomeIcon className="mr-1" icon={faExternalLinkAlt} />
|
||||
{silence.comment}
|
||||
<Truncate lines={collapsed ? showLines : false}>
|
||||
{silence.comment}
|
||||
</Truncate>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
return silence.comment;
|
||||
return (
|
||||
<Truncate lines={collapsed ? showLines : false}>{silence.comment}</Truncate>
|
||||
);
|
||||
};
|
||||
SilenceComment.propTypes = {
|
||||
silence: APISilence.isRequired
|
||||
silence: APISilence.isRequired,
|
||||
collapsed: PropTypes.bool.isRequired
|
||||
};
|
||||
|
||||
const SilenceExpiryBadgeWithProgress = ({ silence, progress }) => {
|
||||
@@ -305,7 +313,10 @@ const Silence = inject("alertStore")(
|
||||
<div className="card mt-1 border-0 p-1">
|
||||
<div className="card-text mb-0">
|
||||
<span className="text-muted my-1">
|
||||
<SilenceComment silence={silence} />
|
||||
<SilenceComment
|
||||
silence={silence}
|
||||
collapsed={this.collapse.value}
|
||||
/>
|
||||
<span className="blockquote-footer pt-1">
|
||||
<span
|
||||
className="float-right cursor-pointer"
|
||||
|
||||
@@ -168,13 +168,23 @@ describe("<Silence />", () => {
|
||||
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders comment as link when jiraURL is set", () => {
|
||||
it("renders comment as link when jiraURL is set and silence is collapsed", () => {
|
||||
alertStore.data.silences.default[silence.id].jiraURL =
|
||||
"http://jira.example.com";
|
||||
const tree = MountedSilence(alertmanager).find("Silence");
|
||||
const link = tree.find("a[href='http://jira.example.com']");
|
||||
expect(link).toHaveLength(1);
|
||||
expect(link.text()).toBe("Fake silence");
|
||||
expect(link.text()).toBe("Fake silence…");
|
||||
});
|
||||
|
||||
it("renders comment as link when jiraURL is set and silence is expaned", () => {
|
||||
alertStore.data.silences.default[silence.id].jiraURL =
|
||||
"http://jira.example.com";
|
||||
const tree = MountedSilence(alertmanager).find("Silence");
|
||||
tree.instance().collapse.toggle();
|
||||
const link = tree.find("a[href='http://jira.example.com']");
|
||||
expect(link).toHaveLength(1);
|
||||
expect(link.text()).toBe("Fake silence…");
|
||||
});
|
||||
|
||||
it("clears progress timer on unmount", () => {
|
||||
|
||||
Reference in New Issue
Block a user