From 866388c09e433c2bb8ee7e7c23e423cb9541e2f7 Mon Sep 17 00:00:00 2001 From: mannilakash Date: Mon, 30 Mar 2026 13:00:20 -0400 Subject: [PATCH] fix: refactoring changes and removing unnecessary changes --- .../Status/Components/PageSpeedMetrics.tsx | 77 +++++++------------ client/src/Types/StatusPage.ts | 3 +- client/src/Validation/statusPage.ts | 5 +- 3 files changed, 30 insertions(+), 55 deletions(-) diff --git a/client/src/Pages/StatusPage/Status/Components/PageSpeedMetrics.tsx b/client/src/Pages/StatusPage/Status/Components/PageSpeedMetrics.tsx index 2693ca751..3b658a33f 100644 --- a/client/src/Pages/StatusPage/Status/Components/PageSpeedMetrics.tsx +++ b/client/src/Pages/StatusPage/Status/Components/PageSpeedMetrics.tsx @@ -4,7 +4,6 @@ import { useTheme } from "@mui/material/styles"; import { useTranslation } from "react-i18next"; import type { Monitor } from "@/Types/Monitor"; import Grid from "@mui/material/Grid"; -import useMediaQuery from "@mui/material/useMediaQuery"; import Box from "@mui/material/Box"; import { LAYOUT, SPACING } from "@/Utils/Theme/constants"; import { getPageSpeedGaugeColor } from "@/Utils/MonitorUtils"; @@ -24,10 +23,9 @@ interface MetricConfig { const MetricItem = ({ label, progress }: MetricConfig) => { const theme = useTheme(); - const isSmall = useMediaQuery(theme.breakpoints.down("sm")); return ( { textAlign: "center", gap: theme.spacing(SPACING.LG), padding: theme.spacing(LAYOUT.XS), - borderRight: isSmall ? "none" : `1px solid ${theme.palette.divider}`, - borderBottom: isSmall ? `1px solid ${theme.palette.divider}` : "none", + borderRight: { xs: "none", md: `1px solid ${theme.palette.divider}` }, + borderBottom: { xs: `1px solid ${theme.palette.divider}`, md: "none" }, "&:last-child": { borderRight: "none", borderBottom: "none", @@ -64,40 +62,28 @@ const MetricItem = ({ label, progress }: MetricConfig) => { const buildMetrics = ( check: NonNullable[number], t: (key: string) => string -): MetricConfig[] => { - const metrics: MetricConfig[] = []; - - if (typeof check.performance === "number") { - metrics.push({ - key: "performance", - label: t("pages.statusPages.monitorsList.pagespeed.performance"), - progress: check.performance, - }); - } - if (typeof check.accessibility === "number") { - metrics.push({ - key: "accessibility", - label: t("pages.statusPages.monitorsList.pagespeed.accessibility"), - progress: check.accessibility, - }); - } - if (typeof check.bestPractices === "number") { - metrics.push({ - key: "bestPractices", - 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; -}; +): MetricConfig[] => [ + { + key: "performance", + label: t("pages.statusPages.monitorsList.pagespeed.performance"), + progress: check.performance ?? 0, + }, + { + key: "accessibility", + label: t("pages.statusPages.monitorsList.pagespeed.accessibility"), + progress: check.accessibility ?? 0, + }, + { + key: "bestPractices", + label: t("pages.statusPages.monitorsList.pagespeed.bestPractices"), + progress: check.bestPractices ?? 0, + }, + { + key: "seo", + label: t("pages.statusPages.monitorsList.pagespeed.seo"), + progress: check.seo ?? 0, + }, +]; export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => { const theme = useTheme(); @@ -118,23 +104,12 @@ export const PageSpeedMetrics = ({ monitor }: { monitor: StatusPageMonitor }) => const metrics = buildMetrics(latestCheck, t); - if (metrics.length === 0) { - return ( - - {t("pages.statusPages.monitorsList.noData")} - - ); - } - return ( {metrics.map((metric) => ( > = { http: "pages.common.monitors.monitorTypes.optionHttp", diff --git a/client/src/Validation/statusPage.ts b/client/src/Validation/statusPage.ts index b5fe9b861..beffa98be 100644 --- a/client/src/Validation/statusPage.ts +++ b/client/src/Validation/statusPage.ts @@ -1,4 +1,5 @@ import { z } from "zod"; +import { MONITOR_DISPLAY_TYPES } from "@/Types/StatusPage"; export const statusPageSchema = z.object({ companyName: z @@ -14,9 +15,7 @@ export const statusPageSchema = z.object({ "URL can only contain lowercase letters, numbers, and hyphens" ), timezone: z.string().optional(), - type: z - .array(z.enum(["uptime", "infrastructure", "pagespeed"])) - .min(1, "At least one type is required"), + type: z.array(z.enum(MONITOR_DISPLAY_TYPES)).min(1, "At least one type is required"), color: z.string().min(1, "Color is required"), monitors: z.array(z.string()).min(1, "At least one monitor is required"), isPublished: z.boolean(),