1010 v-if =" systemMetricsStreams[system]?.at(-1)"
1111 :name =" system"
1212 :link =" `/systems/${system}`"
13+ :enable-alert =" systemConfigs[system]?.enableAlerts"
1314 :metrics =" systemMetricsStreams[system].at(-1)!"
15+ @change-alert-toggle ="
16+ (value) => handleAlertToggleChange(value, system)
17+ "
1418 />
1519 <USkeleton class =" h-60 w-full" v-else />
1620 </div >
@@ -25,7 +29,14 @@ import type { Metrics } from "../../shared/types";
2529const isLoading = ref (false );
2630
2731const systems = ref ([]);
28-
32+ const systemConfigs = ref <
33+ Record <
34+ string ,
35+ {
36+ enableAlerts : boolean ;
37+ }
38+ >
39+ > ({});
2940const systemMetricsStreams = reactive <Record <string , Metrics []>>({});
3041
3142function setupMetricsStream() {
@@ -44,17 +55,47 @@ async function loadSystems() {
4455 systems .value = (await $fetch (" /api/sytems" )) ?? [];
4556}
4657
58+ async function loadSystemConfigs() {
59+ const savedSystemConfigs = await $fetch (" /api/system-configs" );
60+
61+ if (savedSystemConfigs ) {
62+ systemConfigs .value = savedSystemConfigs ;
63+ }
64+ }
65+
4766onMounted (async () => {
4867 try {
4968 isLoading .value = true ;
50- await loadSystems ();
69+ await Promise . allSettled ([ loadSystems (), loadSystemConfigs ()] );
5170 setupMetricsStream ();
5271 } catch (error ) {
5372 console .log ({ error });
5473 } finally {
5574 isLoading .value = false ;
5675 }
5776});
77+
78+ async function handleAlertToggleChange(value : boolean , system : string ) {
79+ try {
80+ await $fetch (" /api/system-config" , {
81+ method: " PUT" ,
82+ body: {
83+ system ,
84+ enableAlerts: value ,
85+ },
86+ });
87+ useToast ().add ({
88+ title: " Successfully updated system alert config" ,
89+ color: " green" ,
90+ });
91+ } catch (error ) {
92+ console .log ({ error });
93+ useToast ().add ({
94+ title: " Error updating system alert config" ,
95+ color: " red" ,
96+ });
97+ }
98+ }
5899 </script >
59100
60101<style ></style >
0 commit comments