refactor: moving search loading state to onitorTable component
This commit is contained in:
1 parent
a517edfea3
commit
5adca16b55
3 files changed
+61
-62
No files matched your search
@@ -1,10 +1,10 @@
|
|||||||
import { Skeleton, TableBody, TableCell, TableRow } from "@mui/material";
|
import { Skeleton, TableCell, TableRow } from "@mui/material";
|
||||||
const ROWS_NUMBER = 7;
|
const ROWS_NUMBER = 7;
|
||||||
const ROWS_ARRAY = Array.from({ length: ROWS_NUMBER }, (_, i) => i);
|
const ROWS_ARRAY = Array.from({ length: ROWS_NUMBER }, (_, i) => i);
|
||||||
|
|
||||||
const TableBodySkeleton = () => {
|
const TableBodySkeleton = () => {
|
||||||
return (
|
return (
|
||||||
<TableBody>
|
<>
|
||||||
{ROWS_ARRAY.map((row) => (
|
{ROWS_ARRAY.map((row) => (
|
||||||
<TableRow key={row}>
|
<TableRow key={row}>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
@@ -24,7 +24,7 @@ const TableBodySkeleton = () => {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Typography,
|
Typography,
|
||||||
Button,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
|
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
|
||||||
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
||||||
@@ -108,7 +109,7 @@ TablePaginationActions.propTypes = {
|
|||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
const MonitorTable = ({ isAdmin, filter, setLoading, isSearching }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -221,7 +222,37 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<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>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
@@ -271,9 +302,10 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
<TableCell>Actions</TableCell>
|
<TableCell>Actions</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
{monitors.length > 0 ? (
|
<TableBody>
|
||||||
<TableBody>
|
{/* TODO add empty state. Check if is searching, and empty => skeleton. Is empty, not searching => skeleton */}
|
||||||
{monitors.map((monitor) => {
|
{monitors.length > 0 ? (
|
||||||
|
monitors.map((monitor) => {
|
||||||
let uptimePercentage = "";
|
let uptimePercentage = "";
|
||||||
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
||||||
|
|
||||||
@@ -343,11 +375,11 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})}
|
})
|
||||||
</TableBody>
|
) : (
|
||||||
) : (
|
<TableBodySkeleton />
|
||||||
<TableBodySkeleton />
|
)}
|
||||||
)}
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
<Stack
|
<Stack
|
||||||
@@ -420,7 +452,7 @@ const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -428,6 +460,7 @@ MonitorTable.propTypes = {
|
|||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
filter: PropTypes.string,
|
filter: PropTypes.string,
|
||||||
setLoading: PropTypes.func,
|
setLoading: PropTypes.func,
|
||||||
|
isSearching: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MemoizedMonitorTable = memo(MonitorTable);
|
const MemoizedMonitorTable = memo(MonitorTable);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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, CircularProgress, Stack, Typography } from "@mui/material";
|
import { Box, Button, 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";
|
||||||
@@ -36,17 +36,15 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
//Why are we tying loading to monitors length?
|
const loading = monitorState?.isLoading;
|
||||||
const loading =
|
|
||||||
monitorState?.isLoading; /* && monitorState?.monitorsSummary?.monitors?.length === 0 */
|
|
||||||
|
|
||||||
const hasMonitors = monitorState?.monitorsSummary?.monitors?.length !== 0;
|
const totalMonitors = monitorState?.monitorsSummary?.monitorCounts?.total;
|
||||||
const noMonitors = monitorState?.monitorsSummary?.monitors?.length === 0;
|
const isTotalMonitorsUndefined = totalMonitors === undefined;
|
||||||
|
const hasMonitors = !isTotalMonitorsUndefined && totalMonitors !== 0;
|
||||||
|
const noMonitors = isTotalMonitorsUndefined || totalMonitors === 0;
|
||||||
const canAddMonitor = isAdmin && hasMonitors;
|
const canAddMonitor = isAdmin && hasMonitors;
|
||||||
const needsAdmin = !isAdmin && noMonitors;
|
const needsAdmin = !isAdmin && noMonitors;
|
||||||
|
|
||||||
/* console.log({ loading });
|
|
||||||
console.log({ monitorState }); */
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
className="monitors"
|
className="monitors"
|
||||||
@@ -131,8 +129,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
borderColor={theme.palette.border.light}
|
borderColor={theme.palette.border.light}
|
||||||
backgroundColor={theme.palette.background.accent}
|
backgroundColor={theme.palette.background.accent}
|
||||||
>
|
>
|
||||||
{/* TODO maybe we dont need the conditional here, since we already check for monitors before */}
|
{totalMonitors}
|
||||||
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
width="25%"
|
width="25%"
|
||||||
@@ -140,50 +137,19 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
ml="auto"
|
ml="auto"
|
||||||
>
|
>
|
||||||
<Search
|
<Search
|
||||||
options={monitorState?.monitorsSummary?.monitors ?? []}
|
options={monitorState.monitorsSummary.monitors}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
inputValue={search}
|
inputValue={search}
|
||||||
handleInputChange={handleSearch}
|
handleInputChange={handleSearch}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box position="relative">
|
<MonitorTable
|
||||||
{isSearching && (
|
isAdmin={isAdmin}
|
||||||
<>
|
filter={debouncedFilter}
|
||||||
<Box
|
setLoading={setIsSearching}
|
||||||
width="100%"
|
isSearching={isSearching}
|
||||||
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