1717
1818<template >
1919 <div >
20- <a-select
21- v-model:value =" severity"
22- style =" width : 200px ; margin-bottom : 12px "
23- @change =" onFilterChange" >
24- <a-select-option value =" " >{{ $t('label.severity') }}: {{ $t('label.all') }}</a-select-option >
25- <a-select-option v-for =" s in severities" :key =" s" :value =" s" >{{ s }}</a-select-option >
26- </a-select >
20+ <div class =" toolbar" >
21+ <a-select
22+ v-model:value =" severity"
23+ style =" width : 200px "
24+ @change =" onFilterChange" >
25+ <a-select-option value =" " >{{ $t('label.severity') }}: {{ $t('label.all') }}</a-select-option >
26+ <a-select-option v-for =" s in severities" :key =" s" :value =" s" >{{ s }}</a-select-option >
27+ </a-select >
28+ <a-button v-if =" canCreateRule" type =" primary" @click =" showCreateRule = true" >
29+ <template #icon ><plus-outlined /></template >
30+ {{ $t('label.create.resource.alert.rule') }}
31+ </a-button >
32+ </div >
2733 <a-table
2834 size =" small"
2935 :columns =" columns"
4753 </template >
4854 </template >
4955 </a-table >
56+ <a-modal
57+ v-if =" showCreateRule"
58+ :visible =" showCreateRule"
59+ :title =" $t('label.create.resource.alert.rule')"
60+ :footer =" null"
61+ :maskClosable =" false"
62+ centered
63+ @cancel =" showCreateRule = false" >
64+ <create-resource-alert-rule
65+ :resource =" resource"
66+ :presetResourceType =" resourceType"
67+ @close-action =" showCreateRule = false" />
68+ </a-modal >
5069 </div >
5170</template >
5271
5372<script >
5473import { getAPI } from ' @/api'
5574import { resourceAlertLabel } from ' @/views/resourcealert/resourceAlertOptions'
75+ import CreateResourceAlertRule from ' @/views/resourcealert/CreateResourceAlertRule.vue'
5676
5777// Shows the alerts of one resource, or of one rule when no resourceType is given.
5878export default {
5979 name: ' ResourceAlertsTab' ,
80+ components: {
81+ CreateResourceAlertRule
82+ },
6083 props: {
6184 resource: {
6285 type: Object ,
@@ -78,6 +101,7 @@ export default {
78101 return {
79102 alerts: [],
80103 tabLoading: false ,
104+ showCreateRule: false ,
81105 severity: ' ' ,
82106 severities: [' CRITICAL' , ' HIGH' , ' MEDIUM' , ' LOW' ],
83107 page: 1 ,
@@ -94,6 +118,10 @@ export default {
94118 }
95119 },
96120 computed: {
121+ // Extensions do not report VM or host usage, so rules on them would never fire
122+ canCreateRule () {
123+ return !! this .resourceType && ' createResourceAlertRule' in this .$store .getters .apis && this .resource ? .hypervisor !== ' External'
124+ },
97125 pagination () {
98126 return {
99127 current: this .page ,
@@ -157,3 +185,12 @@ export default {
157185 }
158186}
159187< / script>
188+
189+ < style scoped>
190+ .toolbar {
191+ display: flex;
192+ justify- content: space- between;
193+ align- items: center;
194+ margin- bottom: 12px ;
195+ }
196+ < / style>
0 commit comments