@@ -26,12 +26,13 @@ enum Operation {
2626}
2727
2828const route = useRoute ();
29+ const router = useRouter ();
2930const endpointName = route .params .endpointName .toString ();
3031const store = useHeartbeatInstancesStore ();
3132const { filteredInstances, sortedInstances, instanceFilterString, sortByInstances } = storeToRefs (store );
3233const endpointSettings = ref <EndpointSettings []>([endpointSettingsClient .defaultEndpointSettingsValue ()]);
3334const backLink = ref <string >(routeLinks .heartbeats .root );
34- const filterInstances = (data : EndpointsView []) =>
35+ const filterToValidInstances = (data : EndpointsView []) =>
3536 data
3637 .filter ((instance ) => instance .name === endpointName )
3738 .filter ((instance ) => {
@@ -42,8 +43,8 @@ const filterInstances = (data: EndpointsView[]) =>
4243
4344 return true ;
4445 });
45- const instances = computed (() => filterInstances (filteredInstances .value ));
46- const totalInstances = computed (() => filterInstances (sortedInstances .value ));
46+ const filteredValidInstances = computed (() => filterToValidInstances (filteredInstances .value ));
47+ const totalValidInstances = computed (() => filterToValidInstances (sortedInstances .value ));
4748const showBulkWarningDialog = ref (false );
4849const dialogWarningOperation = ref (Operation .Mute );
4950
@@ -68,7 +69,9 @@ async function proceedWarningDialog() {
6869 showBulkWarningDialog .value = false ;
6970
7071 try {
71- await store .toggleEndpointMonitor (instances .value .filter ((instance ) => (dialogWarningOperation .value === Operation .Unmute && ! instance .monitor_heartbeat ) || (dialogWarningOperation .value === Operation .Mute && instance .monitor_heartbeat )));
72+ await store .toggleEndpointMonitor (
73+ filteredValidInstances .value .filter ((instance ) => (dialogWarningOperation .value === Operation .Unmute && ! instance .monitor_heartbeat ) || (dialogWarningOperation .value === Operation .Mute && instance .monitor_heartbeat ))
74+ );
7275 useShowToast (TYPE .SUCCESS , ` All endpoint instances ${dialogWarningOperation .value } ` , " " , false , { timeout: 1000 });
7376 } catch {
7477 useShowToast (TYPE .ERROR , " Save failed" , " " , false , { timeout: 3000 });
@@ -84,6 +87,16 @@ async function deleteInstance(instance: EndpointsView) {
8487 }
8588}
8689
90+ async function deleteAllInstances() {
91+ try {
92+ await Promise .all (sortedInstances .value .filter ((instance ) => instance .name === endpointName ).map ((instance ) => store .deleteEndpointInstance (instance )));
93+ useShowToast (TYPE .SUCCESS , " Endpoint deleted" , " " , false , { timeout: 1000 });
94+ await router .replace (backLink .value );
95+ } catch {
96+ useShowToast (TYPE .ERROR , " Delete failed" , " " , false , { timeout: 3000 });
97+ }
98+ }
99+
87100async function toggleAlerts(instance : EndpointsView ) {
88101 try {
89102 await store .toggleEndpointMonitor ([instance ]);
@@ -99,7 +112,7 @@ async function toggleAlerts(instance: EndpointsView) {
99112 <ConfirmDialog
100113 v-if =" showBulkWarningDialog"
101114 heading =" Proceed with bulk operation"
102- :body =" `Are you sure you want to ${dialogWarningOperation} ${instances .length} endpoint instance(s)?`"
115+ :body =" `Are you sure you want to ${dialogWarningOperation} ${filteredValidInstances .length} endpoint instance(s)?`"
103116 @cancel =" cancelWarningDialog"
104117 @confirm =" proceedWarningDialog"
105118 />
@@ -119,19 +132,19 @@ async function toggleAlerts(instance: EndpointsView) {
119132 <div class =" row filters" >
120133 <div class =" col-sm-12" >
121134 <span class =" buttonsContainer" >
122- <button type =" button" class =" btn btn-warning btn-sm" :disabled =" instances .length === 0" @click =" showBulkOperationWarningDialog(Operation.Mute)" >
135+ <button type =" button" class =" btn btn-warning btn-sm" :disabled =" filteredValidInstances .length === 0" @click =" showBulkOperationWarningDialog(Operation.Mute)" >
123136 <i
124137 :class =" {
125- 'text-black': instances .length > 0,
138+ 'text-black': filteredValidInstances .length > 0,
126139 }"
127140 class =" fa fa-bell-slash"
128141 />
129142 Mute Alerts on All
130143 </button >
131- <button type =" button" class =" btn btn-default btn-sm" :disabled =" instances .length === 0" @click =" showBulkOperationWarningDialog(Operation.Unmute)" >
144+ <button type =" button" class =" btn btn-default btn-sm" :disabled =" filteredValidInstances .length === 0" @click =" showBulkOperationWarningDialog(Operation.Unmute)" >
132145 <i
133146 :class =" {
134- 'text-black': instances .length > 0,
147+ 'text-black': filteredValidInstances .length > 0,
135148 }"
136149 class =" fa fa-bell"
137150 />
@@ -141,7 +154,7 @@ async function toggleAlerts(instance: EndpointsView) {
141154 </div >
142155 </div >
143156 <div class =" row" >
144- <ResultsCount :displayed =" instances .length" :total =" totalInstances .length" />
157+ <ResultsCount :displayed =" filteredValidInstances .length" :total =" totalValidInstances .length" />
145158 </div >
146159 <section role =" table" aria-label =" endpoint-instances" >
147160 <!-- Table headings-->
@@ -180,9 +193,15 @@ async function toggleAlerts(instance: EndpointsView) {
180193 </div >
181194 </div >
182195 </div >
183- <no-data v-if =" instances.length === 0" message =" No endpoint instances found. For untracked endpoints, disconnected instances are automatically pruned." ></no-data >
196+ <no-data v-if =" filteredValidInstances.length === 0" message =" No endpoint instances found. For untracked endpoints, disconnected instances are automatically pruned." >
197+ <div v-if =" totalValidInstances.length === 0" class =" delete-all" >
198+ <span >You may</span >
199+ <button type =" button" @click =" deleteAllInstances()" class =" btn btn-danger btn-sm" ><i class =" fa fa-trash text-white" /> Delete</button >
200+ <span >this endpoint</span >
201+ </div >
202+ </no-data >
184203 <!-- Table rows-->
185- <DataView :data =" instances " :show-items-per-page =" true" :items-per-page =" 20" >
204+ <DataView :data =" filteredValidInstances " :show-items-per-page =" true" :items-per-page =" 20" >
186205 <template #data =" { pageData } " >
187206 <div role =" rowgroup" aria-label =" endpoints" >
188207 <div role =" row" :aria-label =" instance.name" class =" row grid-row" v-for =" instance in pageData" :key =" instance.id" >
@@ -247,4 +266,10 @@ async function toggleAlerts(instance: EndpointsView) {
247266 border-radius : 3px ;
248267 padding : 0.4em ;
249268}
269+
270+ .delete-all {
271+ display : flex ;
272+ align-items : center ;
273+ gap : 0.4em ;
274+ }
250275 </style >
0 commit comments