diff --git a/client/src/Components/v2/actions-menu/index.tsx b/client/src/Components/v2/actions-menu/index.tsx new file mode 100644 index 000000000..3b2f3688a --- /dev/null +++ b/client/src/Components/v2/actions-menu/index.tsx @@ -0,0 +1,56 @@ +import React, { useState } from "react"; +import Menu from "@mui/material/Menu"; +import MenuItem from "@mui/material/MenuItem"; +import IconButton from "@mui/material/IconButton"; +import { Settings } from "lucide-react"; + +export type ActionMenuItem = { + id: number | string; + label: React.ReactNode; + action: Function; + closeMenu?: boolean; +}; + +export const ActionsMenu = ({ items }: { items: ActionMenuItem[] }) => { + const [anchorEl, setAnchorEl] = useState(null); + const open = Boolean(anchorEl); + + const handleClick = (e: React.MouseEvent) => { + e.stopPropagation(); + setAnchorEl(e.currentTarget); + }; + + const handleClose = (e: React.MouseEvent) => { + e.stopPropagation(); + setAnchorEl(null); + }; + + return ( +
+ + + + + {items.map((item) => ( + ) => { + e.stopPropagation(); + if (item.closeMenu) handleClose(e); + item.action(); + }} + > + {item.label} + + ))} + +
+ ); +}; diff --git a/client/src/Components/v2/common/charts/HeatmapResponseTime.tsx b/client/src/Components/v2/common/charts/HeatmapResponseTime.tsx new file mode 100644 index 000000000..97289ba43 --- /dev/null +++ b/client/src/Components/v2/common/charts/HeatmapResponseTime.tsx @@ -0,0 +1,140 @@ +import Box from "@mui/material/Box"; +import { useTheme } from "@mui/material/styles"; +import type { Check } from "@/Types/Check"; +import { getResponseColor } from "@/Utils/DataUtils"; +import { HeatmapResponseTimeTooltip } from "@/Components/v2/common/charts/HeatmapResponseTimeTooltip"; +import type { SxProps } from "@mui/material/styles"; +import type { ResponsiveStyleValue } from "@mui/system"; + +interface PlaceholderCheck { + status: "placeholder"; + responseTime: 0; + createdAt: ""; +} + +interface HeatmapResponseTimeProps { + checks: Check[]; + gap?: ResponsiveStyleValue; + availabilityCellSx?: SxProps; + responseCellSx?: SxProps; +} + +export const HeatmapResponseTime = ({ + checks, + gap, + availabilityCellSx, + responseCellSx, +}: HeatmapResponseTimeProps) => { + const theme = useTheme(); + if (!gap) { + gap = theme.spacing(0.5); + } + + if (!checks || checks.length === 0) return null; + + const latestChecks = checks.slice(-25).reverse(); + + let data: Array; + if (latestChecks.length !== 25) { + const placeholders = Array(25 - latestChecks.length).fill({ + status: "placeholder" as const, + }); + data = [...latestChecks, ...placeholders]; + } else { + data = latestChecks; + } + return ( + + + {data.map((check, index) => { + const statusBg = + check.status === "placeholder" + ? theme.palette.action.hover + : check.status === true + ? theme.palette.success.light + : theme.palette.error.light; + const respBg = + check.status === "placeholder" + ? theme.palette.action.hover + : getResponseColor(check.responseTime || 0, { + start: theme.palette.success.main, + mid: theme.palette.warning.main, + end: theme.palette.error.main, + }); + const statusBorder = + check.status === "placeholder" + ? theme.palette.divider + : check.status === true + ? theme.palette.success.main + : theme.palette.error.main; + + return ( + + + + + + + + + + + + ); + })} + + + ); +}; diff --git a/client/src/Components/v2/common/charts/HeatmapResponseTimeTooltip.tsx b/client/src/Components/v2/common/charts/HeatmapResponseTimeTooltip.tsx new file mode 100644 index 000000000..448a60e49 --- /dev/null +++ b/client/src/Components/v2/common/charts/HeatmapResponseTimeTooltip.tsx @@ -0,0 +1,71 @@ +import Stack from "@mui/material/Stack"; +import Tooltip from "@mui/material/Tooltip"; +import Typography from "@mui/material/Typography"; +import { formatDateWithTz } from "@/Utils/TimeUtils"; +import type { Check } from "@/Types/Check"; +import { useTheme } from "@mui/material/styles"; +import { useSelector } from "react-redux"; +import type { RootState } from "@/Types/state"; + +type HeatmapCheck = Check | { status: "placeholder"; responseTime: 0; createdAt: "" }; + +export const HeatmapResponseTimeTooltip = ({ + children, + check, +}: { + children: React.ReactElement; + check: HeatmapCheck; +}) => { + const uiTimezone = useSelector((state: RootState) => state.ui.timezone); + const theme = useTheme(); + + const getColor = (status: boolean) => { + if (status === true) return theme.palette.success.light; + if (status === false) return theme.palette.error.light; + }; + + if (check.status === "placeholder") { + return children; + } + + return ( + + + {formatDateWithTz(check?.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone)} + + {check?.originalResponseTime && ( + + Response Time: {check.originalResponseTime.toFixed()} ms + + )} + + + Status:{" "} + {check?.status} + + + } + > + {children} + + ); +}; diff --git a/client/src/Components/v2/common/charts/HistogramResponseTime.tsx b/client/src/Components/v2/common/charts/HistogramResponseTime.tsx new file mode 100644 index 000000000..bbe3bd9d4 --- /dev/null +++ b/client/src/Components/v2/common/charts/HistogramResponseTime.tsx @@ -0,0 +1,102 @@ +import Box from "@mui/material/Box"; +import { useTheme } from "@mui/material/styles"; +import type { ResponsiveStyleValue } from "@mui/system"; +import type { Check } from "@/Types/Check"; +import { HeatmapResponseTimeTooltip } from "./HeatmapResponseTimeTooltip"; + +interface HistogramResponseTimeProps { + checks: Check[]; + height?: ResponsiveStyleValue; + gap?: ResponsiveStyleValue; +} + +const DEFAULT_HEIGHT = 50; + +export const HistogramResponseTime = ({ + checks, + height = DEFAULT_HEIGHT, + gap, +}: HistogramResponseTimeProps) => { + const theme = useTheme(); + + if (!Array.isArray(checks) || checks.length === 0) return null; + + let data = Array(); + + if (!checks || checks.length === 0) { + data = []; + } + if (checks.length !== 25) { + const placeholders = Array(25 - checks.length).fill({ + status: "placeholder", + }); + data = [...checks, ...placeholders]; + } else { + data = checks; + } + const chartHeight = typeof height === "number" ? `${height}px` : height; + const gridGap = gap ?? theme.spacing(0.5); + return ( + + + {data.map((check, index) => { + const isPlaceholder = (check as any).status === "placeholder"; + const heightPct = `${Math.max(0, Math.min(100, (check as any).responseTime ?? 0))}%`; + const barColor = + check.status === true + ? theme.palette.success.light + : theme.palette.error.light; + const bar = ( + + + + ); + + return isPlaceholder ? ( + + {bar} + + ) : ( + + {bar} + + ); + })} + + + ); +}; diff --git a/client/src/Components/v2/common/controls/HeaderCreate.tsx b/client/src/Components/v2/common/controls/HeaderCreate.tsx new file mode 100644 index 000000000..8234cc8ed --- /dev/null +++ b/client/src/Components/v2/common/controls/HeaderCreate.tsx @@ -0,0 +1,47 @@ +import { Stack } from "@mui/material"; +import { useNavigate } from "react-router-dom"; +import { ButtonInput } from "../../inputs/Button"; +import { useTranslation } from "react-i18next"; + +interface HeaderCreateProps { + label?: string; + path: string; + isLoading?: boolean; + isAdmin?: boolean; +} + +export const HeaderCreate = ({ + label, + path, + isLoading = false, + isAdmin = false, +}: HeaderCreateProps) => { + const navigate = useNavigate(); + const { t } = useTranslation(); + + if (!isAdmin) { + return null; + } + + const handleClick = () => { + navigate(path); + }; + + return ( + + + {label || t("common.buttons.create")} + + + ); +}; diff --git a/client/src/Components/v2/common/index.ts b/client/src/Components/v2/common/index.ts new file mode 100644 index 000000000..e354983eb --- /dev/null +++ b/client/src/Components/v2/common/index.ts @@ -0,0 +1,4 @@ +export * from "../common/charts/HistogramResponseTime"; +export * from "../common/charts/HeatmapResponseTime"; +export * from "../common/charts/HeatmapResponseTimeTooltip"; +export * from "../common/controls/HeaderCreate"; diff --git a/client/src/Components/v2/design-elements/BaseBox.tsx b/client/src/Components/v2/design-elements/BaseBox.tsx new file mode 100644 index 000000000..580d15dcf --- /dev/null +++ b/client/src/Components/v2/design-elements/BaseBox.tsx @@ -0,0 +1,19 @@ +import Box, { type BoxProps } from "@mui/material/Box"; +import { useTheme } from "@mui/material/styles"; + +export const BaseBox = ({ sx, ...rest }: BoxProps) => { + const theme = useTheme(); + return ( + + ); +}; diff --git a/client/src/Components/v2/design-elements/BasePage.tsx b/client/src/Components/v2/design-elements/BasePage.tsx new file mode 100644 index 000000000..c853a8d30 --- /dev/null +++ b/client/src/Components/v2/design-elements/BasePage.tsx @@ -0,0 +1,159 @@ +import Stack from "@mui/material/Stack"; +import { + ErrorFallback, + EmptyFallback, + EmptyMonitorFallback, +} from "@/Components/v2/design-elements/Fallback"; +import { Breadcrumb } from "@/Components/v2/design-elements/Breadcrumb"; +import CircularProgress from "@mui/material/CircularProgress"; + +import type { StackProps } from "@mui/material/Stack"; +import { useTheme } from "@mui/material/styles"; +import { useTranslation } from "react-i18next"; +interface BasePageProps extends StackProps { + loading?: boolean; + error?: boolean; + children: React.ReactNode; + breadcrumbOverride?: string[]; +} + +export const BasePage = ({ + loading, + error, + children, + breadcrumbOverride, + ...props +}: BasePageProps) => { + const theme = useTheme(); + + if (loading) { + return ( + + + + ); + } + + if (error) { + return ( + + ); + } + + return ( + + + {children} + + ); +}; + +interface BasePageWithStatesProps extends StackProps { + loading: boolean; + error: any; + items: any[]; + bullets: string[] | unknown; + page: string; + actionButtonText: string; + actionLink: string; + children: React.ReactNode; +} + +export const BasePageWithStates = ({ + loading, + error, + items, + page, + bullets, + actionButtonText, + actionLink, + children, + ...props +}: BasePageWithStatesProps) => { + const showLoading = loading && (!items || items.length === 0); + + if (isEmpty(items)) { + return ( + + ); + } + + return ( + + {children} + + ); +}; + +interface MonitorBasePageWithStatesProps extends StackProps { + loading: boolean; + error: any; + items: any[]; + page: string; + actionLink?: string; + children: React.ReactNode; +} + +const isEmpty = (items: any[]) => { + if (!items) return true; + if (Array.isArray(items) && items.length === 0) return true; + return false; +}; + +export const MonitorBasePageWithStates = ({ + loading, + error, + items, + page, + actionLink, + children, + ...props +}: MonitorBasePageWithStatesProps) => { + const { t } = useTranslation(); + + const showLoading = loading && (!items || items.length === 0); + + if (!loading && isEmpty(items)) { + return ( + + ); + } + + return ( + + {children} + + ); +}; diff --git a/client/src/Components/v2/design-elements/Breadcrumb.tsx b/client/src/Components/v2/design-elements/Breadcrumb.tsx new file mode 100644 index 000000000..4489f992d --- /dev/null +++ b/client/src/Components/v2/design-elements/Breadcrumb.tsx @@ -0,0 +1,117 @@ +import MuiBreadcrumbs from "@mui/material/Breadcrumbs"; +import Typography from "@mui/material/Typography"; +import { Link, useLocation } from "react-router-dom"; +import { useTheme } from "@mui/material/styles"; +import { ChevronRight, Home } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +export const Breadcrumb = ({ breadcrumbOverride }: { breadcrumbOverride?: string[] }) => { + const { t } = useTranslation(); + const theme = useTheme(); + const location = useLocation(); + + // Don't show breadcrumb on dashboard + if (location.pathname === "/" || location.pathname === "/uptime") { + return null; + } + + const pathnames = breadcrumbOverride || location.pathname.split("/").filter((x) => x); + + // Don't show if only one level (e.g., /uptime) + if (pathnames.length === 0) { + return null; + } + + return ( + + } + sx={{ + fontSize: "14px", + marginBottom: theme.spacing(6), + "& .MuiBreadcrumbs-separator": { + color: theme.palette.text.secondary, + }, + }} + > + + + + Home + + + {pathnames.map((value, index) => { + const last = index === pathnames.length - 1; + const to = `/${pathnames.slice(0, index + 1).join("/")}`; + + let displayName = ""; + + // Paths that are IDs should be detail pages + if (value.length === 24 || value.match(/^[a-f0-9-]{36}$/)) { + displayName = "Details"; + } else { + displayName = + t(`common.breadcrumbs.${value}`) || + value.charAt(0).toUpperCase() + value.slice(1); + } + + return last ? ( + + {displayName} + + ) : ( + + + {displayName} + + + ); + })} + + ); +}; diff --git a/client/src/Components/v2/design-elements/BulletPointCheck.tsx b/client/src/Components/v2/design-elements/BulletPointCheck.tsx new file mode 100644 index 000000000..2893ee4c2 --- /dev/null +++ b/client/src/Components/v2/design-elements/BulletPointCheck.tsx @@ -0,0 +1,46 @@ +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { Check } from "lucide-react"; +import { useTheme } from "@mui/material/styles"; + +export const BulletPointCheck = ({ + text, + variant = "info", +}: { + text: string; + noHighlightText?: string; + variant?: "success" | "error" | "info"; +}) => { + const theme = useTheme(); + const colors: Record = { + success: theme.palette.success.main, + error: theme.palette.error.main, + info: theme.palette.text.secondary, + }; + + return ( + + + + {text} + + + ); +}; diff --git a/client/src/Components/v2/design-elements/Fallback.tsx b/client/src/Components/v2/design-elements/Fallback.tsx new file mode 100644 index 000000000..16eece25a --- /dev/null +++ b/client/src/Components/v2/design-elements/Fallback.tsx @@ -0,0 +1,180 @@ +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import { BulletPointCheck, SkeletonCard } from "@/Components/v2/design-elements"; +import { Button } from "@/Components/v2/inputs"; + +import { useNavigate } from "react-router"; +import useMediaQuery from "@mui/material/useMediaQuery"; +import { useTheme } from "@mui/material/styles"; +import type { StackProps } from "@mui/material/Stack"; + +interface BaseFallbackProps extends StackProps { + children: React.ReactNode; +} + +export const BaseFallback = ({ children, ...props }: BaseFallbackProps) => { + const theme = useTheme(); + const isSmall = useMediaQuery(theme.breakpoints.down("md")); + + return ( + + + {children} + + ); +}; + +export const ErrorFallback = ({ + title, + subtitle, +}: { + title: string; + subtitle: string; +}) => { + const theme = useTheme(); + return ( + + + {title} + + {subtitle} + + ); +}; + +export const EmptyFallback = ({ + title, + bullets, + actionButtonText, + actionLink, +}: { + title: string; + bullets: any; + actionButtonText: string; + actionLink: string; +}) => { + const theme = useTheme(); + const navigate = useNavigate(); + return ( + + + + {title} + + + {Array.isArray(bullets) && + bullets?.map((bullet: string) => ( + + ))} + + + + + + + ); +}; + +export const EmptyMonitorFallback = ({ + page, + title, + bullets, + actionButtonText, + actionLink, +}: { + page: string; + title: string; + bullets: any; + actionButtonText: string; + actionLink: string; +}) => { + const theme = useTheme(); + const navigate = useNavigate(); + return ( + + + + {title} + + + {Array.isArray(bullets) && + bullets?.map((bullet: string, index: number) => ( + + ))} + + + + + + + ); +}; diff --git a/client/src/Components/v2/design-elements/SkeletonCard.tsx b/client/src/Components/v2/design-elements/SkeletonCard.tsx new file mode 100644 index 000000000..05f0c462a --- /dev/null +++ b/client/src/Components/v2/design-elements/SkeletonCard.tsx @@ -0,0 +1,147 @@ +import { Box, Stack, useTheme } from "@mui/material"; + +interface SkeletonCardProps { + width?: number | string | { xs?: number | string; md?: number | string }; + showHalo?: boolean; +} + +export const SkeletonCard = ({ + width = { xs: 130, md: 216 }, + showHalo = true, +}: SkeletonCardProps) => { + const theme = useTheme(); + const pulseAnimation = { + "@keyframes pulse": { + "0%, 100%": { opacity: 1 }, + "50%": { opacity: 0.72 }, + }, + }; + + const floatAnimation = { + "@keyframes float": { + "0%, 100%": { transform: "rotate(5deg) translate(12px, -20px)" }, + "50%": { transform: "rotate(5deg) translate(12px, -24px)" }, + }, + }; + + const cardStyle = { + width: width, + height: 57, + borderRadius: theme.shape.borderRadius, + background: + theme.palette.mode === "dark" + ? theme.palette.secondary.dark + : theme.palette.background.paper, + boxShadow: + theme.palette.mode === "dark" + ? "0 8px 30px rgba(0,0,0,.3), 0 0 0 1px rgba(255,255,255,.05) inset" + : "0 8px 30px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.05) inset", + display: "flex", + gap: theme.spacing(5), + alignItems: "center", + padding: theme.spacing(5), + }; + + const blockStyle = { + width: 55, + height: 34, + borderRadius: theme.shape.borderRadius, + background: theme.palette.secondary.main, + border: `1px solid ${theme.palette.divider}`, + animation: "pulse 1.6s ease-in-out infinite", + ...pulseAnimation, + }; + + const lineStyle = { + height: 7, + borderRadius: theme.shape.borderRadius, + background: theme.palette.secondary.main, + border: `1px solid ${theme.palette.divider}`, + animation: "pulse 1.6s ease-in-out infinite", + ...pulseAnimation, + }; + + return ( + + {showHalo && ( +