Merge pull request #939 from bluewave-labs/901-create-confirmation-dialogs-for-clear-all-stats-and-remove-all-monitors
Create delete all monitors and clear all stats windows using dialog component, Resolves #901
This commit is contained in:
4 files changed
+149
-135
No files matched your search
@@ -0,0 +1,80 @@
|
|||||||
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
import { Button, Modal, Stack, Typography } from "@mui/material";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
const Dialog = ({ modelTitle, modelDescription,
|
||||||
|
open, onClose, title, confirmationBtnLbl, confirmationBtnOnClick, cancelBtnLbl, cancelBtnOnClick, theme, isLoading, description }) => {
|
||||||
|
return <Modal
|
||||||
|
aria-labelledby={modelTitle}
|
||||||
|
aria-describedby={modelDescription}
|
||||||
|
open={open}
|
||||||
|
onClose={onClose} >
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: "50%",
|
||||||
|
left: "50%",
|
||||||
|
transform: "translate(-50%, -50%)",
|
||||||
|
width: 400,
|
||||||
|
bgcolor: theme.palette.background.main,
|
||||||
|
border: 1,
|
||||||
|
borderColor: theme.palette.border.light,
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
boxShadow: 24,
|
||||||
|
p: theme.spacing(15),
|
||||||
|
"&:focus": {
|
||||||
|
outline: "none",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography id={modelTitle} component="h2"
|
||||||
|
fontSize={16}
|
||||||
|
color={theme.palette.text.primary}
|
||||||
|
fontWeight={600}>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{description && <Typography id={modelDescription} color={theme.palette.text.tertiary}>
|
||||||
|
{description}
|
||||||
|
</Typography>}
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
mt={theme.spacing(12)}
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="text"
|
||||||
|
color="info"
|
||||||
|
onClick={cancelBtnOnClick}
|
||||||
|
>
|
||||||
|
{cancelBtnLbl}
|
||||||
|
</Button>
|
||||||
|
<LoadingButton
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
loading= {isLoading}
|
||||||
|
onClick={confirmationBtnOnClick}
|
||||||
|
>
|
||||||
|
{confirmationBtnLbl}
|
||||||
|
</LoadingButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Modal>
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog.propTypes = {
|
||||||
|
modelTitle: PropTypes.string.isRequired,
|
||||||
|
modelDescription: PropTypes.string.isRequired,
|
||||||
|
open: PropTypes.bool.isRequired,
|
||||||
|
onClose: PropTypes.func.isRequired,
|
||||||
|
title: PropTypes.string.isRequired,
|
||||||
|
confirmationBtnLbl: PropTypes.string.isRequired,
|
||||||
|
confirmationBtnOnClick: PropTypes.func.isRequired,
|
||||||
|
cancelBtnLbl: PropTypes.string.isRequired,
|
||||||
|
cancelBtnOnClick: PropTypes.func.isRequired,
|
||||||
|
theme: PropTypes.object.isRequired,
|
||||||
|
isLoading: PropTypes.bool.isRequired,
|
||||||
|
description: PropTypes.string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Dialog
|
||||||
@@ -2,7 +2,7 @@ import { useNavigate, useParams } from "react-router";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material";
|
import { Box, Stack, Tooltip, Typography } from "@mui/material";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
@@ -24,6 +24,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
|
|||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import Dialog from "../../../Components/Dialog";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a URL string and returns a URL object.
|
* Parses a URL string and returns a URL object.
|
||||||
@@ -447,71 +448,21 @@ const Configure = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Modal
|
<Dialog
|
||||||
aria-labelledby="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
aria-describedby="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onClose={() => setIsOpen(false)}
|
onClose={() => setIsOpen(false)}
|
||||||
disablePortal
|
title="Do you really want to delete this monitor?"
|
||||||
|
confirmationBtnLbl="Delete"
|
||||||
|
confirmationBtnOnClick={handleRemove}
|
||||||
|
cancelBtnLbl="Cancel"
|
||||||
|
cancelBtnOnClick={() => setIsOpen(false)}
|
||||||
|
theme={theme}
|
||||||
|
isLoading={isLoading}
|
||||||
|
description="Once deleted, this monitor cannot be retrieved."
|
||||||
>
|
>
|
||||||
<Stack
|
</Dialog>
|
||||||
gap={theme.spacing(2)}
|
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
width: 400,
|
|
||||||
bgcolor: theme.palette.background.main,
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.border.light,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
boxShadow: 24,
|
|
||||||
p: theme.spacing(15),
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
id="modal-delete-monitor"
|
|
||||||
component="h2"
|
|
||||||
fontSize={16}
|
|
||||||
color={theme.palette.text.primary}
|
|
||||||
fontWeight={600}
|
|
||||||
>
|
|
||||||
Do you really want to delete this monitor?
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
id="delete-monitor-confirmation"
|
|
||||||
color={theme.palette.text.tertiary}
|
|
||||||
>
|
|
||||||
Once deleted, this monitor cannot be retrieved.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(12)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={() => setIsOpen(false)}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<LoadingButton
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
loading={isLoading}
|
|
||||||
onClick={handleRemove}
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</LoadingButton>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,13 +5,9 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import {
|
import {
|
||||||
Button,
|
|
||||||
IconButton,
|
IconButton,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem
|
||||||
Modal,
|
|
||||||
Stack,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
deleteUptimeMonitor,
|
deleteUptimeMonitor,
|
||||||
@@ -20,6 +16,7 @@ import {
|
|||||||
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import Dialog from "../../../Components/Dialog"
|
||||||
|
|
||||||
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
@@ -29,7 +26,7 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const authToken = authState.authToken;
|
const authToken = authState.authToken;
|
||||||
|
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -199,69 +196,21 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
<Modal
|
<Dialog
|
||||||
aria-labelledby="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
aria-describedby="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onClose={(e) => {
|
onClose={() => setIsOpen(false)}
|
||||||
e.stopPropagation();
|
title="Do you really want to delete this monitor?"
|
||||||
setIsOpen(false);
|
confirmationBtnLbl="Delete"
|
||||||
}}
|
confirmationBtnOnClick={e => { e.stopPropagation(); handleRemove(e) }}
|
||||||
|
cancelBtnLbl="Cancel"
|
||||||
|
cancelBtnOnClick={e => { e.stopPropagation(); setIsOpen(false) }}
|
||||||
|
theme={theme}
|
||||||
|
isLoading={isLoading}
|
||||||
|
description="Once deleted, this monitor cannot be retrieved."
|
||||||
>
|
>
|
||||||
<Stack
|
</Dialog>
|
||||||
gap={theme.spacing(2)}
|
|
||||||
sx={{
|
|
||||||
position: "absolute",
|
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
width: 400,
|
|
||||||
bgcolor: theme.palette.background.main,
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.border.light,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
boxShadow: 24,
|
|
||||||
p: theme.spacing(15),
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography id="modal-delete-monitor" component="h2" variant="h2">
|
|
||||||
Do you really want to delete this monitor?
|
|
||||||
</Typography>
|
|
||||||
<Typography id="delete-monitor-confirmation" variant="body1">
|
|
||||||
Once deleted, this monitor cannot be retrieved.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(12)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setIsOpen(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation(e);
|
|
||||||
handleRemove(e);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { ConfigBox } from "./styled";
|
|||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
import { settingsValidation } from "../../Validation/validation";
|
import { settingsValidation } from "../../Validation/validation";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
import Dialog from "../../Components/Dialog"
|
||||||
|
|
||||||
const SECONDS_PER_DAY = 86400;
|
const SECONDS_PER_DAY = 86400;
|
||||||
|
|
||||||
@@ -39,6 +40,8 @@ const Settings = ({ isAdmin }) => {
|
|||||||
});
|
});
|
||||||
const [version,setVersion]=useState("unknown");
|
const [version,setVersion]=useState("unknown");
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
|
||||||
|
const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -139,6 +142,8 @@ const Settings = ({ isAdmin }) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
createToast({ body: "Failed to clear stats" });
|
createToast({ body: "Failed to clear stats" });
|
||||||
|
} finally {
|
||||||
|
setIsOpen(deleteStatsMonitorsInitState)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -167,6 +172,8 @@ const Settings = ({ isAdmin }) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
createToast({ Body: "Failed to delete all monitors" });
|
createToast({ Body: "Failed to delete all monitors" });
|
||||||
|
} finally {
|
||||||
|
setIsOpen(deleteStatsMonitorsInitState)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -243,17 +250,30 @@ const Settings = ({ isAdmin }) => {
|
|||||||
/>
|
/>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography>Clear all stats. This is irreversible.</Typography>
|
<Typography>Clear all stats. This is irreversible.</Typography>
|
||||||
<LoadingButton
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
loading={isLoading || authIsLoading || checksIsLoading}
|
onClick={()=>setIsOpen({...deleteStatsMonitorsInitState, deleteStats: true})}
|
||||||
onClick={handleClearStats}
|
|
||||||
sx={{ mt: theme.spacing(4) }}
|
sx={{ mt: theme.spacing(4) }}
|
||||||
>
|
>
|
||||||
Clear all stats
|
Clear all stats
|
||||||
</LoadingButton>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<Dialog
|
||||||
|
modelTitle="model-clear-stats"
|
||||||
|
modelDescription="clear-stats-confirmation"
|
||||||
|
open={isOpen.deleteStats}
|
||||||
|
onClose={() => setIsOpen(deleteStatsMonitorsInitState)}
|
||||||
|
title="Do you want to clear all stats?"
|
||||||
|
confirmationBtnLbl="Yes, clear all stats"
|
||||||
|
confirmationBtnOnClick={handleClearStats}
|
||||||
|
cancelBtnLbl="Cancel"
|
||||||
|
cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)}
|
||||||
|
theme={theme}
|
||||||
|
isLoading={isLoading || authIsLoading || checksIsLoading}
|
||||||
|
>
|
||||||
|
</Dialog>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
@@ -283,13 +303,27 @@ const Settings = ({ isAdmin }) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
loading={isLoading || authIsLoading || checksIsLoading}
|
loading={isLoading || authIsLoading || checksIsLoading}
|
||||||
onClick={handleDeleteAllMonitors}
|
onClick={()=>setIsOpen({...deleteStatsMonitorsInitState, deleteMonitors: true})}
|
||||||
sx={{ mt: theme.spacing(4) }}
|
sx={{ mt: theme.spacing(4) }}
|
||||||
>
|
>
|
||||||
Remove all monitors
|
Remove all monitors
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<Dialog
|
||||||
|
modelTitle="model-delete-all-monitors"
|
||||||
|
modelDescription="delete-all-monitors-confirmation"
|
||||||
|
open={isOpen.deleteMonitors}
|
||||||
|
onClose={() => setIsOpen(deleteStatsMonitorsInitState)}
|
||||||
|
title="Do you want to remove all monitors?"
|
||||||
|
confirmationBtnLbl="Yes, clear all monitors"
|
||||||
|
confirmationBtnOnClick={handleDeleteAllMonitors}
|
||||||
|
cancelBtnLbl="Cancel"
|
||||||
|
cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)}
|
||||||
|
theme={theme}
|
||||||
|
isLoading={isLoading || authIsLoading || checksIsLoading}
|
||||||
|
>
|
||||||
|
</Dialog>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
|
|||||||
Reference in new issue
Block a user