remove mock data and add redux state
This commit is contained in:
6 files changed
+83
-61
No files matched your search
@@ -9,41 +9,50 @@ import { useTranslation } from "react-i18next";
|
|||||||
import type { MonitorsSummary } from "@/Types/Monitor";
|
import type { MonitorsSummary } from "@/Types/Monitor";
|
||||||
|
|
||||||
interface MonitorStatusCardProps {
|
interface MonitorStatusCardProps {
|
||||||
summary: MonitorsSummary;
|
summary: MonitorsSummary | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MonitorStatusCard = ({ summary }: MonitorStatusCardProps) => {
|
export const MonitorStatusCard = ({ summary }: MonitorStatusCardProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const up = summary.upMonitors;
|
const up = summary?.upMonitors ?? 0;
|
||||||
const total = summary.totalMonitors;
|
const total = summary?.totalMonitors ?? 0;
|
||||||
const ratio = total > 0 ? up / total : 0;
|
const ratio = total > 0 ? up / total : 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardCard title={t("pages.dashboard.cards.monitorStatus")}>
|
<DashboardCard title={t("pages.dashboard.cards.monitorStatus")}>
|
||||||
<Stack gap={theme.spacing(SPACING.SM)}>
|
{total === 0 ? (
|
||||||
<Stack
|
<Typography
|
||||||
direction="row"
|
fontSize={typographyLevels.m}
|
||||||
alignItems="baseline"
|
color={theme.palette.text.disabled}
|
||||||
gap={theme.spacing(SPACING.XS)}
|
|
||||||
>
|
>
|
||||||
<Typography
|
{t("pages.dashboard.noData")}
|
||||||
fontSize={typographyLevels.xxl}
|
</Typography>
|
||||||
fontWeight={500}
|
) : (
|
||||||
color={theme.palette.text.primary}
|
<Stack gap={theme.spacing(SPACING.SM)}>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="baseline"
|
||||||
|
gap={theme.spacing(SPACING.XS)}
|
||||||
>
|
>
|
||||||
{up}
|
<Typography
|
||||||
</Typography>
|
fontSize={typographyLevels.xxl}
|
||||||
<Typography
|
fontWeight={500}
|
||||||
fontSize={typographyLevels.m}
|
color={theme.palette.text.primary}
|
||||||
color={theme.palette.text.secondary}
|
>
|
||||||
>
|
{up}
|
||||||
{t("pages.dashboard.monitorStatus.ofUp", { total })}
|
</Typography>
|
||||||
</Typography>
|
<Typography
|
||||||
|
fontSize={typographyLevels.m}
|
||||||
|
color={theme.palette.text.secondary}
|
||||||
|
>
|
||||||
|
{t("pages.dashboard.monitorStatus.ofUp", { total })}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<ProgressBar fillRatio={ratio} />
|
||||||
</Stack>
|
</Stack>
|
||||||
<ProgressBar fillRatio={ratio} />
|
)}
|
||||||
</Stack>
|
|
||||||
</DashboardCard>
|
</DashboardCard>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||||
import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import type { DashboardTypeCount } from "@/Pages/Dashboard/types";
|
import type { MonitorTypeCount } from "@/Types/Monitor";
|
||||||
import { getMonitorTypeLabel } from "@/Types/Monitor";
|
import { getMonitorTypeLabel } from "@/Types/Monitor";
|
||||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||||
|
import { typographyLevels } from "@/Utils/Theme/Palette";
|
||||||
|
|
||||||
interface MonitorsByTypeCardProps {
|
interface MonitorsByTypeCardProps {
|
||||||
monitorsByType: DashboardTypeCount[];
|
monitorsByType: MonitorTypeCount[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MonitorsByTypeCard = ({ monitorsByType }: MonitorsByTypeCardProps) => {
|
export const MonitorsByTypeCard = ({ monitorsByType }: MonitorsByTypeCardProps) => {
|
||||||
@@ -19,17 +21,26 @@ export const MonitorsByTypeCard = ({ monitorsByType }: MonitorsByTypeCardProps)
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardCard title={t("pages.dashboard.cards.monitorsByType")}>
|
<DashboardCard title={t("pages.dashboard.cards.monitorsByType")}>
|
||||||
<Stack gap={theme.spacing(LAYOUT.SM)}>
|
{monitorsByType.length === 0 ? (
|
||||||
{monitorsByType.map(({ type, count }) => (
|
<Typography
|
||||||
<BarRow
|
fontSize={typographyLevels.m}
|
||||||
key={type}
|
color={theme.palette.text.disabled}
|
||||||
label={getMonitorTypeLabel(type, t)}
|
>
|
||||||
value={String(count)}
|
{t("pages.dashboard.noData")}
|
||||||
fillRatio={count / maxCount}
|
</Typography>
|
||||||
valueColor={theme.palette.text.primary}
|
) : (
|
||||||
/>
|
<Stack gap={theme.spacing(LAYOUT.SM)}>
|
||||||
))}
|
{monitorsByType.map(({ type, count }) => (
|
||||||
</Stack>
|
<BarRow
|
||||||
|
key={type}
|
||||||
|
label={getMonitorTypeLabel(type, t)}
|
||||||
|
value={String(count)}
|
||||||
|
fillRatio={count / maxCount}
|
||||||
|
valueColor={theme.palette.text.primary}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
</DashboardCard>
|
</DashboardCard>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,32 +1,34 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
|
||||||
import { BasePage } from "@/Components/design-elements/BasePage";
|
import { BasePage } from "@/Components/design-elements/BasePage";
|
||||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||||
|
import { useMonitorListController } from "@/Hooks/useMonitorListController";
|
||||||
|
import { MonitorTypes, type MonitorTypeCount } from "@/Types/Monitor";
|
||||||
|
|
||||||
import { MonitorStatusCard } from "@/Pages/Dashboard/components/cards/MonitorStatusCard";
|
import { MonitorStatusCard } from "@/Pages/Dashboard/components/cards/MonitorStatusCard";
|
||||||
import { MonitorsByTypeCard } from "@/Pages/Dashboard/components/cards/MonitorsByTypeCard";
|
import { MonitorsByTypeCard } from "@/Pages/Dashboard/components/cards/MonitorsByTypeCard";
|
||||||
import type { MonitorsSummary } from "@/Types/Monitor";
|
|
||||||
import type { DashboardTypeCount } from "@/Pages/Dashboard/types";
|
|
||||||
|
|
||||||
const MOCK_SUMMARY: MonitorsSummary = {
|
|
||||||
totalMonitors: 12,
|
|
||||||
upMonitors: 10,
|
|
||||||
downMonitors: 1,
|
|
||||||
pausedMonitors: 1,
|
|
||||||
initializingMonitors: 0,
|
|
||||||
maintenanceMonitors: 0,
|
|
||||||
breachedMonitors: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MOCK_MONITORS_BY_TYPE: DashboardTypeCount[] = [
|
|
||||||
{ type: "http", count: 7 },
|
|
||||||
{ type: "ping", count: 3 },
|
|
||||||
{ type: "port", count: 2 },
|
|
||||||
];
|
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { monitors, summary } = useMonitorListController({
|
||||||
|
types: [...MonitorTypes],
|
||||||
|
checksLimit: 1,
|
||||||
|
refreshInterval: 30000,
|
||||||
|
rowsPerPageTable: "monitors",
|
||||||
|
rowsPerPageDefault: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
const monitorsByType = useMemo<MonitorTypeCount[]>(() => {
|
||||||
|
const countMap = new Map<MonitorTypeCount["type"], number>();
|
||||||
|
(monitors ?? []).forEach((m) =>
|
||||||
|
countMap.set(m.type, (countMap.get(m.type) ?? 0) + 1)
|
||||||
|
);
|
||||||
|
return [...countMap.entries()]
|
||||||
|
.map(([type, count]) => ({ type, count }))
|
||||||
|
.sort((a, b) => b.count - a.count);
|
||||||
|
}, [monitors]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasePage headerKey="dashboard">
|
<BasePage headerKey="dashboard">
|
||||||
@@ -35,8 +37,8 @@ const Dashboard = () => {
|
|||||||
gridTemplateColumns={{ xs: "1fr", md: "1fr 1fr" }}
|
gridTemplateColumns={{ xs: "1fr", md: "1fr 1fr" }}
|
||||||
gap={theme.spacing(LAYOUT.MD)}
|
gap={theme.spacing(LAYOUT.MD)}
|
||||||
>
|
>
|
||||||
<MonitorStatusCard summary={MOCK_SUMMARY} />
|
<MonitorStatusCard summary={summary} />
|
||||||
<MonitorsByTypeCard monitorsByType={MOCK_MONITORS_BY_TYPE} />
|
<MonitorsByTypeCard monitorsByType={monitorsByType} />
|
||||||
</Box>
|
</Box>
|
||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import type { MonitorType } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
export interface DashboardTypeCount {
|
|
||||||
type: MonitorType;
|
|
||||||
count: number;
|
|
||||||
}
|
|
||||||
@@ -192,6 +192,11 @@ export interface MonitorsSummary {
|
|||||||
breachedMonitors: number;
|
breachedMonitors: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MonitorTypeCount {
|
||||||
|
type: MonitorType;
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MonitorsWithChecksResponse {
|
export interface MonitorsWithChecksResponse {
|
||||||
count: number;
|
count: number;
|
||||||
monitors: MonitorWithChecks[];
|
monitors: MonitorWithChecks[];
|
||||||
|
|||||||
@@ -1911,6 +1911,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
|
"noData": "No data available at this moment.",
|
||||||
"monitorStatus": {
|
"monitorStatus": {
|
||||||
"ofUp": "of {{total}} up"
|
"ofUp": "of {{total}} up"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user