feat: simplify code and functionalities
This commit is contained in:
11 files changed
+23
-735
No files matched your search
@@ -1,55 +0,0 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||
import { typographyLevels } from "@/Utils/Theme/Palette";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { DashboardMonitorRow } from "@/Pages/Dashboard/types";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
|
||||
interface CurrentlyDownCardProps {
|
||||
downMonitors: DashboardMonitorRow[];
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const CurrentlyDownCard = ({
|
||||
downMonitors,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: CurrentlyDownCardProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<DashboardCard
|
||||
title={t("pages.dashboard.cards.currentlyDown")}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
dragHandleProps={dragHandleProps}
|
||||
>
|
||||
{downMonitors.length === 0 ? (
|
||||
<Typography
|
||||
fontSize={typographyLevels.m}
|
||||
color={theme.palette.text.secondary}
|
||||
>
|
||||
{t("pages.dashboard.emptyStates.allMonitorsUp")}
|
||||
</Typography>
|
||||
) : (
|
||||
<Stack gap={theme.spacing(1)}>
|
||||
{downMonitors.map((m) => (
|
||||
<Typography
|
||||
key={m.id}
|
||||
fontSize={typographyLevels.m}
|
||||
color={theme.palette.error.main}
|
||||
>
|
||||
{m.name}
|
||||
</Typography>
|
||||
))}
|
||||
</Stack>
|
||||
)}
|
||||
</DashboardCard>
|
||||
);
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||
import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { formatPercentageFromWhole } from "@/Utils/FormatUtils";
|
||||
import type { DashboardMonitorRow } from "@/Pages/Dashboard/types";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||
|
||||
const TOP_N = 5;
|
||||
|
||||
interface LowestUptimeCardProps {
|
||||
lowestUptimeMonitors: DashboardMonitorRow[];
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const LowestUptimeCard = ({
|
||||
lowestUptimeMonitors,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: LowestUptimeCardProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const top = lowestUptimeMonitors.slice(0, TOP_N);
|
||||
const total = lowestUptimeMonitors.length;
|
||||
|
||||
return (
|
||||
<DashboardCard
|
||||
title={t("pages.dashboard.cards.lowestUptime")}
|
||||
dragHandleProps={dragHandleProps}
|
||||
topRight={
|
||||
total > 0
|
||||
? t("pages.dashboard.emptyStates.topOf", {
|
||||
count: Math.min(TOP_N, total),
|
||||
total,
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
>
|
||||
<Stack gap={LAYOUT.SM}>
|
||||
{top.map((monitor) => {
|
||||
const uptime = monitor.uptimePercentage;
|
||||
const downtime = 100 - uptime;
|
||||
return (
|
||||
<BarRow
|
||||
key={monitor.id}
|
||||
label={monitor.name}
|
||||
value={formatPercentageFromWhole(uptime)}
|
||||
fillRatio={downtime / 100}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</DashboardCard>
|
||||
);
|
||||
};
|
||||
@@ -7,20 +7,16 @@ import { typographyLevels } from "@/Utils/Theme/Palette";
|
||||
import { SPACING } from "@/Utils/Theme/constants";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { MonitorsSummary } from "@/Types/Monitor";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
|
||||
interface MonitorStatusCardProps {
|
||||
summary: MonitorsSummary;
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const MonitorStatusCard = ({
|
||||
summary,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: MonitorStatusCardProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
@@ -34,7 +30,6 @@ export const MonitorStatusCard = ({
|
||||
title={t("pages.dashboard.cards.monitorStatus")}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
dragHandleProps={dragHandleProps}
|
||||
>
|
||||
<Stack gap={theme.spacing(SPACING.SM)}>
|
||||
<Stack
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||
import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
||||
import { typographyLevels } from "@/Utils/Theme/Palette";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { DashboardGroupCount } from "@/Pages/Dashboard/types";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||
|
||||
interface MonitorsByGroupCardProps {
|
||||
monitorsByGroup: DashboardGroupCount[];
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const MonitorsByGroupCard = ({
|
||||
monitorsByGroup,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: MonitorsByGroupCardProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const maxCount = monitorsByGroup[0]?.count ?? 1;
|
||||
|
||||
return (
|
||||
<DashboardCard
|
||||
title={t("pages.dashboard.cards.monitorsByGroup")}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
dragHandleProps={dragHandleProps}
|
||||
>
|
||||
{monitorsByGroup.length === 0 ? (
|
||||
<Typography
|
||||
fontSize={typographyLevels.m}
|
||||
color={theme.palette.text.secondary}
|
||||
>
|
||||
{t("pages.dashboard.emptyStates.noGroups")}
|
||||
</Typography>
|
||||
) : (
|
||||
<Stack gap={LAYOUT.SM}>
|
||||
{monitorsByGroup.map(({ group, count }) => (
|
||||
<BarRow
|
||||
key={group}
|
||||
label={group}
|
||||
value={String(count)}
|
||||
fillRatio={count / maxCount}
|
||||
valueColor={theme.palette.text.primary}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
)}
|
||||
</DashboardCard>
|
||||
);
|
||||
};
|
||||
@@ -4,21 +4,18 @@ import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import type { DashboardTypeCount } from "@/Pages/Dashboard/types";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||
|
||||
interface MonitorsByTypeCardProps {
|
||||
monitorsByType: DashboardTypeCount[];
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const MonitorsByTypeCard = ({
|
||||
monitorsByType,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: MonitorsByTypeCardProps) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
@@ -30,7 +27,6 @@ export const MonitorsByTypeCard = ({
|
||||
title={t("pages.dashboard.cards.monitorsByType")}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
dragHandleProps={dragHandleProps}
|
||||
>
|
||||
<Stack gap={LAYOUT.SM}>
|
||||
{monitorsByType.map(({ type, count }) => (
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import Stack from "@mui/material/Stack";
|
||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||
import { BarRow } from "@/Pages/Dashboard/components/cards/BarRow";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { formatMs } from "@/Utils/TimeUtils";
|
||||
import type { DashboardMonitorRow } from "@/Pages/Dashboard/types";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
||||
|
||||
const TOP_N = 5;
|
||||
|
||||
interface SlowestMonitorsCardProps {
|
||||
slowestMonitors: DashboardMonitorRow[];
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const SlowestMonitorsCard = ({
|
||||
slowestMonitors,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: SlowestMonitorsCardProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const top = slowestMonitors.slice(0, TOP_N);
|
||||
const maxAvg = top[0]?.avgResponseTime ?? 1;
|
||||
const total = slowestMonitors.length;
|
||||
|
||||
return (
|
||||
<DashboardCard
|
||||
title={t("pages.dashboard.cards.slowestMonitors")}
|
||||
dragHandleProps={dragHandleProps}
|
||||
topRight={
|
||||
total > 0
|
||||
? t("pages.dashboard.emptyStates.topOf", {
|
||||
count: Math.min(TOP_N, total),
|
||||
total,
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
>
|
||||
<Stack gap={LAYOUT.SM}>
|
||||
{top.map((m) => (
|
||||
<BarRow
|
||||
key={m.id}
|
||||
label={m.name}
|
||||
value={formatMs(m.avgResponseTime)}
|
||||
fillRatio={m.avgResponseTime / maxAvg}
|
||||
/>
|
||||
))}
|
||||
</Stack>
|
||||
</DashboardCard>
|
||||
);
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { DashboardCard } from "@/Pages/Dashboard/components/DashboardCard";
|
||||
import { typographyLevels } from "@/Utils/Theme/Palette";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { DashboardCardId } from "@/Pages/Dashboard/dashboardCards";
|
||||
import type { DraggableSyntheticListeners } from "@dnd-kit/core";
|
||||
|
||||
interface StubCardProps {
|
||||
cardId: DashboardCardId;
|
||||
isLoading?: boolean;
|
||||
error?: unknown;
|
||||
dragHandleProps?: DraggableSyntheticListeners;
|
||||
}
|
||||
|
||||
export const StubCard = ({
|
||||
cardId,
|
||||
isLoading,
|
||||
error,
|
||||
dragHandleProps,
|
||||
}: StubCardProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<DashboardCard
|
||||
title={t(`pages.dashboard.cards.${cardId}`)}
|
||||
isLoading={isLoading}
|
||||
error={error}
|
||||
dragHandleProps={dragHandleProps}
|
||||
>
|
||||
<Typography
|
||||
fontSize={typographyLevels.m}
|
||||
color={theme.palette.text.disabled}
|
||||
fontStyle="italic"
|
||||
>
|
||||
{t("pages.dashboard.comingSoon")}
|
||||
</Typography>
|
||||
</DashboardCard>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user