client/src/Pages/Infrastructure/Create/index.jsx
This commit is contained in:
1 parent
d4ecb26ffe
commit
0ecbf48f5d
1 file changed
+39
-34
@@ -93,10 +93,7 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
// Populate form fields if editing
|
// Populate form fields if editing
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (monitor == undefined && (!isCreate || globalSettingsLoading)) return;
|
|
||||||
const globalThresholds = globalSettings?.data?.settings?.globalThresholds;
|
const globalThresholds = globalSettings?.data?.settings?.globalThresholds;
|
||||||
|
|
||||||
// Define default empty string for all thresholds
|
|
||||||
const defaultThresholds = {
|
const defaultThresholds = {
|
||||||
cpu: "",
|
cpu: "",
|
||||||
memory: "",
|
memory: "",
|
||||||
@@ -104,37 +101,45 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
temperature: "",
|
temperature: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
setInfrastructureMonitor((prev) => ({
|
if (isCreate) {
|
||||||
...prev,
|
// If global settings are not loaded yet, use default thresholds
|
||||||
url: monitor != undefined ? monitor.url.replace(/^https?:\/\//, "") : "",
|
if (globalSettingsLoading) return;
|
||||||
name: monitor != undefined ? monitor.name || "" : "",
|
// Create mode: use global thresholds
|
||||||
notifications: monitor != undefined ? monitor.notifications : [],
|
setInfrastructureMonitor((prev) => ({
|
||||||
interval: monitor != undefined ? monitor.interval / MS_PER_MINUTE : 0.25,
|
...prev,
|
||||||
cpu: globalThresholds.cpu != null,
|
url: "",
|
||||||
usage_cpu:
|
name: "",
|
||||||
globalThresholds.cpu != null
|
notifications: [],
|
||||||
? globalThresholds.cpu.toString()
|
interval: 0.25,
|
||||||
: defaultThresholds.cpu,
|
cpu: globalThresholds?.cpu != null,
|
||||||
|
usage_cpu: globalThresholds?.cpu?.toString() || defaultThresholds.cpu,
|
||||||
memory: globalThresholds.memory != null,
|
memory: globalThresholds?.memory != null,
|
||||||
usage_memory:
|
usage_memory: globalThresholds?.memory?.toString() || defaultThresholds.memory,
|
||||||
globalThresholds.memory != null
|
disk: globalThresholds?.disk != null,
|
||||||
? globalThresholds.memory.toString()
|
usage_disk: globalThresholds?.disk?.toString() || defaultThresholds.disk,
|
||||||
: defaultThresholds.memory,
|
temperature: globalThresholds?.temperature != null,
|
||||||
|
usage_temperature:
|
||||||
disk: globalThresholds.disk != null,
|
globalThresholds?.temperature?.toString() || defaultThresholds.temperature,
|
||||||
usage_disk:
|
}));
|
||||||
globalThresholds.disk != null
|
} else if (monitor) {
|
||||||
? globalThresholds.disk.toString()
|
// Edit mode: use monitor only, ignore global thresholds
|
||||||
: defaultThresholds.disk,
|
setInfrastructureMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
temperature: globalThresholds.temperature != null,
|
url: monitor.url?.replace(/^https?:\/\//, "") || "",
|
||||||
usage_temperature:
|
name: monitor.name || "",
|
||||||
globalThresholds.temperature != null
|
notifications: monitor.notifications || [],
|
||||||
? globalThresholds.temperature.toString()
|
interval: monitor.interval / MS_PER_MINUTE,
|
||||||
: defaultThresholds.temperature,
|
cpu: !!monitor.thresholds?.usage_cpu ?? false,
|
||||||
}));
|
usage_cpu: monitor.thresholds?.usage_cpu * 100?.toString() || "",
|
||||||
}, [isCreate, globalSettings, monitor, globalSettingsLoading]);
|
memory: !!monitor.thresholds?.usage_memory ?? false,
|
||||||
|
usage_memory: monitor.thresholds?.usage_memory * 100?.toString() || "",
|
||||||
|
disk: !!monitor.thresholds?.usage_disk ?? false,
|
||||||
|
usage_disk: monitor.thresholds?.usage_disk * 100?.toString() || "",
|
||||||
|
temperature: !!monitor.thresholds?.usage_temperature ?? false,
|
||||||
|
usage_temperature: monitor.thresholds?.usage_temperature * 100?.toString() || "",
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [isCreate, monitor, globalSettings, globalSettingsLoading]);
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
|
|||||||
Reference in new issue
Block a user