Skip to content

Commit 4036b53

Browse files
committed
Add Edit Silence feature
We have added a new feature that allows users to easily edit an existing Silence instead of expiring it and creating a new one. Now, users can select a Silence from the list to edit fields such as matchers, startsAt, endsAt, duration and comment.
1 parent c3d1c02 commit 4036b53

6 files changed

Lines changed: 45 additions & 11 deletions

File tree

promgen/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class MatcherSerializer(serializers.Serializer):
130130

131131

132132
class SilenceSerializer(serializers.Serializer):
133+
id = serializers.CharField(required=False)
133134
matchers = MatcherSerializer(many=True)
134135
startsAt = serializers.CharField(required=False)
135136
endsAt = serializers.CharField(required=False)

promgen/static/js/promgen.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ function activateTabFromHash() {
156156
}
157157
}
158158

159+
function UTCToFormattedLocalDateTime(utcString) {
160+
const date = new Date(utcString);
161+
const year = date.getFullYear();
162+
const month = String(date.getMonth() + 1).padStart(2, "0");
163+
const day = String(date.getDate()).padStart(2, "0");
164+
const hours = String(date.getHours()).padStart(2, "0");
165+
const minutes = String(date.getMinutes()).padStart(2, "0");
166+
return `${year}-${month}-${day}T${hours}:${minutes}`;
167+
}
168+
159169
$(document).ready(function() {
160170
$('[data-toggle="popover"]').popover();
161171
$('[data-toggle="tooltip"]').tooltip();

promgen/static/js/promgen.vue.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const dataStore = Vue.reactive({
2323
const silenceStore = Vue.reactive({
2424
state: {
2525
show: false,
26-
labels: {}
26+
labels: {},
27+
silence: null,
2728
},
2829
setLabels(labels) {
2930
this.state.labels = { ...labels };
@@ -47,6 +48,10 @@ const silenceStore = Vue.reactive({
4748
}
4849
this.state.labels[label] = value;
4950
},
51+
setSilence(silence) {
52+
this.state.silence = silence;
53+
this.setLabels(silence.labels);
54+
},
5055
showModal() {
5156
this.state.show = true;
5257
},
@@ -159,6 +164,11 @@ const app = Vue.createApp({
159164
silencesMatchService.includes(silence)
160165
);
161166
},
167+
editSilence: function (silence) {
168+
silenceListStore.hideModal();
169+
silenceStore.setSilence(silence);
170+
silenceStore.showModal();
171+
}
162172
},
163173
computed: {
164174
activeServiceAlerts: function () {
@@ -255,6 +265,7 @@ app.component('silence-create-modal', {
255265
}
256266

257267
const body = JSON.stringify({
268+
id: this.state.silence?.id,
258269
matchers: matchers,
259270
startsAt: this.form.startsAt,
260271
endsAt: this.form.endsAt,
@@ -287,11 +298,17 @@ app.component('silence-create-modal', {
287298
if (modal.length) {
288299
globalStore.setMessages([]);
289300
this.form = {operator: "="};
301+
silenceStore.state.silence = null;
290302
this.state = silenceStore.state;
291303
modal.modal('hide');
292304
}
293305
},
294306
showModal() {
307+
if (this.state.silence) {
308+
this.form.startsAt = UTCToFormattedLocalDateTime(this.state.silence.startsAt);
309+
this.form.endsAt = UTCToFormattedLocalDateTime(this.state.silence.endsAt);
310+
this.form.comment = this.state.silence.comment;
311+
}
295312
const modal = $('#silenceCreateModal');
296313
if (modal.length) {
297314
// Detect when the modal is closed, and update the state accordingly. This is

promgen/templates/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
<script type="text/x-template" id="silence-list-modal-template">
6565
{% include 'promgen/vue/silence_list_modal.html' %}
6666
</script>
67-
<script src="{% static 'js/promgen.js' %}?v=5"></script>
67+
<script src="{% static 'js/promgen.js' %}?v=6"></script>
6868
<script src="{% static 'js/mixins.vue.js' %}"></script>
69-
<script src="{% static 'js/promgen.vue.js' %}?v=5"></script>
69+
<script src="{% static 'js/promgen.vue.js' %}?v=6"></script>
7070
{% block javascript %}{% endblock %}
7171

7272
<datalist style="display:none" id="common.labels">

promgen/templates/promgen/vue/silence_create_modal.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<div class="modal-content">
44
<div class="modal-header">
55
<button type="button" class="close" @click="state.show = false" aria-label="Close"><span aria-hidden="true">&times;</span></button>
6-
<h4 class="modal-title" id="silenceModalLabel">New Silence</h4>
6+
<h4 class="modal-title" id="silenceModalLabel">
7+
<div v-if="!state.silence">New Silence</div>
8+
<div v-else>Edit Silence: [[state.silence.id]]</div>
9+
</h4>
710
</div>
811
<div class="modal-body" style="padding:10px 30px;">
912

@@ -100,7 +103,10 @@ <h5>
100103
</form>
101104
</div>
102105
<div class="modal-footer">
103-
<button type="button" class="btn btn-primary" @click="submit()">Create</button>
106+
<button type="button" class="btn btn-primary" @click="submit()">
107+
<div v-if="!state.silence">Create</div>
108+
<div v-else>Save</div>
109+
</button>
104110
</div>
105111
</div>
106112
</div>

promgen/templates/promgen/vue/silence_row.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
</ul>
2222
</td>
2323
<td class="col-xs-3" v-html="urlize(silence.comment)"></td>
24-
<td class="col-xs-3">[[ silence.createdBy ]]</td>
25-
<td style="col-xs-1">
26-
<a
27-
@click="$root.expireSilence(silence.id)"
28-
class="btn btn-warning btn-xs"
29-
>
24+
<td class="col-xs-2">[[ silence.createdBy ]]</td>
25+
<td class="col-xs-2">
26+
<a @click="$root.editSilence(silence)" class="btn btn-warning btn-xs">
27+
{% translate "Edit" %}
28+
</a>
29+
<a @click="$root.expireSilence(silence.id)" class="btn btn-warning btn-xs">
3030
{% translate "Expire" %}
3131
</a>
3232
</td>

0 commit comments

Comments
 (0)