Merge pull request #2317 from bluewave-labs/Pause-button-addition-on-configuration
Added pause button in configuration page.
This commit is contained in:
3 files changed
+52
-17
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
|
||||||
const useMonitorUtils = () => {
|
const useMonitorUtils = () => {
|
||||||
|
|
||||||
const getMonitorWithPercentage = useCallback((monitor, theme) => {
|
const getMonitorWithPercentage = useCallback((monitor, theme) => {
|
||||||
let uptimePercentage = "";
|
let uptimePercentage = "";
|
||||||
let percentageColor = "";
|
let percentageColor = "";
|
||||||
@@ -36,7 +38,16 @@ const useMonitorUtils = () => {
|
|||||||
return monitor?.status == true ? "up" : "down";
|
return monitor?.status == true ? "up" : "down";
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return { getMonitorWithPercentage, determineState };
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const statusColor = {
|
||||||
|
up: theme.palette.success.lowContrast,
|
||||||
|
down: theme.palette.error.lowContrast,
|
||||||
|
paused: theme.palette.warning.lowContrast,
|
||||||
|
pending: theme.palette.warning.lowContrast,
|
||||||
|
};
|
||||||
|
|
||||||
|
return { getMonitorWithPercentage, determineState, statusColor };
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useMonitorUtils };
|
export { useMonitorUtils };
|
||||||
@@ -34,6 +34,10 @@ import SkeletonLayout from "./skeleton";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import Dialog from "../../../Components/Dialog";
|
import Dialog from "../../../Components/Dialog";
|
||||||
import NotificationIntegrationModal from "../../../Components/NotificationIntegrationModal/Components/NotificationIntegrationModal";
|
import NotificationIntegrationModal from "../../../Components/NotificationIntegrationModal/Components/NotificationIntegrationModal";
|
||||||
|
import { usePauseMonitor } from "../../../Hooks/useMonitorControls";
|
||||||
|
import PauseOutlinedIcon from "@mui/icons-material/PauseOutlined";
|
||||||
|
import PlayArrowOutlinedIcon from "@mui/icons-material/PlayArrowOutlined";
|
||||||
|
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a URL string and returns a URL object.
|
* Parses a URL string and returns a URL object.
|
||||||
@@ -83,11 +87,19 @@ const Configure = () => {
|
|||||||
include: "ok",
|
include: "ok",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [trigger, setTrigger] = useState(false);
|
||||||
|
const triggerUpdate = () => {
|
||||||
|
setTrigger(!trigger);
|
||||||
|
};
|
||||||
|
const [pauseMonitor, isPausing, error] = usePauseMonitor({
|
||||||
|
monitorId: monitor?._id,
|
||||||
|
triggerUpdate,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
try {
|
try {
|
||||||
const action = await dispatch(getUptimeMonitorById({ monitorId }));
|
const action = await dispatch(getUptimeMonitorById({ monitorId }));
|
||||||
|
|
||||||
if (getUptimeMonitorById.fulfilled.match(action)) {
|
if (getUptimeMonitorById.fulfilled.match(action)) {
|
||||||
const monitor = action.payload.data;
|
const monitor = action.payload.data;
|
||||||
setMonitor(monitor);
|
setMonitor(monitor);
|
||||||
@@ -100,7 +112,7 @@ const Configure = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [monitorId, navigate]);
|
}, [monitorId, navigate, trigger]);
|
||||||
|
|
||||||
const handleChange = (event, name) => {
|
const handleChange = (event, name) => {
|
||||||
let { checked, value, id } = event.target;
|
let { checked, value, id } = event.target;
|
||||||
@@ -202,17 +214,7 @@ const Configure = () => {
|
|||||||
setIsNotificationModalOpen(false);
|
setIsNotificationModalOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const statusColor = {
|
const { determineState, statusColor } = useMonitorUtils();
|
||||||
true: theme.palette.success.main,
|
|
||||||
false: theme.palette.error.main,
|
|
||||||
undefined: theme.palette.warning.main,
|
|
||||||
};
|
|
||||||
|
|
||||||
const statusMsg = {
|
|
||||||
true: "Your site is up.",
|
|
||||||
false: "Your site is down.",
|
|
||||||
undefined: "Pending...",
|
|
||||||
};
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -257,7 +259,7 @@ const Configure = () => {
|
|||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={statusMsg[monitor?.status ?? undefined]}
|
title={t(`statusMsg.${[determineState(monitor)]}`)}
|
||||||
disableInteractive
|
disableInteractive
|
||||||
slotProps={{
|
slotProps={{
|
||||||
popper: {
|
popper: {
|
||||||
@@ -273,7 +275,7 @@ const Configure = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
<PulseDot color={statusColor[monitor?.status ?? undefined]} />
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
</Box>
|
</Box>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Typography
|
<Typography
|
||||||
@@ -307,11 +309,27 @@ const Configure = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
|
justifyContent="space-between"
|
||||||
sx={{
|
sx={{
|
||||||
alignSelf: "flex-end",
|
alignSelf: "flex-end",
|
||||||
ml: "auto",
|
ml: "auto",
|
||||||
|
display: "flex",
|
||||||
|
gap: theme.spacing(2),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
loading={isPausing}
|
||||||
|
startIcon={
|
||||||
|
monitor?.isActive ? <PauseOutlinedIcon /> : <PlayArrowOutlinedIcon />
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
pauseMonitor();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitor?.isActive ? t("pause") : t("resume")}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
@@ -543,5 +543,11 @@
|
|||||||
"uptimeCreateSelectURL": "Enter the URL or IP to monitor (e.g., https://example.com/ or 192.168.1.100) and add a clear display name that appears on the dashboard.",
|
"uptimeCreateSelectURL": "Enter the URL or IP to monitor (e.g., https://example.com/ or 192.168.1.100) and add a clear display name that appears on the dashboard.",
|
||||||
"sendTestEmail": "Send test email",
|
"sendTestEmail": "Send test email",
|
||||||
"emailSent": "Email sent successfully",
|
"emailSent": "Email sent successfully",
|
||||||
"failedToSendEmail": "Failed to send email"
|
"failedToSendEmail": "Failed to send email",
|
||||||
|
"statusMsg" : {
|
||||||
|
"paused": "Monitoring is paused.",
|
||||||
|
"up": "Your site is up.",
|
||||||
|
"down": "Your site is down.",
|
||||||
|
"pending": "Pending..."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user