remove unused
This commit is contained in:
1 parent
45ef2438de
commit
cbd0530d85
12 files changed
+28
-1075
No files matched your search
@@ -1,100 +0,0 @@
|
|||||||
import { Checkbox, FormControl, ListItemText, MenuItem, Select } from "@mui/material";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A reusable filter header component that displays a dropdown menu with selectable options.
|
|
||||||
*
|
|
||||||
* @component
|
|
||||||
* @param {Object} props - The component props.
|
|
||||||
* @param {string} props.header - The header text to display when no options are selected.
|
|
||||||
* @param {Array} props.options - An array of options to display in the dropdown menu. Each option should have a `value` and `label`.
|
|
||||||
* @param {Array} [props.value] - The currently selected values.
|
|
||||||
* @param {Function} props.onChange - The callback function to handle changes in the selected values.
|
|
||||||
* @param {boolean} [props.multiple=true] - Whether multiple options can be selected.
|
|
||||||
* @returns {JSX.Element} The rendered FilterHeader component.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const FilterHeader = ({ header, options, value, onChange, multiple = true }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const controlledValue = value === undefined ? [] : value; // Ensure value is always treated as an array for controlled component purposes
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FormControl
|
|
||||||
sx={{ minWidth: "10%" }}
|
|
||||||
size="small"
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
multiple={multiple}
|
|
||||||
IconComponent={(props) => (
|
|
||||||
<Icon
|
|
||||||
{...props}
|
|
||||||
name="PlusCircle"
|
|
||||||
size={18}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
displayEmpty
|
|
||||||
value={controlledValue}
|
|
||||||
onChange={onChange}
|
|
||||||
renderValue={(selected) => {
|
|
||||||
if (!selected?.length) {
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
header +
|
|
||||||
" | " +
|
|
||||||
selected
|
|
||||||
.map((value) => options.find((option) => option.value === value)?.label)
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(", ")
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
MenuProps={{
|
|
||||||
anchorOrigin: {
|
|
||||||
vertical: "bottom",
|
|
||||||
horizontal: "left",
|
|
||||||
},
|
|
||||||
transformOrigin: {
|
|
||||||
vertical: "top",
|
|
||||||
horizontal: "left",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{options.map((option) => (
|
|
||||||
<MenuItem
|
|
||||||
key={option.value}
|
|
||||||
value={option.value}
|
|
||||||
sx={{
|
|
||||||
height: theme.spacing(17),
|
|
||||||
padding: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Checkbox
|
|
||||||
checked={controlledValue.includes(option.value)}
|
|
||||||
size="small"
|
|
||||||
/>
|
|
||||||
<ListItemText primary={option.label} />
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
FilterHeader.propTypes = {
|
|
||||||
header: PropTypes.string.isRequired,
|
|
||||||
options: PropTypes.arrayOf(
|
|
||||||
PropTypes.shape({
|
|
||||||
value: PropTypes.string.isRequired,
|
|
||||||
label: PropTypes.string.isRequired,
|
|
||||||
})
|
|
||||||
).isRequired,
|
|
||||||
value: PropTypes.arrayOf(PropTypes.string),
|
|
||||||
onChange: PropTypes.func.isRequired,
|
|
||||||
multiple: PropTypes.bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FilterHeader;
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
import * as React from "react";
|
|
||||||
import Button from "@mui/material/Button";
|
|
||||||
import ButtonGroup from "@mui/material/ButtonGroup";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
|
||||||
import Grow from "@mui/material/Grow";
|
|
||||||
import Paper from "@mui/material/Paper";
|
|
||||||
import Popper from "@mui/material/Popper";
|
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
|
||||||
import MenuList from "@mui/material/MenuList";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { createToast } from "../../../Utils/toastUtils.jsx";
|
|
||||||
import { useExportMonitors } from "../../../Hooks/monitorHooks.js";
|
|
||||||
|
|
||||||
const MonitorActions = ({ isLoading }) => {
|
|
||||||
const [open, setOpen] = React.useState(false);
|
|
||||||
const anchorRef = React.useRef(null);
|
|
||||||
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [exportMonitors, isExporting] = useExportMonitors();
|
|
||||||
|
|
||||||
const options = [t("monitorActions.import"), t("monitorActions.export")];
|
|
||||||
|
|
||||||
const handleClick = async () => {
|
|
||||||
if (selectedIndex === 0) {
|
|
||||||
// Import
|
|
||||||
navigate("/uptime/bulk-import");
|
|
||||||
} else {
|
|
||||||
// Export
|
|
||||||
const [success, error] = await exportMonitors();
|
|
||||||
if (!success) {
|
|
||||||
createToast({ body: error || t("export.failed") });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMenuItemClick = (event, index) => {
|
|
||||||
setSelectedIndex(index);
|
|
||||||
setOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleToggle = () => {
|
|
||||||
setOpen((prevOpen) => !prevOpen);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = (event) => {
|
|
||||||
if (anchorRef.current && anchorRef.current.contains(event.target)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<React.Fragment>
|
|
||||||
<ButtonGroup
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
ref={anchorRef}
|
|
||||||
aria-label="Monitor actions"
|
|
||||||
disabled={isLoading || isExporting}
|
|
||||||
>
|
|
||||||
<Button onClick={handleClick}>{options[selectedIndex]}</Button>
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
aria-controls={open ? "split-button-menu" : undefined}
|
|
||||||
aria-expanded={open ? "true" : undefined}
|
|
||||||
aria-label="select monitor action"
|
|
||||||
aria-haspopup="menu"
|
|
||||||
onClick={handleToggle}
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
name="ChevronDown"
|
|
||||||
size={20}
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
<Popper
|
|
||||||
sx={{ zIndex: 1 }}
|
|
||||||
open={open}
|
|
||||||
anchorEl={anchorRef.current}
|
|
||||||
role={undefined}
|
|
||||||
transition
|
|
||||||
disablePortal
|
|
||||||
>
|
|
||||||
{({ TransitionProps, placement }) => (
|
|
||||||
<Grow
|
|
||||||
{...TransitionProps}
|
|
||||||
style={{
|
|
||||||
transformOrigin: placement === "bottom" ? "center top" : "center bottom",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Paper>
|
|
||||||
<ClickAwayListener onClickAway={handleClose}>
|
|
||||||
<MenuList
|
|
||||||
id="split-button-menu"
|
|
||||||
autoFocusItem
|
|
||||||
>
|
|
||||||
{options.map((option, index) => (
|
|
||||||
<MenuItem
|
|
||||||
key={option}
|
|
||||||
selected={index === selectedIndex}
|
|
||||||
onClick={(event) => handleMenuItemClick(event, index)}
|
|
||||||
>
|
|
||||||
{option}
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</MenuList>
|
|
||||||
</ClickAwayListener>
|
|
||||||
</Paper>
|
|
||||||
</Grow>
|
|
||||||
)}
|
|
||||||
</Popper>
|
|
||||||
</React.Fragment>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MonitorActions;
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { Stack, Typography } from "@mui/material";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import SkeletonLayout from "./skeleton.jsx";
|
|
||||||
|
|
||||||
const MonitorCountHeader = ({
|
|
||||||
isLoading = false,
|
|
||||||
monitorCount,
|
|
||||||
heading = "monitors",
|
|
||||||
sx,
|
|
||||||
children,
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
if (isLoading) return <SkeletonLayout />;
|
|
||||||
|
|
||||||
if (monitorCount === 1) {
|
|
||||||
heading = "monitor";
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
display="flex"
|
|
||||||
width="fit-content"
|
|
||||||
height={theme.spacing(18)}
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
mt={theme.spacing(2)}
|
|
||||||
px={theme.spacing(4)}
|
|
||||||
pt={theme.spacing(2)}
|
|
||||||
pb={theme.spacing(3)}
|
|
||||||
borderRadius={theme.spacing(1)}
|
|
||||||
sx={{
|
|
||||||
...sx,
|
|
||||||
backgroundColor: theme.palette.secondary.main,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitorCount} <Typography component="h2">{heading}</Typography>
|
|
||||||
{children}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
MonitorCountHeader.propTypes = {
|
|
||||||
isLoading: PropTypes.bool,
|
|
||||||
monitorCount: PropTypes.number,
|
|
||||||
heading: PropTypes.string,
|
|
||||||
children: PropTypes.node,
|
|
||||||
sx: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MonitorCountHeader;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { Stack, Skeleton } from "@mui/material";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
|
|
||||||
const SkeletonLayout = () => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
variant="text"
|
|
||||||
width={100}
|
|
||||||
height={32}
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
variant="circular"
|
|
||||||
width={40}
|
|
||||||
height={40}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SkeletonLayout;
|
|
||||||
@@ -3,7 +3,6 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import MonitorActions from "../MonitorActions/index.jsx";
|
|
||||||
|
|
||||||
const CreateMonitorHeader = ({ isAdmin, label, isLoading = true, path, bulkPath }) => {
|
const CreateMonitorHeader = ({ isAdmin, label, isLoading = true, path, bulkPath }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Status from "./status.jsx";
|
|
||||||
import Skeleton from "./skeleton.jsx";
|
|
||||||
import Button from "@mui/material/Button";
|
|
||||||
import { Tooltip } from "@mui/material";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import { usePauseMonitor } from "../../../Hooks/monitorHooks.js";
|
|
||||||
import { useSendTestEmail } from "../../../Hooks/useSendTestEmail.js";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useTestAllNotifications } from "../../../Hooks/useNotifications.js";
|
|
||||||
/**
|
|
||||||
* MonitorDetailsControlHeader component displays the control header for monitor details.
|
|
||||||
* It includes status display, pause/resume button, and a configure button for admins.
|
|
||||||
*
|
|
||||||
* @component
|
|
||||||
* @param {Object} props - Component props
|
|
||||||
* @param {string} props.path - The base path for navigation
|
|
||||||
* @param {boolean} [props.isLoading=false] - Flag indicating if the data is loading
|
|
||||||
* @param {boolean} [props.isAdmin=false] - Flag indicating if the user is an admin
|
|
||||||
* @param {Object} props.monitor - The monitor object containing details
|
|
||||||
* @param {Function} props.triggerUpdate - Function to trigger an update
|
|
||||||
* @returns {JSX.Element} The rendered component
|
|
||||||
*/
|
|
||||||
const MonitorDetailsControlHeader = ({
|
|
||||||
path,
|
|
||||||
isLoading = false,
|
|
||||||
isAdmin = false,
|
|
||||||
monitor,
|
|
||||||
triggerUpdate,
|
|
||||||
}) => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [pauseMonitor, isPausing, error] = usePauseMonitor();
|
|
||||||
|
|
||||||
const isTestNotificationsDisabled = monitor?.notifications?.length === 0;
|
|
||||||
|
|
||||||
const tooltipTitle = isTestNotificationsDisabled ? t("testNotificationsDisabled") : "";
|
|
||||||
|
|
||||||
// const [isSending, emailError, sendTestEmail] = useSendTestEmail();
|
|
||||||
|
|
||||||
const [testAllNotifications, isSending, errorAllNotifications] =
|
|
||||||
useTestAllNotifications();
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return <Skeleton />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
>
|
|
||||||
<Status monitor={monitor} />
|
|
||||||
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Tooltip
|
|
||||||
key={monitor?.id}
|
|
||||||
placement="bottom"
|
|
||||||
title={tooltipTitle}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
loading={isSending}
|
|
||||||
startIcon={
|
|
||||||
<Icon
|
|
||||||
name="Mail"
|
|
||||||
size={18}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
disabled={isTestNotificationsDisabled}
|
|
||||||
onClick={() => {
|
|
||||||
testAllNotifications({ monitorId: monitor?.id });
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("sendTestNotifications")}
|
|
||||||
</Button>
|
|
||||||
</span>
|
|
||||||
</Tooltip>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
onClick={(e) => {
|
|
||||||
navigate(`/incidents/${monitor?.id}`);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("menu.incidents")}
|
|
||||||
</Button>
|
|
||||||
{isAdmin && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
loading={isPausing}
|
|
||||||
startIcon={
|
|
||||||
monitor?.isActive ? (
|
|
||||||
<Icon
|
|
||||||
name="Pause"
|
|
||||||
size={18}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Icon
|
|
||||||
name="Play"
|
|
||||||
size={18}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
pauseMonitor({
|
|
||||||
monitorId: monitor?.id,
|
|
||||||
triggerUpdate,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitor?.isActive ? t("pause") : t("resume")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{isAdmin && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
startIcon={
|
|
||||||
<Icon
|
|
||||||
name="Settings"
|
|
||||||
size={18}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
|
||||||
>
|
|
||||||
Configure
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
MonitorDetailsControlHeader.propTypes = {
|
|
||||||
path: PropTypes.string,
|
|
||||||
isLoading: PropTypes.bool,
|
|
||||||
isAdmin: PropTypes.bool,
|
|
||||||
monitor: PropTypes.object,
|
|
||||||
triggerUpdate: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MonitorDetailsControlHeader;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { Stack, Skeleton } from "@mui/material";
|
|
||||||
|
|
||||||
const SkeletonLayout = () => {
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
>
|
|
||||||
<Skeleton
|
|
||||||
height={40}
|
|
||||||
variant="rounded"
|
|
||||||
width="15%"
|
|
||||||
/>
|
|
||||||
<Skeleton
|
|
||||||
height={40}
|
|
||||||
variant="rounded"
|
|
||||||
width="15%"
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SkeletonLayout;
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// Components
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import PulseDot from "../Animated/PulseDot.jsx";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Dot from "../Dot/index.jsx";
|
|
||||||
// Utils
|
|
||||||
import { formatDurationRounded } from "../../../Utils/timeUtilsLegacy.js";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils.js";
|
|
||||||
import { formatMonitorUrl } from "../../../Utils/utils.js";
|
|
||||||
/**
|
|
||||||
* Status component displays the status information of a monitor.
|
|
||||||
* It includes the monitor's name, URL, and check interval.
|
|
||||||
*
|
|
||||||
* @component
|
|
||||||
* @param {Object} props - Component props
|
|
||||||
* @param {Object} props.monitor - The monitor object containing details
|
|
||||||
* @param {string} props.monitor.name - The name of the monitor
|
|
||||||
* @param {string} props.monitor.url - The URL of the monitor
|
|
||||||
* @param {number} props.monitor.interval - The interval at which the monitor checks
|
|
||||||
* @returns {JSX.Element} The rendered component
|
|
||||||
*/
|
|
||||||
const Status = ({ monitor }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { statusColor, determineState } = useMonitorUtils();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack>
|
|
||||||
<Typography variant="monitorName">{monitor?.name}</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems={"center"}
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
>
|
|
||||||
<PulseDot color={statusColor[determineState(monitor)]} />
|
|
||||||
<Typography variant="monitorUrl">{formatMonitorUrl(monitor?.url)}</Typography>
|
|
||||||
<Dot />
|
|
||||||
<Typography>
|
|
||||||
Checking every {formatDurationRounded(monitor?.interval)}.
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Status.propTypes = {
|
|
||||||
monitor: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Status;
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
// Components
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Divider from "@mui/material/Divider";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
import Search from "../Inputs/Search/index.jsx";
|
|
||||||
|
|
||||||
// Utils
|
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
|
|
||||||
const NotificationConfig = ({
|
|
||||||
notifications,
|
|
||||||
setMonitor,
|
|
||||||
setNotifications,
|
|
||||||
//FieldWrapper's props
|
|
||||||
gap,
|
|
||||||
labelMb,
|
|
||||||
labelFontWeight,
|
|
||||||
labelVariant,
|
|
||||||
labelSx = {},
|
|
||||||
sx = {},
|
|
||||||
}) => {
|
|
||||||
// Local state
|
|
||||||
const [notificationsSearch, setNotificationsSearch] = useState("");
|
|
||||||
const [selectedNotifications, setSelectedNotifications] = useState([]);
|
|
||||||
|
|
||||||
const handleSearch = (value) => {
|
|
||||||
setSelectedNotifications(value);
|
|
||||||
setMonitor((prev) => {
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
notifications: value.map((notification) => notification.id),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handlers
|
|
||||||
const handleDelete = (id) => {
|
|
||||||
const updatedNotifications = selectedNotifications.filter(
|
|
||||||
(notification) => notification.id !== id
|
|
||||||
);
|
|
||||||
|
|
||||||
setSelectedNotifications(updatedNotifications);
|
|
||||||
setMonitor((prev) => {
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
notifications: updatedNotifications.map((notification) => notification.id),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Setup
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (setNotifications) {
|
|
||||||
const toSet = setNotifications.map((notification) => {
|
|
||||||
return notifications.find((n) => n.id === notification);
|
|
||||||
});
|
|
||||||
setSelectedNotifications(toSet);
|
|
||||||
}
|
|
||||||
}, [setNotifications, notifications]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack gap={theme.spacing(6)}>
|
|
||||||
<Search
|
|
||||||
type="notifications"
|
|
||||||
label="Notifications"
|
|
||||||
options={notifications}
|
|
||||||
filteredBy="notificationName"
|
|
||||||
multiple={true}
|
|
||||||
value={selectedNotifications}
|
|
||||||
inputValue={notificationsSearch}
|
|
||||||
handleInputChange={setNotificationsSearch}
|
|
||||||
handleChange={(value) => {
|
|
||||||
handleSearch(value);
|
|
||||||
}}
|
|
||||||
labelMb={labelMb}
|
|
||||||
labelVariant={labelVariant}
|
|
||||||
labelFontWeight={labelFontWeight}
|
|
||||||
labelSx={labelSx}
|
|
||||||
gap={gap}
|
|
||||||
sx={{
|
|
||||||
...sx,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
flex={1}
|
|
||||||
width="100%"
|
|
||||||
>
|
|
||||||
{selectedNotifications.map((notification, index) => (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
key={notification.id}
|
|
||||||
width="100%"
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
flexGrow={1} // <-- This will take up all available horizontal space
|
|
||||||
>
|
|
||||||
{notification.notificationName}
|
|
||||||
</Typography>
|
|
||||||
<Icon
|
|
||||||
name="Trash2"
|
|
||||||
size={20}
|
|
||||||
onClick={() => {
|
|
||||||
handleDelete(notification.id);
|
|
||||||
}}
|
|
||||||
style={{ cursor: "pointer" }}
|
|
||||||
/>
|
|
||||||
{index < selectedNotifications.length - 1 && <Divider />}
|
|
||||||
</Stack>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
NotificationConfig.propTypes = {
|
|
||||||
notifications: PropTypes.array,
|
|
||||||
setMonitor: PropTypes.func,
|
|
||||||
setNotifications: PropTypes.array,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default NotificationConfig;
|
|
||||||
@@ -159,14 +159,14 @@ export const HeaderDeleteControls = ({
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
startIcon={<Icon icon={Trash} />}
|
startIcon={<Icon icon={Trash} />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onDelete?.();
|
onDelete?.();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("common.buttons.delete")}
|
{t("common.buttons.delete")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -15,13 +15,7 @@ interface SelectInputProps<T> extends Omit<SelectProps<T>, "label"> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SelectInputInner = <T,>(
|
const SelectInputInner = <T,>(
|
||||||
{
|
{ fieldLabel, required, placeholder, placeholderColor, ...props }: SelectInputProps<T>,
|
||||||
fieldLabel,
|
|
||||||
required,
|
|
||||||
placeholder,
|
|
||||||
placeholderColor,
|
|
||||||
...props
|
|
||||||
}: SelectInputProps<T>,
|
|
||||||
ref: React.ForwardedRef<HTMLDivElement>
|
ref: React.ForwardedRef<HTMLDivElement>
|
||||||
) => {
|
) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
@@ -1,107 +1,8 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { networkService } from "../main.jsx";
|
import { networkService } from "../main.jsx";
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
import { createToast } from "../Utils/toastUtils.jsx";
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { useMonitorUtils } from "./useMonitorUtils.js";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [monitors, setMonitors] = useState(undefined);
|
|
||||||
const [monitorsSummary, setMonitorsSummary] = useState(undefined);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitors = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getMonitorsWithSummaryByTeamId({
|
|
||||||
types,
|
|
||||||
});
|
|
||||||
const { monitors, summary } = res?.data?.data ?? {};
|
|
||||||
setMonitors(monitors);
|
|
||||||
setMonitorsSummary(summary);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitors();
|
|
||||||
}, [types, monitorUpdateTrigger]);
|
|
||||||
return [monitors, monitorsSummary, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchMonitorsWithChecks = ({
|
|
||||||
types,
|
|
||||||
limit,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
filter,
|
|
||||||
field,
|
|
||||||
order,
|
|
||||||
monitorUpdateTrigger,
|
|
||||||
}) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [count, setCount] = useState(undefined);
|
|
||||||
const [monitors, setMonitors] = useState(undefined);
|
|
||||||
const [summary, setSummary] = useState(undefined);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
const theme = useTheme();
|
|
||||||
const { getMonitorWithPercentage } = useMonitorUtils();
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitors = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getMonitorsWithChecksByTeamId({
|
|
||||||
limit,
|
|
||||||
types,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
filter,
|
|
||||||
field,
|
|
||||||
order,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { count, monitors, summary } = res?.data?.data ?? {};
|
|
||||||
const mappedMonitors = monitors.map((monitor) =>
|
|
||||||
getMonitorWithPercentage(monitor, theme)
|
|
||||||
);
|
|
||||||
setSummary(summary);
|
|
||||||
setMonitors(mappedMonitors);
|
|
||||||
setCount(count || 0);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitors();
|
|
||||||
}, [
|
|
||||||
field,
|
|
||||||
filter,
|
|
||||||
getMonitorWithPercentage,
|
|
||||||
limit,
|
|
||||||
order,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
theme,
|
|
||||||
types,
|
|
||||||
monitorUpdateTrigger,
|
|
||||||
]);
|
|
||||||
return [summary, monitors, count, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [monitors, setMonitors] = useState(undefined);
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
@@ -132,225 +33,17 @@ export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
|||||||
return [monitors, isLoading, networkError];
|
return [monitors, isLoading, networkError];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useFetchStatsByMonitorId = ({
|
|
||||||
monitorId,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
numToDisplay,
|
|
||||||
normalize,
|
|
||||||
updateTrigger,
|
|
||||||
}) => {
|
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
|
||||||
const [audits, setAudits] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitor = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getStatsByMonitorId({
|
|
||||||
monitorId: monitorId,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
numToDisplay,
|
|
||||||
normalize,
|
|
||||||
});
|
|
||||||
setMonitor(res?.data?.data ?? undefined);
|
|
||||||
setAudits(res?.data?.data?.checks?.[0]?.audits ?? undefined);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitor();
|
|
||||||
}, [monitorId, dateRange, numToDisplay, normalize, sortOrder, limit, updateTrigger]);
|
|
||||||
return [monitor, audits, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchMonitorGames = ({ setGames, updateTrigger }) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchGames = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getMonitorGames();
|
|
||||||
setGames(res.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchGames();
|
|
||||||
}, [setGames, updateTrigger]);
|
|
||||||
return [isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
useEffect(() => {
|
|
||||||
if (typeof monitorId === "undefined") {
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const fetchMonitor = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
|
||||||
setMonitor(res.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitor();
|
|
||||||
}, [monitorId, setMonitor, updateTrigger]);
|
|
||||||
return [isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchHardwareMonitorById = ({ monitorId, dateRange, updateTrigger }) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitor = async () => {
|
|
||||||
try {
|
|
||||||
if (!monitorId) {
|
|
||||||
return { monitor: undefined, isLoading: false, networkError: undefined };
|
|
||||||
}
|
|
||||||
const response = await networkService.getHardwareDetailsByMonitorId({
|
|
||||||
monitorId: monitorId,
|
|
||||||
dateRange: dateRange,
|
|
||||||
});
|
|
||||||
setMonitor(response.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitor();
|
|
||||||
}, [monitorId, dateRange, updateTrigger]);
|
|
||||||
return [monitor, isLoading, networkError];
|
|
||||||
};
|
|
||||||
export const useFetchPageSpeedMonitorById = ({ monitorId, dateRange, updateTrigger }) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
|
||||||
const [monitorStats, setMonitorStats] = useState(undefined);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitor = async () => {
|
|
||||||
try {
|
|
||||||
if (!monitorId) {
|
|
||||||
return { monitor: undefined, isLoading: false, networkError: undefined };
|
|
||||||
}
|
|
||||||
const response = await networkService.getPageSpeedDetailsByMonitorId({
|
|
||||||
monitorId: monitorId,
|
|
||||||
dateRange: dateRange,
|
|
||||||
});
|
|
||||||
setMonitor(response.data.data.monitor);
|
|
||||||
setMonitorStats(response.data.data.monitorStats);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitor();
|
|
||||||
}, [monitorId, dateRange, updateTrigger]);
|
|
||||||
return [monitor, monitorStats, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchUptimeMonitorById = ({ monitorId, dateRange, trigger }) => {
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [monitor, setMonitor] = useState(undefined);
|
|
||||||
const [monitorStats, setMonitorStats] = useState(undefined);
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitors = async () => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.getUptimeDetailsById({
|
|
||||||
monitorId: monitorId,
|
|
||||||
dateRange: dateRange,
|
|
||||||
normalize: true,
|
|
||||||
});
|
|
||||||
const { monitorData, monitorStats } = res?.data?.data ?? {};
|
|
||||||
setMonitor(monitorData);
|
|
||||||
setMonitorStats(monitorStats);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitors();
|
|
||||||
}, [dateRange, monitorId, trigger]);
|
|
||||||
return [monitor, monitorStats, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useCreateMonitor = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const createMonitor = async ({ monitor, redirect }) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await networkService.createMonitor({ monitor });
|
|
||||||
createToast({ body: "Monitor created successfully!" });
|
|
||||||
if (redirect) {
|
|
||||||
navigate(redirect);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: "Failed to create monitor." });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return [createMonitor, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchGlobalSettings = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [globalSettings, setGlobalSettings] = useState(undefined);
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchGlobalSettings = async () => {
|
|
||||||
try {
|
|
||||||
const res = await networkService.getAppSettings();
|
|
||||||
setGlobalSettings(res?.data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch global settings:", error);
|
|
||||||
createToast({ body: "Failed to load global settings" });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchGlobalSettings();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return [globalSettings, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useDeleteMonitor = () => {
|
export const useDeleteMonitor = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const { t } = useTranslation();
|
||||||
const deleteMonitor = async ({ monitor, redirect }) => {
|
const deleteMonitor = async (monitorId, successCallback = () => {}) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await networkService.deleteMonitorById({ monitorId: monitor.id });
|
await networkService.deleteMonitorById({ monitorId });
|
||||||
createToast({ body: "Monitor deleted successfully!" });
|
successCallback();
|
||||||
if (redirect) {
|
createToast({ body: t("monitorDeleted") });
|
||||||
navigate(redirect);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({ body: "Failed to delete monitor." });
|
createToast({ body: t("failedDeleteMonitor") });
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -358,68 +51,24 @@ export const useDeleteMonitor = () => {
|
|||||||
return [deleteMonitor, isLoading];
|
return [deleteMonitor, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useUpdateMonitor = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const updateMonitor = async ({ monitor, redirect }) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const updatedFields = {
|
|
||||||
name: monitor.name,
|
|
||||||
statusWindowSize: monitor.statusWindowSize,
|
|
||||||
statusWindowThreshold: monitor.statusWindowThreshold,
|
|
||||||
description: monitor.description,
|
|
||||||
interval: monitor.interval,
|
|
||||||
notifications: monitor.notifications,
|
|
||||||
matchMethod: monitor.matchMethod,
|
|
||||||
expectedValue: monitor.expectedValue,
|
|
||||||
ignoreTlsErrors: monitor.ignoreTlsErrors,
|
|
||||||
jsonPath: monitor.jsonPath,
|
|
||||||
...((monitor.type === "port" || monitor.type === "game") && {
|
|
||||||
port: monitor.port,
|
|
||||||
}),
|
|
||||||
...(monitor.type == "game" && {
|
|
||||||
gameId: monitor.gameId,
|
|
||||||
}),
|
|
||||||
...(monitor.type === "hardware" && {
|
|
||||||
thresholds: monitor.thresholds,
|
|
||||||
secret: monitor.secret,
|
|
||||||
selectedDisks: monitor.selectedDisks,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
await networkService.updateMonitor({
|
|
||||||
monitorId: monitor.id,
|
|
||||||
updatedFields,
|
|
||||||
});
|
|
||||||
|
|
||||||
createToast({ body: "Monitor updated successfully!" });
|
|
||||||
if (redirect) {
|
|
||||||
navigate(redirect);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: "Failed to update monitor." });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return [updateMonitor, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const usePauseMonitor = () => {
|
export const usePauseMonitor = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState(undefined);
|
const [error, setError] = useState(null);
|
||||||
const pauseMonitor = async ({ monitorId, triggerUpdate }) => {
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const pauseMonitor = async (monitorId, successCallback = () => {}) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await networkService.pauseMonitorById({ monitorId });
|
const res = await networkService.pauseMonitorById({ monitorId });
|
||||||
createToast({
|
successCallback();
|
||||||
body: res.data.data.isActive
|
if (res.data.data.isActive === false) {
|
||||||
? "Monitor resumed successfully"
|
createToast({ body: t("monitorPaused") });
|
||||||
: "Monitor paused successfully",
|
} else {
|
||||||
});
|
createToast({ body: t("monitorResumed") });
|
||||||
triggerUpdate();
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error);
|
setError(error.message);
|
||||||
|
createToast({ body: t("failedPauseMonitor") });
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -491,7 +140,7 @@ export const useCreateBulkMonitors = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await networkService.createBulkMonitors(formData);
|
const response = await networkService.createBulkMonitors(formData);
|
||||||
return [true, response.data, null]; // [success, data, error]
|
return [true, response.data, null];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err?.response?.data?.msg || err.message;
|
const errorMessage = err?.response?.data?.msg || err.message;
|
||||||
return [false, null, errorMessage];
|
return [false, null, errorMessage];
|
||||||
@@ -503,39 +152,6 @@ export const useCreateBulkMonitors = () => {
|
|||||||
return [createBulkMonitors, isLoading];
|
return [createBulkMonitors, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useExportMonitors = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const exportMonitors = async () => {
|
|
||||||
setIsLoading(true);
|
|
||||||
try {
|
|
||||||
const response = await networkService.exportMonitors();
|
|
||||||
|
|
||||||
// Create a download link
|
|
||||||
const url = window.URL.createObjectURL(response.data);
|
|
||||||
const link = document.createElement("a");
|
|
||||||
link.href = url;
|
|
||||||
link.setAttribute("download", "monitors.csv");
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
link.remove();
|
|
||||||
window.URL.revokeObjectURL(url);
|
|
||||||
|
|
||||||
createToast({ body: t("export.success") });
|
|
||||||
return [true, null];
|
|
||||||
} catch (err) {
|
|
||||||
const errorMessage = err?.response?.data?.msg || err.message;
|
|
||||||
createToast({ body: errorMessage || t("export.failed") });
|
|
||||||
return [false, errorMessage];
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [exportMonitors, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useFetchJson = () => {
|
export const useFetchJson = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const fetchJson = async () => {
|
const fetchJson = async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user