fix: refactoring changes and removing unnecessary changes
This commit is contained in:
1 parent
c7d93311ce
commit
866388c09e
3 files changed
+30
-55
No files matched your search
@@ -4,7 +4,6 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
import Grid from "@mui/material/Grid";
|
import Grid from "@mui/material/Grid";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import { LAYOUT, SPACING } from "@/Utils/Theme/constants";
|
import { LAYOUT, SPACING } from "@/Utils/Theme/constants";
|
||||||
import { getPageSpeedGaugeColor } from "@/Utils/MonitorUtils";
|
import { getPageSpeedGaugeColor } from "@/Utils/MonitorUtils";
|
||||||
@@ -24,10 +23,9 @@ interface MetricConfig {
|
|||||||
|
|
||||||
const MetricItem = ({ label, progress }: MetricConfig) => {
|
const MetricItem = ({ label, progress }: MetricConfig) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("sm"));
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
size={isSmall ? 12 : 3}
|
size={{ xs: 12, md: 3 }}
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
@@ -35,8 +33,8 @@ const MetricItem = ({ label, progress }: MetricConfig) => {
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
gap: theme.spacing(SPACING.LG),
|
gap: theme.spacing(SPACING.LG),
|
||||||
padding: theme.spacing(LAYOUT.XS),
|
padding: theme.spacing(LAYOUT.XS),
|
||||||
borderRight: isSmall ? "none" : `1px solid ${theme.palette.divider}`,
|
borderRight: { xs: "none", md: `1px solid ${theme.palette.divider}` },
|
||||||
borderBottom: isSmall ? `1px solid ${theme.palette.divider}` : "none",
|
borderBottom: { xs: `1px solid ${theme.palette.divider}`, md: "none" },
|
||||||
"&:last-child": {
|
"&:last-child": {
|
||||||
borderRight: "none",
|
borderRight: "none",
|
||||||
borderBottom: "none",
|
borderBottom: "none",
|
||||||
@@ -64,40 +62,28 @@ const MetricItem = ({ label, progress }: MetricConfig) => {
|
|||||||
const buildMetrics = (
|
const buildMetrics = (
|
||||||
check: NonNullable<Monitor["recentChecks"]>[number],
|
check: NonNullable<Monitor["recentChecks"]>[number],
|
||||||
t: (key: string) => string
|
t: (key: string) => string
|
||||||
): MetricConfig[] => {
|
): MetricConfig[] => [
|
||||||
const metrics: MetricConfig[] = [];
|
{
|
||||||
|
key: "performance",
|
||||||
if (typeof check.performance === "number") {
|
label: t("pages.statusPages.monitorsList.pagespeed.performance"),
|
||||||
metrics.push({
|
progress: check.performance ?? 0,
|
||||||
key: "performance",
|
},
|
||||||
label: t("pages.statusPages.monitorsList.pagespeed.performance"),
|
{
|
||||||
progress: check.performance,
|
key: "accessibility",
|
||||||
});
|
label: t("pages.statusPages.monitorsList.pagespeed.accessibility"),
|
||||||
}
|
progress: check.accessibility ?? 0,
|
||||||
if (typeof check.accessibility === "number") {
|
},
|
||||||
metrics.push({
|
{
|
||||||
key: "accessibility",
|
key: "bestPractices",
|
||||||
label: t("pages.statusPages.monitorsList.pagespeed.accessibility"),
|
label: t("pages.statusPages.monitorsList.pagespeed.bestPractices"),
|
||||||
progress: check.accessibility,
|
progress: check.bestPractices ?? 0,
|
||||||
});
|
},
|
||||||
}
|
{
|
||||||
if (typeof check.bestPractices === "number") {
|
key: "seo",
|
||||||
metrics.push({
|
label: t("pages.statusPages.monitorsList.pagespeed.seo"),
|
||||||
key: "bestPractices",
|
progress: check.seo ?? 0,
|
||||||
label: t("pages.statusPages.monitorsList.pagespeed.bestPractices"),
|
},
|
||||||
progress: check.bestPractices,
|
];
|
||||||
});
|
|
||||||
}
|
|
||||||
if (typeof check.seo === "number") {
|
|
||||||
metrics.push({
|
|
||||||
key: "seo",
|
|
||||||
label: t("pages.statusPages.monitorsList.pagespeed.seo"),
|
|
||||||
progress: check.seo,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return metrics;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => {
|
export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -118,23 +104,12 @@ export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) =>
|
|||||||
|
|
||||||
const metrics = buildMetrics(latestCheck, t);
|
const metrics = buildMetrics(latestCheck, t);
|
||||||
|
|
||||||
if (metrics.length === 0) {
|
|
||||||
return (
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color={theme.palette.text.secondary}
|
|
||||||
>
|
|
||||||
{t("pages.statusPages.monitorsList.noData")}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
padding={theme.spacing(LAYOUT.LG)}
|
padding={theme.spacing(LAYOUT.LG)}
|
||||||
sx={{ flex: 1 }}
|
flex={1}
|
||||||
>
|
>
|
||||||
{metrics.map((metric) => (
|
{metrics.map((metric) => (
|
||||||
<MetricItem
|
<MetricItem
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { Monitor, MonitorType } from "@/Types/Monitor";
|
import type { Monitor, MonitorType } from "@/Types/Monitor";
|
||||||
export type MonitorDisplayType = "uptime" | "infrastructure" | "pagespeed";
|
export const MONITOR_DISPLAY_TYPES = ["uptime", "infrastructure", "pagespeed"] as const;
|
||||||
|
export type MonitorDisplayType = (typeof MONITOR_DISPLAY_TYPES)[number];
|
||||||
|
|
||||||
export const MONITOR_TYPE_KEYS: Partial<Record<MonitorType, string>> = {
|
export const MONITOR_TYPE_KEYS: Partial<Record<MonitorType, string>> = {
|
||||||
http: "pages.common.monitors.monitorTypes.optionHttp",
|
http: "pages.common.monitors.monitorTypes.optionHttp",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { MONITOR_DISPLAY_TYPES } from "@/Types/StatusPage";
|
||||||
|
|
||||||
export const statusPageSchema = z.object({
|
export const statusPageSchema = z.object({
|
||||||
companyName: z
|
companyName: z
|
||||||
@@ -14,9 +15,7 @@ export const statusPageSchema = z.object({
|
|||||||
"URL can only contain lowercase letters, numbers, and hyphens"
|
"URL can only contain lowercase letters, numbers, and hyphens"
|
||||||
),
|
),
|
||||||
timezone: z.string().optional(),
|
timezone: z.string().optional(),
|
||||||
type: z
|
type: z.array(z.enum(MONITOR_DISPLAY_TYPES)).min(1, "At least one type is required"),
|
||||||
.array(z.enum(["uptime", "infrastructure", "pagespeed"]))
|
|
||||||
.min(1, "At least one type is required"),
|
|
||||||
color: z.string().min(1, "Color is required"),
|
color: z.string().min(1, "Color is required"),
|
||||||
monitors: z.array(z.string()).min(1, "At least one monitor is required"),
|
monitors: z.array(z.string()).min(1, "At least one monitor is required"),
|
||||||
isPublished: z.boolean(),
|
isPublished: z.boolean(),
|
||||||
|
|||||||
Reference in new issue
Block a user