Updated UseEffect
This commit is contained in:
1 parent
e04ac77ddd
commit
d4ecb26ffe
1 file changed
+7
-3
@@ -93,8 +93,8 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
// Populate form fields if editing
|
// Populate form fields if editing
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isCreate || globalSettingsLoading) return;
|
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
|
// Define default empty string for all thresholds
|
||||||
const defaultThresholds = {
|
const defaultThresholds = {
|
||||||
@@ -106,6 +106,10 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
|
|
||||||
setInfrastructureMonitor((prev) => ({
|
setInfrastructureMonitor((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
url: monitor != undefined ? monitor.url.replace(/^https?:\/\//, "") : "",
|
||||||
|
name: monitor != undefined ? monitor.name || "" : "",
|
||||||
|
notifications: monitor != undefined ? monitor.notifications : [],
|
||||||
|
interval: monitor != undefined ? monitor.interval / MS_PER_MINUTE : 0.25,
|
||||||
cpu: globalThresholds.cpu != null,
|
cpu: globalThresholds.cpu != null,
|
||||||
usage_cpu:
|
usage_cpu:
|
||||||
globalThresholds.cpu != null
|
globalThresholds.cpu != null
|
||||||
@@ -130,7 +134,7 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
? globalThresholds.temperature.toString()
|
? globalThresholds.temperature.toString()
|
||||||
: defaultThresholds.temperature,
|
: defaultThresholds.temperature,
|
||||||
}));
|
}));
|
||||||
}, [isCreate, globalSettings]);
|
}, [isCreate, globalSettings, monitor, globalSettingsLoading]);
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const onSubmit = async (event) => {
|
const onSubmit = async (event) => {
|
||||||
|
|||||||
Reference in new issue
Block a user