Skip to content

Commit 6720eeb

Browse files
alert and rule modals
1 parent 02755b5 commit 6720eeb

File tree

22 files changed

+1074
-471
lines changed

22 files changed

+1074
-471
lines changed

app/vmui/packages/vmui/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ const App: FC = () => {
3030
<Route
3131
path={router.rules}
3232
element={<ExploreRules
33-
ruleTypeFilter=""
33+
typeFilter=""
3434
/>}
3535
/>
3636
<Route
3737
path={router.alerts}
3838
element={<ExploreRules
39-
ruleTypeFilter="alert"
39+
typeFilter="alert"
4040
/>}
4141
/>
4242
<Route
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
export const getGroupsUrl = (server: string, ruleType: string): string => {
2-
let groupUrl = `${server}/api/v1/rules`;
2+
let groupUrl = `${server}/vmalert/api/v1/rules?datasource_type=vlogs`;
33
if (ruleType) {
4-
groupUrl = `${groupUrl}?type=${ruleType}`;
4+
groupUrl = `${groupUrl}&type=${ruleType}`;
55
}
66
return groupUrl;
77
};
88

9+
export const getItemUrl = (
10+
server: string,
11+
groupId: string,
12+
id: string,
13+
mode: string,
14+
): string => {
15+
return `${server}/vmalert/api/v1/${mode}?group_id=${groupId}&${mode}_id=${id}`;
16+
};
17+
918
export const getNotifiersUrl = (server: string): string => {
10-
return `${server}/api/v1/notifiers`;
19+
return `${server}/vmalert/api/v1/notifiers`;
1120
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import "./style.scss";
2+
import { Alert as APIAlert } from "../../../types";
3+
import { Link } from "react-router-dom";
4+
5+
interface BaseAlertProps {
6+
item: APIAlert;
7+
}
8+
9+
const BaseAlert = ({ item }: BaseAlertProps) => {
10+
const query = item?.expression;
11+
12+
const source = item.source;
13+
14+
return (
15+
<div className="vm-explore-alerts-rule-item">
16+
<table>
17+
<tbody>
18+
<tr>
19+
<td className="vm-col-small">Name</td>
20+
<td>{item.name}</td>
21+
</tr>
22+
<tr>
23+
<td className="vm-col-small">Group</td>
24+
<td>
25+
<Link to={`/groups#group-${item.group_id}`}>{item.group_id}</Link>
26+
</td>
27+
</tr>
28+
<tr>
29+
<td className="vm-col-small">Query</td>
30+
<td>
31+
{(source && (
32+
<Link
33+
to={source}
34+
target="_blank"
35+
rel="noreferrer"
36+
>
37+
<pre>
38+
<code className="language-promql">{query}</code>
39+
</pre>
40+
</Link>
41+
)) || (
42+
<pre>
43+
<code className="language-promql">{query}</code>
44+
</pre>
45+
)}
46+
</td>
47+
</tr>
48+
{item.labels && (
49+
<tr>
50+
<td className="vm-col-small">Labels</td>
51+
<td>
52+
<div className="vm-badge-container">
53+
{Object.entries(item.labels).map(([name, value]) => (
54+
<span
55+
key={name}
56+
className="vm-badge"
57+
>{`${name}: ${value}`}</span>
58+
))}
59+
</div>
60+
</td>
61+
</tr>
62+
)}
63+
</tbody>
64+
</table>
65+
{item.annotations && (
66+
<>
67+
<span className="title">Annotations</span>
68+
<table>
69+
<tbody>
70+
{Object.entries(item.annotations || {}).map(([name, value]) => (
71+
<tr key={name}>
72+
<td className="vm-col-small">{name}</td>
73+
<td>{value}</td>
74+
</tr>
75+
))}
76+
</tbody>
77+
</table>
78+
</>
79+
)}
80+
</div>
81+
);
82+
};
83+
84+
export default BaseAlert;
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@use "src/styles/variables" as *;
2+
3+
.vm-modal {
4+
.vm-explore-alerts-rule-item {
5+
table {
6+
width: auto;
7+
}
8+
}
9+
}
10+
11+
.vm-explore-alerts-rule-item {
12+
row-gap: $padding-global;
13+
margin-right: $padding-global;
14+
display: flex;
15+
flex-direction: column;
16+
17+
.title {
18+
font-weight: bold;
19+
text-align: center;
20+
}
21+
22+
a:hover > pre {
23+
background-color: $color-hover-darker;
24+
cursor: pointer;
25+
}
26+
27+
a:hover {
28+
background-color: $color-hover-darker;
29+
cursor: pointer;
30+
}
31+
32+
pre {
33+
background-color: $color-hover-black;
34+
padding: 0 $padding-global;
35+
border-radius: $border-radius-small;
36+
word-break: break-word;
37+
white-space: pre-wrap;
38+
.keyword,
39+
.function,
40+
.attr-name,
41+
.range-duration {
42+
color: $color-keyword;
43+
}
44+
}
45+
46+
.vm-col-small {
47+
width: 15%;
48+
white-space: nowrap;
49+
text-align: left;
50+
overflow: hidden;
51+
text-overflow: ellipsis;
52+
}
53+
54+
table {
55+
width: 100%;
56+
table-layout: fixed;
57+
tr[id] {
58+
cursor: pointer;
59+
&:hover {
60+
background-color: $color-hover-darker;
61+
}
62+
}
63+
td, th {
64+
line-height: 30px;
65+
padding: $padding-small;
66+
}
67+
th[colspan],
68+
td[colspan] {
69+
font-weight: bold;
70+
text-align: center;
71+
padding: 20px 0;
72+
}
73+
th {
74+
font-weight: bold;
75+
text-align: center;
76+
padding: 0 $padding-small;
77+
}
78+
}
79+
80+
.vm-badge-container {
81+
display: flex;
82+
flex-wrap: wrap;
83+
gap: $padding-small;
84+
}
85+
86+
.vm-badge {
87+
padding: 0 $padding-small;
88+
border-radius: $border-radius-small;
89+
background-color: $color-hover-black;
90+
max-width: 300px;
91+
overflow: hidden;
92+
white-space: nowrap;
93+
text-overflow: ellipsis;
94+
width: fit-content;
95+
96+
&:is(.firing) {
97+
background: $color-error;
98+
color: $color-white;
99+
}
100+
101+
&:is(.pending) {
102+
background: $color-warning;
103+
color: $color-white;
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)