From f7bea5cd1933cf42cc1b376530e122b271731218 Mon Sep 17 00:00:00 2001 From: Vicente Olivert Riera Date: Fri, 26 Jul 2024 19:56:10 +0900 Subject: [PATCH] Convert silence_row into a Vue component This will help with future development around the Silence area. The component allows choosing the color of the matchers, and also emits an event when a matcher is clicked. That way we can reuse the component for multiple purposes, displaying the matchers in a different color and doing an different action when a matcher is clicked. A few bits had to be added in order to maintain the current style, such as the template and tbody tags. --- promgen/static/js/promgen.vue.js | 17 +++++++++++ promgen/templates/base.html | 3 ++ .../templates/promgen/global_silences.html | 28 +++++++++++-------- promgen/templates/promgen/project_detail.html | 8 ++++-- promgen/templates/promgen/service_block.html | 8 ++++-- promgen/templates/promgen/silence_row.html | 18 ------------ .../templates/promgen/vue/silence_row.html | 28 +++++++++++++++++++ 7 files changed, 75 insertions(+), 35 deletions(-) delete mode 100644 promgen/templates/promgen/silence_row.html create mode 100644 promgen/templates/promgen/vue/silence_row.html diff --git a/promgen/static/js/promgen.vue.js b/promgen/static/js/promgen.vue.js index be3d63ab8..baac5975e 100644 --- a/promgen/static/js/promgen.vue.js +++ b/promgen/static/js/promgen.vue.js @@ -150,6 +150,23 @@ const app = Vue.createApp({ app.config.compilerOptions.whitespace = "preserve"; +app.component("silence-row", { + delimiters: ["[[", "]]"], + template: "#silence-row-template", + mixins: [mixins], + emits: ["matcherClick"], + props: { + silence: { + type: Object, + required: true, + }, + labelColor: { + type: String, + default: "info", + }, + }, +}); + app.component('silence-modal', { template: '#silence-modal-template', delimiters: ['[[', ']]'], diff --git a/promgen/templates/base.html b/promgen/templates/base.html index 4acfea225..a97a880b5 100644 --- a/promgen/templates/base.html +++ b/promgen/templates/base.html @@ -55,6 +55,9 @@ + diff --git a/promgen/templates/promgen/global_silences.html b/promgen/templates/promgen/global_silences.html index 627f3f77d..9b7c9784a 100644 --- a/promgen/templates/promgen/global_silences.html +++ b/promgen/templates/promgen/global_silences.html @@ -4,16 +4,22 @@ × - - - - - - - - - - {% include 'promgen/silence_row.html' %} - + + + + + + + + + + +
StartsEndsMatchersCommentCreated by 
StartsEndsMatchersCommentCreated by 
diff --git a/promgen/templates/promgen/project_detail.html b/promgen/templates/promgen/project_detail.html index 772343a8c..6842466bf 100644 --- a/promgen/templates/promgen/project_detail.html +++ b/promgen/templates/promgen/project_detail.html @@ -45,9 +45,11 @@

Silences - - {% include 'promgen/silence_row.html' %} - + + +
diff --git a/promgen/templates/promgen/service_block.html b/promgen/templates/promgen/service_block.html index 7d768bc6d..441752edd 100644 --- a/promgen/templates/promgen/service_block.html +++ b/promgen/templates/promgen/service_block.html @@ -17,9 +17,11 @@ Silences - - {% include 'promgen/silence_row.html' %} - + + +
diff --git a/promgen/templates/promgen/silence_row.html b/promgen/templates/promgen/silence_row.html deleted file mode 100644 index 6a5038ea2..000000000 --- a/promgen/templates/promgen/silence_row.html +++ /dev/null @@ -1,18 +0,0 @@ -{% load i18n %} -[[time(silence.startsAt)]] -[[time(silence.endsAt)]] - - - - -[[silence.createdBy]] - - - {% trans "Expire" %} - diff --git a/promgen/templates/promgen/vue/silence_row.html b/promgen/templates/promgen/vue/silence_row.html new file mode 100644 index 000000000..6eb1189f0 --- /dev/null +++ b/promgen/templates/promgen/vue/silence_row.html @@ -0,0 +1,28 @@ +{% load i18n %} + + [[ time(silence.startsAt) ]] + [[ time(silence.endsAt) ]] + + + + + [[ silence.createdBy ]] + + + {% translate "Expire" %} + + +