use new query in infra page
This commit is contained in:
1 parent
e616df2766
commit
bde4269fd1
1 file changed
+12
-17
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { /* useDispatch, */ useSelector } from "react-redux";
|
import { /* useDispatch, */ useSelector } from "react-redux";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
@@ -50,12 +50,13 @@ function Infrastructure() {
|
|||||||
setRowsPerPage(parseInt(event.target.value));
|
setRowsPerPage(parseInt(event.target.value));
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
const [monitorState, setMonitorState] = useState({ monitors: [], total: 0 });
|
const [monitors, setMonitors] = useState([]);
|
||||||
|
const [summary, setSummary] = useState({});
|
||||||
|
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const user = jwtDecode(authToken);
|
const user = jwtDecode(authToken);
|
||||||
|
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const response = await networkService.getMonitorsByTeamId({
|
const response = await networkService.getMonitorsByTeamId({
|
||||||
@@ -63,29 +64,23 @@ function Infrastructure() {
|
|||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
types: ["hardware"],
|
types: ["hardware"],
|
||||||
status: null,
|
|
||||||
checkOrder: "desc",
|
|
||||||
normalize: true,
|
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
});
|
});
|
||||||
setMonitorState({
|
setMonitors(response?.data?.data?.monitors ?? []);
|
||||||
monitors: response?.data?.data?.monitors ?? [],
|
setSummary(response?.data?.data?.summary ?? {});
|
||||||
total: response?.data?.data?.monitorCount ?? 0,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
}, [page, rowsPerPage, authToken, user.teamId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [page, rowsPerPage]);
|
}, [fetchMonitors]);
|
||||||
|
|
||||||
const { determineState } = useUtils();
|
const { determineState } = useUtils();
|
||||||
const { monitors, total: totalMonitors } = monitorState;
|
|
||||||
// do it here
|
// do it here
|
||||||
function openDetails(id) {
|
function openDetails(id) {
|
||||||
navigate(`/infrastructure/${id}`);
|
navigate(`/infrastructure/${id}`);
|
||||||
@@ -191,7 +186,7 @@ function Infrastructure() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let isActuallyLoading = isLoading && monitorState.monitors?.length === 0;
|
let isActuallyLoading = isLoading && monitors?.length === 0;
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="infrastructure-monitor"
|
className="infrastructure-monitor"
|
||||||
@@ -209,7 +204,7 @@ function Infrastructure() {
|
|||||||
>
|
>
|
||||||
{isActuallyLoading ? (
|
{isActuallyLoading ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : monitorState.monitors?.length !== 0 ? (
|
) : monitors?.length !== 0 ? (
|
||||||
<Stack gap={theme.spacing(8)}>
|
<Stack gap={theme.spacing(8)}>
|
||||||
<Box>
|
<Box>
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
@@ -254,7 +249,7 @@ function Infrastructure() {
|
|||||||
borderColor={theme.palette.border.light}
|
borderColor={theme.palette.border.light}
|
||||||
backgroundColor={theme.palette.background.accent}
|
backgroundColor={theme.palette.background.accent}
|
||||||
>
|
>
|
||||||
{totalMonitors}
|
{summary?.totalMonitors ?? 0}
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
@@ -272,7 +267,7 @@ function Infrastructure() {
|
|||||||
data={monitorsAsRows}
|
data={monitorsAsRows}
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
monitorCount={totalMonitors}
|
monitorCount={summary?.totalMonitors ?? 0}
|
||||||
page={page}
|
page={page}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
handleChangePage={handleChangePage}
|
handleChangePage={handleChangePage}
|
||||||
|
|||||||
Reference in new issue
Block a user