Add update trigger for pause state
This commit is contained in:
1 parent
f32f994036
commit
d5acfd9e9e
4 files changed
+20
-9
No files matched your search
@@ -7,7 +7,7 @@ import useDebounce from "../../../../Utils/debounce";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Heading } from "../../../../Components/Heading";
|
import { Heading } from "../../../../Components/Heading";
|
||||||
|
|
||||||
const CurrentMonitoring = ({ totalMonitors, monitors, isAdmin }) => {
|
const CurrentMonitoring = ({ totalMonitors, monitors, isAdmin, handlePause }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
@@ -55,12 +55,14 @@ const CurrentMonitoring = ({ totalMonitors, monitors, isAdmin }) => {
|
|||||||
filter={debouncedFilter}
|
filter={debouncedFilter}
|
||||||
setIsSearching={setIsSearching}
|
setIsSearching={setIsSearching}
|
||||||
isSearching={isSearching}
|
isSearching={isSearching}
|
||||||
|
handlePause={handlePause}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentMonitoring.propTypes = {
|
CurrentMonitoring.propTypes = {
|
||||||
|
handlePause: PropTypes.func,
|
||||||
totalMonitors: PropTypes.number,
|
totalMonitors: PropTypes.number,
|
||||||
monitors: PropTypes.array,
|
monitors: PropTypes.array,
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
|||||||
|
|
||||||
import { Pagination } from "../../../Infrastructure/components/TablePagination";
|
import { Pagination } from "../../../Infrastructure/components/TablePagination";
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
|
const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching, handlePause }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -48,7 +48,7 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
|
|||||||
const [sort, setSort] = useState({});
|
const [sort, setSort] = useState({});
|
||||||
const prevFilter = useRef(filter);
|
const prevFilter = useRef(filter);
|
||||||
|
|
||||||
const handleActionMenuDelete = () => {
|
const handleRowUpdate = () => {
|
||||||
setUpdateTrigger((prev) => !prev);
|
setUpdateTrigger((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -297,7 +297,8 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
|
|||||||
<ActionsMenu
|
<ActionsMenu
|
||||||
monitor={monitor}
|
monitor={monitor}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
updateCallback={handleActionMenuDelete}
|
updateRowCallback={handleRowUpdate}
|
||||||
|
pauseCallback={handlePause}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -325,6 +326,7 @@ MonitorTable.propTypes = {
|
|||||||
filter: PropTypes.string,
|
filter: PropTypes.string,
|
||||||
setIsSearching: PropTypes.func,
|
setIsSearching: PropTypes.func,
|
||||||
isSearching: PropTypes.bool,
|
isSearching: PropTypes.bool,
|
||||||
|
setMonitorUpdateTrigger: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MemoizedMonitorTable = memo(MonitorTable);
|
const MemoizedMonitorTable = memo(MonitorTable);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Settings from "../../../assets/icons/settings-bold.svg?react";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import Dialog from "../../../Components/Dialog";
|
import Dialog from "../../../Components/Dialog";
|
||||||
|
|
||||||
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
const ActionsMenu = ({ monitor, isAdmin, updateRowCallback, pauseCallback }) => {
|
||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
const [actions, setActions] = useState({});
|
const [actions, setActions] = useState({});
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
@@ -47,9 +47,9 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
pauseUptimeMonitor({ authToken, monitorId: monitor._id })
|
pauseUptimeMonitor({ authToken, monitorId: monitor._id })
|
||||||
);
|
);
|
||||||
if (pauseUptimeMonitor.fulfilled.match(action)) {
|
if (pauseUptimeMonitor.fulfilled.match(action)) {
|
||||||
updateCallback();
|
|
||||||
const state = action?.payload?.data.isActive === false ? "paused" : "resumed";
|
const state = action?.payload?.data.isActive === false ? "paused" : "resumed";
|
||||||
createToast({ body: `Monitor ${state} successfully.` });
|
createToast({ body: `Monitor ${state} successfully.` });
|
||||||
|
pauseCallback();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(action?.error?.message ?? "Failed to pause monitor.");
|
throw new Error(action?.error?.message ?? "Failed to pause monitor.");
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,8 @@ ActionsMenu.propTypes = {
|
|||||||
isActive: PropTypes.bool,
|
isActive: PropTypes.bool,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
updateCallback: PropTypes.func,
|
updateRowCallback: PropTypes.func,
|
||||||
|
pauseCallback: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ActionsMenu;
|
export default ActionsMenu;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@@ -19,10 +19,15 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
const monitorState = useSelector((state) => state.uptimeMonitors);
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
|
const [monitorUpdateTrigger, setMonitorUpdateTrigger] = useState(false);
|
||||||
|
|
||||||
|
const handlePause = () => {
|
||||||
|
setMonitorUpdateTrigger((prev) => !prev);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch, monitorUpdateTrigger]);
|
||||||
|
|
||||||
//TODO bring fetching to this component, like on pageSpeed
|
//TODO bring fetching to this component, like on pageSpeed
|
||||||
|
|
||||||
@@ -92,6 +97,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
monitors={monitorState.monitorsSummary.monitors}
|
monitors={monitorState.monitorsSummary.monitors}
|
||||||
totalMonitors={totalMonitors}
|
totalMonitors={totalMonitors}
|
||||||
|
handlePause={handlePause}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user