Made code readable

This commit is contained in:
singh-kanwarpreet committed 2025-07-30 23:14:35 +05:30
1 parent 5e46a9f2d5
commit 2d6fdcb1e2
1 file changed
+44 -17
@@ -96,8 +96,9 @@ const CreateInfrastructureMonitor = () => {
if (isCreate) { if (isCreate) {
// If global settings are not loaded yet, use default thresholds // If global settings are not loaded yet, use default thresholds
if (globalSettingsLoading) return; if (globalSettingsLoading) return;
// Create mode: use global thresholds // Create mode: use global thresholds
const globalThresholds = globalSettings?.data?.settings?.globalThresholds; const globalThresholds = globalSettings?.data?.settings?.globalThresholds || {};
const defaultThresholds = { const defaultThresholds = {
cpu: "", cpu: "",
memory: "", memory: "",
@@ -111,15 +112,26 @@ const CreateInfrastructureMonitor = () => {
name: "", name: "",
notifications: [], notifications: [],
interval: 0.25, interval: 0.25,
cpu: globalThresholds?.cpu != null, cpu: globalThresholds.cpu != null,
usage_cpu: globalThresholds?.cpu?.toString() || defaultThresholds.cpu, usage_cpu:
memory: globalThresholds?.memory != null, globalThresholds.cpu != null
usage_memory: globalThresholds?.memory?.toString() || defaultThresholds.memory, ? globalThresholds.cpu.toString()
disk: globalThresholds?.disk != null, : defaultThresholds.cpu,
usage_disk: globalThresholds?.disk?.toString() || defaultThresholds.disk, memory: globalThresholds.memory != null,
temperature: globalThresholds?.temperature != null, usage_memory:
globalThresholds.memory != null
? globalThresholds.memory.toString()
: defaultThresholds.memory,
disk: globalThresholds.disk != null,
usage_disk:
globalThresholds.disk != null
? globalThresholds.disk.toString()
: defaultThresholds.disk,
temperature: globalThresholds.temperature != null,
usage_temperature: usage_temperature:
globalThresholds?.temperature?.toString() || defaultThresholds.temperature, globalThresholds.temperature != null
? globalThresholds.temperature.toString()
: defaultThresholds.temperature,
})); }));
} else if (monitor) { } else if (monitor) {
// Edit mode: use monitor only, ignore global thresholds // Edit mode: use monitor only, ignore global thresholds
@@ -129,15 +141,30 @@ const CreateInfrastructureMonitor = () => {
name: monitor.name || "", name: monitor.name || "",
notifications: monitor.notifications || [], notifications: monitor.notifications || [],
interval: monitor.interval / MS_PER_MINUTE, interval: monitor.interval / MS_PER_MINUTE,
cpu: !!monitor.thresholds?.usage_cpu ?? false, cpu: monitor.thresholds?.usage_cpu != null,
usage_cpu: monitor.thresholds?.usage_cpu * 100?.toString() || "", usage_cpu:
memory: !!monitor.thresholds?.usage_memory ?? false, monitor.thresholds?.usage_cpu != null
usage_memory: monitor.thresholds?.usage_memory * 100?.toString() || "", ? (monitor.thresholds.usage_cpu * 100).toString()
disk: !!monitor.thresholds?.usage_disk ?? false, : "",
usage_disk: monitor.thresholds?.usage_disk * 100?.toString() || "", memory: monitor.thresholds?.usage_memory != null,
temperature: !!monitor.thresholds?.usage_temperature ?? false, usage_memory:
usage_temperature: monitor.thresholds?.usage_temperature * 100?.toString() || "", monitor.thresholds?.usage_memory != null
? (monitor.thresholds.usage_memory * 100).toString()
: "",
disk: monitor.thresholds?.usage_disk != null,
usage_disk:
monitor.thresholds?.usage_disk != null
? (monitor.thresholds.usage_disk * 100).toString()
: "",
temperature: monitor.thresholds?.usage_temperature != null,
usage_temperature:
monitor.thresholds?.usage_temperature != null
? (monitor.thresholds.usage_temperature * 100).toString()
: "",
secret: monitor.secret || "",
})); }));
setHttps(monitor.url?.startsWith("https"));
} }
}, [isCreate, monitor, globalSettings, globalSettingsLoading]); }, [isCreate, monitor, globalSettings, globalSettingsLoading]);