refactor: moving search loading state to onitorTable component

This commit is contained in:
Caio Cabral committed 2024-10-18 15:45:50 -04:00
1 parent a517edfea3
commit 5adca16b55
3 files changed
+61 -62

No files matched your search

+14 -48
View File
@@ -4,7 +4,7 @@ import { useSelector, useDispatch } from "react-redux";
import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
import { useNavigate } from "react-router-dom";
import { useTheme } from "@emotion/react";
import { Box, Button, CircularProgress, Stack, Typography } from "@mui/material";
import { Box, Button, Stack, Typography } from "@mui/material";
import PropTypes from "prop-types";
import SkeletonLayout from "./skeleton";
import Fallback from "./fallback";
@@ -36,17 +36,15 @@ const Monitors = ({ isAdmin }) => {
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
}, [authState.authToken, dispatch]);
//Why are we tying loading to monitors length?
const loading =
monitorState?.isLoading; /* && monitorState?.monitorsSummary?.monitors?.length === 0 */
const loading = monitorState?.isLoading;
const hasMonitors = monitorState?.monitorsSummary?.monitors?.length !== 0;
const noMonitors = monitorState?.monitorsSummary?.monitors?.length === 0;
const totalMonitors = monitorState?.monitorsSummary?.monitorCounts?.total;
const isTotalMonitorsUndefined = totalMonitors === undefined;
const hasMonitors = !isTotalMonitorsUndefined && totalMonitors !== 0;
const noMonitors = isTotalMonitorsUndefined || totalMonitors === 0;
const canAddMonitor = isAdmin && hasMonitors;
const needsAdmin = !isAdmin && noMonitors;
/* console.log({ loading });
console.log({ monitorState }); */
return (
<Stack
className="monitors"
@@ -131,8 +129,7 @@ const Monitors = ({ isAdmin }) => {
borderColor={theme.palette.border.light}
backgroundColor={theme.palette.background.accent}
>
{/* TODO maybe we dont need the conditional here, since we already check for monitors before */}
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
{totalMonitors}
</Box>
<Box
width="25%"
@@ -140,50 +137,19 @@ const Monitors = ({ isAdmin }) => {
ml="auto"
>
<Search
options={monitorState?.monitorsSummary?.monitors ?? []}
options={monitorState.monitorsSummary.monitors}
filteredBy="name"
inputValue={search}
handleInputChange={handleSearch}
/>
</Box>
</Stack>
<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>
<MonitorTable
isAdmin={isAdmin}
filter={debouncedFilter}
setLoading={setIsSearching}
isSearching={isSearching}
/>
</Box>
</>
)}