Format MonitorsTableMenu component
This commit is contained in:
1 parent
c44325ba7f
commit
5ba82415ad
1 file changed
+41
-24
@@ -34,14 +34,14 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [pauseMonitor] = usePauseMonitor();
|
const [pauseMonitor] = usePauseMonitor();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
// Update local state when monitor prop changes
|
// Update local state when monitor prop changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Ensure we have a valid monitor object with default values for missing properties
|
// Ensure we have a valid monitor object with default values for missing properties
|
||||||
if (monitor) {
|
if (monitor) {
|
||||||
setLocalMonitorState({
|
setLocalMonitorState({
|
||||||
...monitor,
|
...monitor,
|
||||||
status: monitor.status || 'active' // Default to active if status is undefined
|
status: monitor.status || "active", // Default to active if status is undefined
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [monitor]);
|
}, [monitor]);
|
||||||
@@ -77,19 +77,19 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const handlePause = async () => {
|
const handlePause = async () => {
|
||||||
try {
|
try {
|
||||||
// Toggle the local state immediately for better UI responsiveness
|
// Toggle the local state immediately for better UI responsiveness
|
||||||
setLocalMonitorState(prevState => ({
|
setLocalMonitorState((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
status: prevState.status === "paused" ? "active" : "paused"
|
status: prevState.status === "paused" ? "active" : "paused",
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Pass updateCallback as triggerUpdate to the hook
|
// Pass updateCallback as triggerUpdate to the hook
|
||||||
await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback });
|
await pauseMonitor({ monitorId: monitor.id, triggerUpdate: updateCallback });
|
||||||
// Toast is already displayed in the hook, no need to display it again
|
// Toast is already displayed in the hook, no need to display it again
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Error handling is done in the hook - revert the local state on error
|
// Error handling is done in the hook - revert the local state on error
|
||||||
setLocalMonitorState(prevState => ({
|
setLocalMonitorState((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
status: prevState.status === "paused" ? "active" : "paused"
|
status: prevState.status === "paused" ? "active" : "paused",
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -99,7 +99,9 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
await networkService.deleteMonitorById({
|
await networkService.deleteMonitorById({
|
||||||
monitorId: monitor.id,
|
monitorId: monitor.id,
|
||||||
});
|
});
|
||||||
createToast({ body: t("monitorActions.deleteSuccess", "Monitor deleted successfully") });
|
createToast({
|
||||||
|
body: t("monitorActions.deleteSuccess", "Monitor deleted successfully"),
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({ body: t("monitorActions.deleteFailed", "Failed to delete monitor") });
|
createToast({ body: t("monitorActions.deleteFailed", "Failed to delete monitor") });
|
||||||
} finally {
|
} finally {
|
||||||
@@ -145,25 +147,37 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MenuItem onClick={(e) => {
|
<MenuItem
|
||||||
e.stopPropagation();
|
onClick={(e) => {
|
||||||
openDetails(monitor.id);
|
|
||||||
closeMenu(e);
|
|
||||||
}}>{t("monitorActions.details", "Details")}</MenuItem>
|
|
||||||
{isAdmin && (
|
|
||||||
<MenuItem onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
openConfigure(monitor.id);
|
openDetails(monitor.id);
|
||||||
closeMenu(e);
|
closeMenu(e);
|
||||||
}}>{t("configure", "Configure")}</MenuItem>
|
}}
|
||||||
|
>
|
||||||
|
{t("monitorActions.details", "Details")}
|
||||||
|
</MenuItem>
|
||||||
|
{isAdmin && (
|
||||||
|
<MenuItem
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
openConfigure(monitor.id);
|
||||||
|
closeMenu(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("configure", "Configure")}
|
||||||
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<MenuItem onClick={async (e) => {
|
<MenuItem
|
||||||
e.stopPropagation();
|
onClick={async (e) => {
|
||||||
await handlePause();
|
e.stopPropagation();
|
||||||
closeMenu(e);
|
await handlePause();
|
||||||
}}>
|
closeMenu(e);
|
||||||
{localMonitorState?.status === "paused" ? t("resume", "Resume") : t("pause", "Pause")}
|
}}
|
||||||
|
>
|
||||||
|
{localMonitorState?.status === "paused"
|
||||||
|
? t("resume", "Resume")
|
||||||
|
: t("pause", "Pause")}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
@@ -179,7 +193,10 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
open={isDialogOpen}
|
open={isDialogOpen}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
title={t("deleteDialogTitle", "Do you really want to delete this monitor?")}
|
title={t("deleteDialogTitle", "Do you really want to delete this monitor?")}
|
||||||
description={t("deleteDialogDescription", "Once deleted, this monitor cannot be retrieved.")}
|
description={t(
|
||||||
|
"deleteDialogDescription",
|
||||||
|
"Once deleted, this monitor cannot be retrieved."
|
||||||
|
)}
|
||||||
onCancel={cancelRemove}
|
onCancel={cancelRemove}
|
||||||
confirmationButtonLabel={t("delete", "Delete")}
|
confirmationButtonLabel={t("delete", "Delete")}
|
||||||
onConfirm={handleRemove}
|
onConfirm={handleRemove}
|
||||||
|
|||||||
Reference in new issue
Block a user