Added loading indicator to monitor table on search
This commit is contained in:
1 parent
0556876f29
commit
59adc526fe
2 files changed
+54
-4
No files matched your search
@@ -108,7 +108,7 @@ TablePaginationActions.propTypes = {
|
|||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin, filter }) => {
|
const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -161,6 +161,7 @@ const MonitorTable = ({ isAdmin, filter }) => {
|
|||||||
});
|
});
|
||||||
setMonitors(res?.data?.data?.monitors ?? []);
|
setMonitors(res?.data?.data?.monitors ?? []);
|
||||||
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
||||||
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ 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";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Box, Button, Stack, Typography } from "@mui/material";
|
import {
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
CircularProgress,
|
||||||
|
Stack,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import Fallback from "./fallback";
|
import Fallback from "./fallback";
|
||||||
@@ -21,12 +27,19 @@ 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 [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
const [isSearching, setIsSearching] = useState("");
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
const debouncedFilter = useDebounce(search, 500);
|
const debouncedFilter = useDebounce(search, 500);
|
||||||
|
|
||||||
|
const handleSearch = (value) => {
|
||||||
|
setIsSearching(true);
|
||||||
|
setSearch(value);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
let loading =
|
let loading =
|
||||||
monitorState?.isLoading &&
|
monitorState?.isLoading &&
|
||||||
monitorState?.monitorsSummary?.monitors?.length === 0;
|
monitorState?.monitorsSummary?.monitors?.length === 0;
|
||||||
@@ -124,11 +137,47 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
options={monitorState?.monitorsSummary.monitors}
|
options={monitorState?.monitorsSummary.monitors}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
value={search}
|
value={search}
|
||||||
handleInputChange={setSearch}
|
handleInputChange={handleSearch}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<MonitorTable isAdmin={isAdmin} filter={debouncedFilter} />
|
<Box position="relative">
|
||||||
|
{isSearching && (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.background.main,
|
||||||
|
opacity: 0.8,
|
||||||
|
zIndex: 100,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Box
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
top="20%"
|
||||||
|
left="50%"
|
||||||
|
sx={{
|
||||||
|
transform: "translateX(-50%)",
|
||||||
|
zIndex: 101,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CircularProgress
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.other.icon,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<MonitorTable
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
filter={debouncedFilter}
|
||||||
|
setLoading={setIsSearching}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in new issue
Block a user