From bf09a9568a94718e8497041dd45816b5b5b68fe7 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 10 Sep 2024 12:39:19 -0400 Subject: [PATCH 01/82] Revamped stat boxes and header --- Client/src/Pages/Monitors/Details/styled.jsx | 1 + Client/src/Pages/Monitors/utils.jsx | 8 +- Client/src/Pages/PageSpeed/Details/index.css | 7 - Client/src/Pages/PageSpeed/Details/index.jsx | 213 +++++++++--------- Client/src/Pages/PageSpeed/Details/styled.jsx | 29 +++ 5 files changed, 145 insertions(+), 113 deletions(-) create mode 100644 Client/src/Pages/PageSpeed/Details/styled.jsx diff --git a/Client/src/Pages/Monitors/Details/styled.jsx b/Client/src/Pages/Monitors/Details/styled.jsx index 99112802d..7f580d7c7 100644 --- a/Client/src/Pages/Monitors/Details/styled.jsx +++ b/Client/src/Pages/Monitors/Details/styled.jsx @@ -76,6 +76,7 @@ export const StatBox = styled(Box)(({ theme }) => ({ borderColor: theme.palette.border.light, borderRadius: 4, backgroundColor: theme.palette.background.main, + background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`, "& h2": { fontSize: 13, fontWeight: 500, diff --git a/Client/src/Pages/Monitors/utils.jsx b/Client/src/Pages/Monitors/utils.jsx index 0551a65aa..ede5baec1 100644 --- a/Client/src/Pages/Monitors/utils.jsx +++ b/Client/src/Pages/Monitors/utils.jsx @@ -23,22 +23,26 @@ const useUtils = () => { const statusStyles = { up: { backgroundColor: theme.palette.success.bg, + background: `linear-gradient(340deg, ${theme.palette.success.light} -60%, ${theme.palette.success.bg} 35%)`, borderColor: theme.palette.success.light, "& h2": { color: theme.palette.success.main }, }, down: { backgroundColor: theme.palette.error.bg, + background: `linear-gradient(340deg, ${theme.palette.error.light} -60%, ${theme.palette.error.bg} 35%)`, borderColor: theme.palette.error.light, "& h2": { color: theme.palette.error.main }, }, paused: { backgroundColor: theme.palette.warning.light, - borderColor: theme.palette.warning.border, + background: `linear-gradient(340deg, ${theme.palette.warning.dark} -60%, ${theme.palette.warning.light} 35%)`, + borderColor: theme.palette.warning.dark, "& h2": { color: theme.palette.warning.main }, }, pending: { backgroundColor: theme.palette.warning.light, - borderColor: theme.palette.warning.border, + background: `linear-gradient(340deg, ${theme.palette.warning.dark} -60%, ${theme.palette.warning.light} 35%)`, + borderColor: theme.palette.warning.dark, "& h2": { color: theme.palette.warning.main }, }, }; diff --git a/Client/src/Pages/PageSpeed/Details/index.css b/Client/src/Pages/PageSpeed/Details/index.css index 1da62a362..e3279bdf9 100644 --- a/Client/src/Pages/PageSpeed/Details/index.css +++ b/Client/src/Pages/PageSpeed/Details/index.css @@ -1,12 +1,7 @@ -.page-speed-details h1 { - font-size: var(--env-var-font-size-large-plus); -} -.page-speed-details h2, .page-speed-details h6 { font-size: var(--env-var-font-size-large); } .page-speed-details h4, -.page-speed-details p, .page-speed-details p > span { font-size: var(--env-var-font-size-medium); } @@ -17,8 +12,6 @@ .page-speed-details h6 { line-height: 22px; } -.page-speed-details h1, -.page-speed-details h2, .page-speed-details h6 { font-weight: 600; } diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 4004e1715..85af38952 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -1,5 +1,13 @@ import PropTypes from "prop-types"; -import { Box, Button, Skeleton, Stack, Typography } from "@mui/material"; +import { + Box, + Button, + Skeleton, + Stack, + Toolbar, + Tooltip, + Typography, +} from "@mui/material"; import { PieChart } from "@mui/x-charts/PieChart"; import { useDrawingArea } from "@mui/x-charts"; import { useEffect, useState } from "react"; @@ -9,7 +17,9 @@ import { useSelector } from "react-redux"; import { formatDuration, formatDurationRounded, + formatDurationSplit, } from "../../../Utils/timeUtils"; +import { StatBox } from "./styled"; import { logger } from "../../../Utils/Logger"; import { networkService } from "../../../main"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; @@ -21,46 +31,6 @@ import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; import "./index.css"; -const StatBox = ({ icon, title, value }) => { - const theme = useTheme(); - - return ( - - {icon} - - - {title} - - - {value} - - - - ); -}; - -StatBox.propTypes = { - icon: PropTypes.element, - title: PropTypes.string, - value: PropTypes.node, -}; - /** * Renders a centered label within a pie chart. * @@ -356,8 +326,21 @@ const PageSpeedDetails = () => { borderRadius: theme.shape.borderRadius, backgroundColor: theme.palette.background.main, }; + + console.log(monitor); + + const splitDuration = (duration) => { + const { time, format } = formatDurationSplit(duration); + return ( + <> + {time} + {format} + + ); + }; + return ( - + {loading ? ( ) : ( @@ -369,32 +352,82 @@ const PageSpeedDetails = () => { ]} /> - - {monitor?.url} + {monitor.name} - - Your pagespeed monitor is live. - + + + + + + + {monitor?.url} + + + Checking every {formatDurationRounded(monitor?.interval)}. + + - - } - title="Last checked" - value={ - <> - {formatDuration(monitor?.lastChecked)}{" "} - - ago - - - } - /> - } - title="Checks since" - value={ - <> - {formatDuration(monitor?.uptimeDuration)}{" "} - - ago - - - } - > - } - title="Checks every" - value={formatDurationRounded(monitor?.interval)} - > + + + checks since + + {splitDuration(monitor?.uptimeDuration)} + ago + + + + last check + + {splitDuration(monitor?.lastChecked)} + ago + + Score history diff --git a/Client/src/Pages/PageSpeed/Details/styled.jsx b/Client/src/Pages/PageSpeed/Details/styled.jsx new file mode 100644 index 000000000..cae50839e --- /dev/null +++ b/Client/src/Pages/PageSpeed/Details/styled.jsx @@ -0,0 +1,29 @@ +import { Box, styled } from "@mui/material"; + +export const StatBox = styled(Box)(({ theme }) => ({ + padding: `${theme.spacing(4)} ${theme.spacing(8)}`, + minWidth: 200, + width: 225, + border: 1, + borderStyle: "solid", + borderColor: theme.palette.border.light, + borderRadius: 4, + backgroundColor: theme.palette.background.main, + background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`, + "& h2": { + fontSize: 13, + fontWeight: 500, + color: theme.palette.text.secondary, + textTransform: "uppercase", + }, + "& p": { + fontSize: 18, + color: theme.palette.text.primary, + marginTop: theme.spacing(2), + "& span": { + color: theme.palette.text.tertiary, + marginLeft: theme.spacing(2), + fontSize: 15, + }, + }, +})); From 4ec51ca886133911fcdb0550e28d1f18f784d511 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 10 Sep 2024 13:20:33 -0400 Subject: [PATCH 02/82] Revamped chart boxes --- Client/src/Pages/PageSpeed/Details/index.css | 16 ----- Client/src/Pages/PageSpeed/Details/index.jsx | 64 ++++++++----------- Client/src/Pages/PageSpeed/Details/styled.jsx | 46 ++++++++++++- .../src/assets/icons/monitor-graph-line.svg | 3 + .../src/assets/icons/performance-report.svg | 3 + 5 files changed, 76 insertions(+), 56 deletions(-) create mode 100644 Client/src/assets/icons/monitor-graph-line.svg create mode 100644 Client/src/assets/icons/performance-report.svg diff --git a/Client/src/Pages/PageSpeed/Details/index.css b/Client/src/Pages/PageSpeed/Details/index.css index e3279bdf9..18b2f1f3a 100644 --- a/Client/src/Pages/PageSpeed/Details/index.css +++ b/Client/src/Pages/PageSpeed/Details/index.css @@ -9,26 +9,10 @@ .page-speed-details h4 > span { font-size: var(--env-var-font-size-small-plus); } -.page-speed-details h6 { - line-height: 22px; -} -.page-speed-details h6 { - font-weight: 600; -} .page-speed-details button.MuiButtonBase-root { height: 34px; } -.page-speed-details .stat-box { - flex: 1; -} -.page-speed-details .stat-box:last-of-type { - flex-shrink: 1; -} -.page-speed-details .stat-box svg { - width: 22px; - height: 22px; -} .page-speed-details .MuiPieArcLabel-root { font-size: var(--env-var-font-size-small-plus); transition: fill 300ms ease; diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 85af38952..6de6d04d6 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -4,7 +4,6 @@ import { Button, Skeleton, Stack, - Toolbar, Tooltip, Typography, } from "@mui/material"; @@ -19,13 +18,12 @@ import { formatDurationRounded, formatDurationSplit, } from "../../../Utils/timeUtils"; -import { StatBox } from "./styled"; +import { ChartBox, IconBox, StatBox } from "./styled"; import { logger } from "../../../Utils/Logger"; import { networkService } from "../../../main"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; -import LastCheckedIcon from "../../../assets/icons/calendar-check.svg?react"; -import ClockIcon from "../../../assets/icons/maintenance.svg?react"; -import IntervalCheckIcon from "../../../assets/icons/interval-check.svg?react"; +import ScoreIcon from "../../../assets/icons/monitor-graph-line.svg?react"; +import PerformanceIcon from "../../../assets/icons/performance-report.svg?react"; import PageSpeedLineChart from "../../../Components/Charts/PagespeedLineChart"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; @@ -302,7 +300,7 @@ const PageSpeedDetails = () => { cx: pieSize.width / 2, }); - performance += Math.round(value); + performance += Math.floor(value); startAngle = endAngle + padding; } }); @@ -320,13 +318,6 @@ const PageSpeedDetails = () => { let loading = Object.keys(monitor).length === 0; const data = monitor?.checks ? [...monitor.checks].reverse() : []; - let sharedStyles = { - border: 1, - borderColor: theme.palette.border.light, - borderRadius: theme.shape.borderRadius, - backgroundColor: theme.palette.background.main, - }; - console.log(monitor); const splitDuration = (duration) => { @@ -465,32 +456,27 @@ const PageSpeedDetails = () => { - - Score history - - - + + + Showing statistics for past 24 hours. + - - Performance report - - + + + + + + Score history + + + + + + + + + Performance report + { })} - + )} diff --git a/Client/src/Pages/PageSpeed/Details/styled.jsx b/Client/src/Pages/PageSpeed/Details/styled.jsx index cae50839e..b067efa22 100644 --- a/Client/src/Pages/PageSpeed/Details/styled.jsx +++ b/Client/src/Pages/PageSpeed/Details/styled.jsx @@ -1,4 +1,48 @@ -import { Box, styled } from "@mui/material"; +import { Box, Stack, styled } from "@mui/material"; + +export const ChartBox = styled(Stack)(({ theme }) => ({ + flex: "1 30%", + gap: theme.spacing(8), + height: 300, + minWidth: 250, + padding: theme.spacing(8), + border: 1, + borderStyle: "solid", + borderColor: theme.palette.border.light, + borderRadius: 4, + backgroundColor: theme.palette.background.main, + "& h2": { + color: theme.palette.text.secondary, + fontSize: 15, + fontWeight: 500, + }, + "& p": { + color: theme.palette.text.secondary, + }, +})); + +export const IconBox = styled(Box)(({ theme }) => ({ + height: 34, + minWidth: 34, + width: 34, + position: "relative", + border: 1, + borderStyle: "solid", + borderColor: theme.palette.border.dark, + borderRadius: 4, + backgroundColor: theme.palette.background.accent, + "& svg": { + position: "absolute", + top: "50%", + left: "50%", + transform: "translate(-50%, -50%)", + width: 20, + height: 20, + "& path": { + stroke: theme.palette.text.tertiary, + }, + }, +})); export const StatBox = styled(Box)(({ theme }) => ({ padding: `${theme.spacing(4)} ${theme.spacing(8)}`, diff --git a/Client/src/assets/icons/monitor-graph-line.svg b/Client/src/assets/icons/monitor-graph-line.svg new file mode 100644 index 000000000..86049eb9e --- /dev/null +++ b/Client/src/assets/icons/monitor-graph-line.svg @@ -0,0 +1,3 @@ + + + diff --git a/Client/src/assets/icons/performance-report.svg b/Client/src/assets/icons/performance-report.svg new file mode 100644 index 000000000..8b7073ac3 --- /dev/null +++ b/Client/src/assets/icons/performance-report.svg @@ -0,0 +1,3 @@ + + + From 0025141e9dc0d6cce477d1cf787b93f855d43b8f Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 10 Sep 2024 13:24:01 -0400 Subject: [PATCH 03/82] Moved skeleton to its own file for increased readability --- Client/src/Pages/PageSpeed/Details/index.jsx | 58 +------------------ .../src/Pages/PageSpeed/Details/skeleton.jsx | 43 ++++++++++++++ 2 files changed, 45 insertions(+), 56 deletions(-) create mode 100644 Client/src/Pages/PageSpeed/Details/skeleton.jsx diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 6de6d04d6..40d71dc5e 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -1,12 +1,5 @@ import PropTypes from "prop-types"; -import { - Box, - Button, - Skeleton, - Stack, - Tooltip, - Typography, -} from "@mui/material"; +import { Box, Button, Stack, Tooltip, Typography } from "@mui/material"; import { PieChart } from "@mui/x-charts/PieChart"; import { useDrawingArea } from "@mui/x-charts"; import { useEffect, useState } from "react"; @@ -14,13 +7,13 @@ import { useTheme } from "@emotion/react"; import { useNavigate, useParams } from "react-router-dom"; import { useSelector } from "react-redux"; import { - formatDuration, formatDurationRounded, formatDurationSplit, } from "../../../Utils/timeUtils"; import { ChartBox, IconBox, StatBox } from "./styled"; import { logger } from "../../../Utils/Logger"; import { networkService } from "../../../main"; +import SkeletonLayout from "./skeleton"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; import ScoreIcon from "../../../assets/icons/monitor-graph-line.svg?react"; import PerformanceIcon from "../../../assets/icons/performance-report.svg?react"; @@ -118,53 +111,6 @@ PieValueLabel.propTypes = { highlighted: PropTypes.bool, }; -/** - * Renders a skeleton layout. - * - * @returns {JSX.Element} - */ -const SkeletonLayout = () => { - const theme = useTheme(); - - return ( - <> - - - - - - - - - - - - - - - - - - - - ); -}; - const PageSpeedDetails = () => { const theme = useTheme(); const navigate = useNavigate(); diff --git a/Client/src/Pages/PageSpeed/Details/skeleton.jsx b/Client/src/Pages/PageSpeed/Details/skeleton.jsx new file mode 100644 index 000000000..5f64b1e0d --- /dev/null +++ b/Client/src/Pages/PageSpeed/Details/skeleton.jsx @@ -0,0 +1,43 @@ +import { Box, Skeleton, Stack } from "@mui/material"; + +/** + * Renders a skeleton layout. + * + * @returns {JSX.Element} + */ +const SkeletonLayout = () => { + return ( + <> + + + + + + + + + + + + + + + + + + + + ); +}; + +export default SkeletonLayout; From 34f0a1e067687d9c02967efbfe46c7fab9ec5bea Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 10 Sep 2024 14:17:59 -0400 Subject: [PATCH 04/82] Implemented basic pagespeed metrics chart --- .../PageSpeed/Details/Charts/AreaChart.jsx | 109 ++++++++++++++++++ Client/src/Pages/PageSpeed/Details/index.jsx | 9 +- Client/src/Pages/PageSpeed/Details/styled.jsx | 1 - 3 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx new file mode 100644 index 000000000..1c5c8df8a --- /dev/null +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -0,0 +1,109 @@ +import { + AreaChart, + Area, + XAxis, + Tooltip, + CartesianGrid, + ResponsiveContainer, +} from "recharts"; +import { useTheme } from "@emotion/react"; +import { useMemo } from "react"; + +const config = { + accessibility: { + id: "accessibility", + color: "primary", + }, + bestPractices: { + id: "bestPractices", + color: "warning", + }, + performance: { + id: "performance", + color: "success", + }, + seo: { + id: "seo", + color: "unresolved", + }, +}; + +const PagespeedDetailsAreaChart = ({ data }) => { + const formatDate = (timestamp) => { + const date = new Date(timestamp); + return date.toLocaleTimeString("en-US", { + hour: "numeric", + minute: "2-digit", + hour12: true, + }); + }; + + const memoizedData = useMemo(() => data, [data[0]]); + + const theme = useTheme(); + + return ( + + + + + + + {Object.values(config).map(({ id, color }) => { + const startColor = theme.palette[color].main; + const endColor = theme.palette[color].light; + + return ( + + + + + ); + })} + + {Object.keys(config).map((key) => { + const { color } = config[key]; + const strokeColor = theme.palette[color].main; + const activeDotColor = theme.palette[color].bg; + + return ( + + ); + })} + + + ); +}; + +export default PagespeedDetailsAreaChart; diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 40d71dc5e..5fdc186b2 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -20,6 +20,7 @@ import PerformanceIcon from "../../../assets/icons/performance-report.svg?react" import PageSpeedLineChart from "../../../Components/Charts/PagespeedLineChart"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; +import PagespeedDetailsAreaChart from "./Charts/AreaChart"; import "./index.css"; /** @@ -264,7 +265,7 @@ const PageSpeedDetails = () => { let loading = Object.keys(monitor).length === 0; const data = monitor?.checks ? [...monitor.checks].reverse() : []; - console.log(monitor); + console.log(data); const splitDuration = (duration) => { const { time, format } = formatDurationSplit(duration); @@ -407,16 +408,16 @@ const PageSpeedDetails = () => { Showing statistics for past 24 hours. - + Score history - + - + diff --git a/Client/src/Pages/PageSpeed/Details/styled.jsx b/Client/src/Pages/PageSpeed/Details/styled.jsx index b067efa22..a6c829061 100644 --- a/Client/src/Pages/PageSpeed/Details/styled.jsx +++ b/Client/src/Pages/PageSpeed/Details/styled.jsx @@ -1,7 +1,6 @@ import { Box, Stack, styled } from "@mui/material"; export const ChartBox = styled(Stack)(({ theme }) => ({ - flex: "1 30%", gap: theme.spacing(8), height: 300, minWidth: 250, From db3c7e6b525e45b26efc41af04a27598e98e8e5c Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 10 Sep 2024 17:43:43 -0400 Subject: [PATCH 05/82] Added null entries --- .../PageSpeed/Details/Charts/AreaChart.jsx | 142 ++++++++++++++++-- Client/src/Pages/PageSpeed/Details/index.jsx | 7 +- 2 files changed, 132 insertions(+), 17 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx index 1c5c8df8a..6c26c43bd 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -8,42 +8,144 @@ import { } from "recharts"; import { useTheme } from "@emotion/react"; import { useMemo } from "react"; +import { Box, Stack, Typography } from "@mui/material"; +import { formatDate } from "../../../../Utils/timeUtils"; const config = { accessibility: { id: "accessibility", + text: "accessibility", color: "primary", }, bestPractices: { id: "bestPractices", + text: "best practices", color: "warning", }, performance: { id: "performance", + text: "performance", color: "success", }, seo: { id: "seo", + text: "SEO", color: "unresolved", }, }; -const PagespeedDetailsAreaChart = ({ data }) => { - const formatDate = (timestamp) => { - const date = new Date(timestamp); - return date.toLocaleTimeString("en-US", { - hour: "numeric", - minute: "2-digit", - hour12: true, +const CustomToolTip = ({ active, payload, label }) => { + const theme = useTheme(); + + if (active && payload && payload.length) { + return ( + + + {formatDate(new Date(label))} + + {Object.keys(config).map((key) => { + const { color } = config[key]; + const dotColor = theme.palette[color].main; + + return ( + + + + {config[key].text} + {" "} + + {payload[0].payload[key]} + + + ); + })} + + ); + } + return null; +}; + +const processDataWithGaps = (data, interval) => { + if (data.length === 0) return []; + let formattedData = []; + let last = new Date(data[0].createdAt).getTime(); + + // Helper function to add a null entry + const addNullEntry = (timestamp) => { + formattedData.push({ + accessibility: "N/A", + bestPractices: "N/A", + performance: "N/A", + seo: "N/A", + createdAt: timestamp, }); }; - const memoizedData = useMemo(() => data, [data[0]]); + data.forEach((entry) => { + const current = new Date(entry.createdAt).getTime(); + if (current - last > interval * 2) { + // Insert null entries for each interval + let temp = last + interval; + while (temp < current) { + addNullEntry(new Date(temp).toISOString()); + temp += interval; + } + } + + formattedData.push(entry); + last = current; + }); + + return formattedData; +}; + +const PagespeedDetailsAreaChart = ({ data, interval }) => { const theme = useTheme(); + const memoizedData = useMemo( + () => processDataWithGaps(data, interval), + [data] + ); return ( - + { + formatDate(new Date(timestamp), { + year: undefined, + month: undefined, + day: undefined, + }) + } tick={{ - fontSize: 12, + fontSize: 11, fontWeight: 100, opacity: 0.8, stroke: theme.palette.text.tertiary, }} tickLine={false} + minTickGap={20} height={18} + interval="preserveEnd" + /> + } /> - {Object.values(config).map(({ id, color }) => { const startColor = theme.palette[color].main; @@ -87,17 +200,18 @@ const PagespeedDetailsAreaChart = ({ data }) => { {Object.keys(config).map((key) => { const { color } = config[key]; const strokeColor = theme.palette[color].main; - const activeDotColor = theme.palette[color].bg; + const bgColor = theme.palette.background.main; return ( ); })} diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 5fdc186b2..657ecc36d 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -265,8 +265,6 @@ const PageSpeedDetails = () => { let loading = Object.keys(monitor).length === 0; const data = monitor?.checks ? [...monitor.checks].reverse() : []; - console.log(data); - const splitDuration = (duration) => { const { time, format } = formatDurationSplit(duration); return ( @@ -415,7 +413,10 @@ const PageSpeedDetails = () => { Score history - + From a89777333ac691aa70be60838ec643517c50b814 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 11 Sep 2024 11:03:39 +0800 Subject: [PATCH 06/82] Add route, controller, and DB methods for adding demo monitors --- Client/src/Pages/Settings/index.jsx | 42 +- Client/src/assets/data/hostnames.json | 1290 ---------------------- Server/controllers/authController.js | 12 +- Server/controllers/monitorController.js | 25 + Server/db/mongo/MongoDB.js | 2 + Server/db/mongo/modules/monitorModule.js | 24 + Server/routes/monitorRoute.js | 6 + Server/utils/demoMonitors.json | 1290 ++++++++++++++++++++++ Server/utils/messages.js | 1 + Server/utils/utils.js | 12 + 10 files changed, 1402 insertions(+), 1302 deletions(-) delete mode 100644 Client/src/assets/data/hostnames.json create mode 100644 Server/utils/demoMonitors.json diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index d1f15ea8c..5f27abe26 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -1,5 +1,5 @@ import { useTheme } from "@emotion/react"; -import { Box, Button, Stack, styled, Typography } from "@mui/material"; +import { Box, Stack, styled, Typography } from "@mui/material"; import Field from "../../Components/Inputs/Field"; import Link from "../../Components/Link"; import Select from "../../Components/Inputs/Select"; @@ -36,6 +36,10 @@ const Settings = ({ isAdmin }) => { } }; + const addDemoMonitors = () => { + logger.warn("Click"); + }; + const ConfigBox = styled("div")({ display: "flex", flexDirection: "row", @@ -140,6 +144,42 @@ const Settings = ({ isAdmin }) => { )} + {isAdmin && ( + + + Demo Monitors + + Here you can add and remove demo monitors + + + + + Add demo monitors + + Add demo monitors + + + + Remove all monitors + {}} + sx={{ mt: theme.spacing(4) }} + > + Remove all monitors + + + + + )} About diff --git a/Client/src/assets/data/hostnames.json b/Client/src/assets/data/hostnames.json deleted file mode 100644 index b66818c3a..000000000 --- a/Client/src/assets/data/hostnames.json +++ /dev/null @@ -1,1290 +0,0 @@ -[ - { - "Company Name": "0to255", - "Company Link ": "https://0to255.com" - }, - { - "Company Name": "10015.io", - "Company Link ": "https://10015.io" - }, - { - "Company Name": "3DIcons", - "Company Link ": "https://3dicons.co" - }, - { - "Company Name": "About.me", - "Company Link ": "https://about.me" - }, - { - "Company Name": "Alias", - "Company Link ": "https://alias.co" - }, - { - "Company Name": "All About Berlin", - "Company Link ": "https://allaboutberlin.com" - }, - { - "Company Name": "All Acronyms", - "Company Link ": "https://allacronyms.com" - }, - { - "Company Name": "All You Can Read ", - "Company Link ": "https://allyoucanread.com" - }, - { - "Company Name": "AllTrails", - "Company Link ": "https://alltrails.com" - }, - { - "Company Name": "Anotepad", - "Company Link ": "https://anotepad.com" - }, - { - "Company Name": "AnswerSocrates", - "Company Link ": "https://answersocrates.com" - }, - { - "Company Name": "AnswerThePublic ", - "Company Link ": "https://answerthepublic.com" - }, - { - "Company Name": "Apollo ", - "Company Link ": "https://apollo.io" - }, - { - "Company Name": "ArrayList", - "Company Link ": "https://arraylist.org" - }, - { - "Company Name": "Ask Difference", - "Company Link ": "https://askdifference.com" - }, - { - "Company Name": "Audd.io", - "Company Link ": "https://audd.io" - }, - { - "Company Name": "Audiocheck", - "Company Link ": "https://audiocheck.net" - }, - { - "Company Name": "Audionautix", - "Company Link ": "https://audionautix.com" - }, - { - "Company Name": "Authentic Jobs", - "Company Link ": "https://authenticjobs.com" - }, - { - "Company Name": "Behind the Name", - "Company Link ": "https://behindthename.com" - }, - { - "Company Name": "Bilim Terimleri", - "Company Link ": "https://terimler.org" - }, - { - "Company Name": "BitBof", - "Company Link ": "https://bitbof.com" - }, - { - "Company Name": "Blank Page", - "Company Link ": "https://blank.page" - }, - { - "Company Name": "Bonanza", - "Company Link ": "https://bonanza.com" - }, - { - "Company Name": "BookCrossing", - "Company Link ": "https://bookcrossing.com" - }, - { - "Company Name": "Browse AI", - "Company Link ": "https://browse.ai" - }, - { - "Company Name": "Bubbl.us", - "Company Link ": "https://bubbl.us" - }, - { - "Company Name": "Business Model Toolbox", - "Company Link ": "https://bmtoolbox.net" - }, - { - "Company Name": "ByClickDownloader", - "Company Link ": "https://byclickdownloader.com" - }, - { - "Company Name": "Calligraphr", - "Company Link ": "https://calligraphr.com" - }, - { - "Company Name": "CertificateClaim", - "Company Link ": "https://certificateclaim.com" - }, - { - "Company Name": "Chosic", - "Company Link ": "https://chosic.com" - }, - { - "Company Name": "ClipDrop", - "Company Link ": "https://clipdrop.co" - }, - { - "Company Name": "CloudConvert", - "Company Link ": "https://cloudconvert.com" - }, - { - "Company Name": "CodingFont", - "Company Link ": "https://codingfont.com" - }, - { - "Company Name": "Color Hunt", - "Company Link ": "https://colorhunt.co" - }, - { - "Company Name": "ColorHexa", - "Company Link ": "https://colorhexa.com" - }, - { - "Company Name": "Conversion-Tool", - "Company Link ": "https://conversion-tool.com" - }, - { - "Company Name": "Cool Startup Jobs", - "Company Link ": "https://coolstartupjobs.com" - }, - { - "Company Name": "Coroflot", - "Company Link ": "https://coroflot.com" - }, - { - "Company Name": "Corrupt-a-File", - "Company Link ": "https://corrupt-a-file.net" - }, - { - "Company Name": "Couchsurfing", - "Company Link ": "https://couchsurfing.com" - }, - { - "Company Name": "Countries Been", - "Company Link ": "https://countriesbeen.com" - }, - { - "Company Name": "Country Code", - "Company Link ": "https://countrycode.org" - }, - { - "Company Name": "Creately", - "Company Link ": "https://creately.com" - }, - { - "Company Name": "Creately ", - "Company Link ": "https://creately.com" - }, - { - "Company Name": "Crossfade.io", - "Company Link ": "https://crossfade.io" - }, - { - "Company Name": "Crunchbase", - "Company Link ": "https://crunchbase.com" - }, - { - "Company Name": "CVmkr", - "Company Link ": "https://cvwizard.com" - }, - { - "Company Name": "Daily Remote", - "Company Link ": "https://dailyremote.com" - }, - { - "Company Name": "David Li", - "Company Link ": "https://david.li" - }, - { - "Company Name": "DemandHunt", - "Company Link ": "https://demandhunt.com" - }, - { - "Company Name": "Designify", - "Company Link ": "https://designify.com" - }, - { - "Company Name": "Diff Checker", - "Company Link ": "https://diffchecker.com" - }, - { - "Company Name": "DifferenceBetween.info", - "Company Link ": "https://differencebetween.info" - }, - { - "Company Name": "Digital Glossary", - "Company Link ": "https://digital-glossary.com" - }, - { - "Company Name": "Dimensions", - "Company Link ": "https://dimensions.com" - }, - { - "Company Name": "Discoverify Music", - "Company Link ": "https://discoverifymusic.com" - }, - { - "Company Name": "discu.eu", - "Company Link ": "https://discu.eu" - }, - { - "Company Name": "Do It Yourself", - "Company Link ": "https://doityourself.com" - }, - { - "Company Name": "Donkey Car", - "Company Link ": "https://donkeycar.com" - }, - { - "Company Name": "draw.io", - "Company Link ": "https://drawio.com" - }, - { - "Company Name": "Drumeo", - "Company Link ": "https://drumeo.com" - }, - { - "Company Name": "Dummies", - "Company Link ": "https://dummies.com" - }, - { - "Company Name": "Easel.ly", - "Company Link ": "https://easel.ly" - }, - { - "Company Name": "Educalingo", - "Company Link ": "https://educalingo.com" - }, - { - "Company Name": "Emoji Combos", - "Company Link ": "https://emojicombos.com" - }, - { - "Company Name": "EquityBee", - "Company Link ": "https://equitybee.com" - }, - { - "Company Name": "EquityZen", - "Company Link ": "https://equityzen.com" - }, - { - "Company Name": "Escape Room Tips", - "Company Link ": "https://escaperoomtips.com" - }, - { - "Company Name": "Every Noise", - "Company Link ": "https://everynoise.com" - }, - { - "Company Name": "Every Time Zone", - "Company Link ": "https://everytimezone.com" - }, - { - "Company Name": "Excalideck", - "Company Link ": "https://excalideck.com" - }, - { - "Company Name": "Excalidraw", - "Company Link ": "https://excalidraw.com" - }, - { - "Company Name": "Extract pics", - "Company Link ": "https://extract.pics" - }, - { - "Company Name": "EZGIF", - "Company Link ": "https://ezgif.com" - }, - { - "Company Name": "FactSlides", - "Company Link ": "https://factslides.com" - }, - { - "Company Name": "FIGR ", - "Company Link ": "https://figr.app" - }, - { - "Company Name": "Fine Dictionary", - "Company Link ": "https://finedictionary.com" - }, - { - "Company Name": "Fiverr", - "Company Link ": "https://fiverr.com" - }, - { - "Company Name": "Fix It Club", - "Company Link ": "https://fixitclub.com" - }, - { - "Company Name": "FlexJobs", - "Company Link ": "https://flexjobs.com" - }, - { - "Company Name": "Flightradar24", - "Company Link ": "https://flightradar24.com" - }, - { - "Company Name": "FlowCV ", - "Company Link ": "https://flowcv.com" - }, - { - "Company Name": "Foco Clipping", - "Company Link ": "https://fococlipping.com" - }, - { - "Company Name": "Font Squirrel", - "Company Link ": "https://fontsquirrel.com" - }, - { - "Company Name": "FontAwesome", - "Company Link ": "https://fontawesome.com" - }, - { - "Company Name": "Fontello ", - "Company Link ": "https://fontello.com" - }, - { - "Company Name": "Form to Chatbot", - "Company Link ": "https://formtochatbot.com" - }, - { - "Company Name": "Founder Resources", - "Company Link ": "https://founderresources.io" - }, - { - "Company Name": "Franz", - "Company Link ": "https://meetfranz.com" - }, - { - "Company Name": "Fraze It", - "Company Link ": "https://fraze.it" - }, - { - "Company Name": "Freecycle", - "Company Link ": "https://freecycle.org" - }, - { - "Company Name": "FreeType", - "Company Link ": "https://freetype.org" - }, - { - "Company Name": "FutureM", - "Company Link ": "https://futureme.org" - }, - { - "Company Name": "Generated.Photos", - "Company Link ": "https://generated.photos" - }, - { - "Company Name": "Get Human", - "Company Link ": "https://gethuman.com" - }, - { - "Company Name": "Go Bento", - "Company Link ": "https://gobento.com" - }, - { - "Company Name": "Good CV", - "Company Link ": "https://goodcv.com" - }, - { - "Company Name": "Grammar Monster", - "Company Link ": "https://grammar-monster.com" - }, - { - "Company Name": "Grammar Book", - "Company Link ": "https://grammarbook.com" - }, - { - "Company Name": "Gummy Search", - "Company Link ": "https://gummysearch.com" - }, - { - "Company Name": "Gumroad", - "Company Link ": "https://gumroad.com" - }, - { - "Company Name": "HealthIcons", - "Company Link ": "https://healthicons.org" - }, - { - "Company Name": "HexColor", - "Company Link ": "https://hexcolor.co" - }, - { - "Company Name": "Hidden Life Radio", - "Company Link ": "https://hiddenliferadio.com" - }, - { - "Company Name": "Hired", - "Company Link ": "https://lhh.com" - }, - { - "Company Name": "Honey", - "Company Link ": "https://joinhoney.com" - }, - { - "Company Name": "HowStuffWorks", - "Company Link ": "https://howstuffworks.com" - }, - { - "Company Name": "HugeIcons Pro", - "Company Link ": "https://hugeicons.com" - }, - { - "Company Name": "Humble Bundle", - "Company Link ": "https://humblebundle.com" - }, - { - "Company Name": "I Have No TV", - "Company Link ": "https://ihavenotv.com" - }, - { - "Company Name": "I Miss the Office", - "Company Link ": "https://imisstheoffice.eu" - }, - { - "Company Name": "IcoMoon", - "Company Link ": "https://icomoon.io" - }, - { - "Company Name": "Iconfinder", - "Company Link ": "https://iconfinder.com" - }, - { - "Company Name": "Icon Packs", - "Company Link ": "https://iconpacks.net" - }, - { - "Company Name": "Iconshock", - "Company Link ": "https://iconshock.com" - }, - { - "Company Name": "Iconz Design", - "Company Link ": "https://iconz.design" - }, - { - "Company Name": "iFixit", - "Company Link ": "https://ifixit.com" - }, - { - "Company Name": "IFTTT", - "Company Link ": "https://ifttt.com" - }, - { - "Company Name": "Illlustrations", - "Company Link ": "https://illlustrations.co" - }, - { - "Company Name": "Illustration Kit", - "Company Link ": "https://illustrationkit.com" - }, - { - "Company Name": "IMSDB", - "Company Link ": "https://imsdb.com" - }, - { - "Company Name": "Incompetech", - "Company Link ": "https://incompetech.com" - }, - { - "Company Name": "Incredibox", - "Company Link ": "https://incredibox.com" - }, - { - "Company Name": "InnerBod", - "Company Link ": "https://innerbody.com" - }, - { - "Company Name": "Instructables", - "Company Link ": "https://instructables.com" - }, - { - "Company Name": "Integromat", - "Company Link ": "https://make.com" - }, - { - "Company Name": "Investopedia", - "Company Link ": "https://investopedia.com" - }, - { - "Company Name": "Japanese Wiki Corpus", - "Company Link ": "https://japanesewiki.com" - }, - { - "Company Name": "Jitter.Video", - "Company Link ": "https://jitter.video" - }, - { - "Company Name": "Jobspresso", - "Company Link ": "https://jobspresso.co" - }, - { - "Company Name": "JPEG-Optimizer", - "Company Link ": "https://jpeg-optimizer.com" - }, - { - "Company Name": "JS Remotely", - "Company Link ": "https://jsremotely.com" - }, - { - "Company Name": "JScreenFix", - "Company Link ": "https://jscreenfix.com" - }, - { - "Company Name": "JSON Resume", - "Company Link ": "https://jsonresume.io" - }, - { - "Company Name": "Just Join", - "Company Link ": "https://justjoin.it" - }, - { - "Company Name": "Just the Recipe", - "Company Link ": "https://justtherecipe.com" - }, - { - "Company Name": "JustRemote", - "Company Link ": "https://justremote.co" - }, - { - "Company Name": "JustWatch", - "Company Link ": "https://justwatch.com" - }, - { - "Company Name": "Kanopy", - "Company Link ": "https://kanopy.com" - }, - { - "Company Name": "Kassellabs", - "Company Link ": "https://kassellabs.io" - }, - { - "Company Name": "Key Differences", - "Company Link ": "https://keydifferences.com" - }, - { - "Company Name": "Keybase", - "Company Link ": "https://keybase.io" - }, - { - "Company Name": "KeyValues", - "Company Link ": "https://keyvalues.com" - }, - { - "Company Name": "KHInsider", - "Company Link ": "https://khinsider.com" - }, - { - "Company Name": "Killed by Google", - "Company Link ": "https://killedbygoogle.com" - }, - { - "Company Name": "Kimovil", - "Company Link ": "https://kimovil.com" - }, - { - "Company Name": "Lalal.ai", - "Company Link ": "https://www.lalal.ai" - }, - { - "Company Name": "Learn Anything", - "Company Link ": "https://learn-anything.xyz" - }, - { - "Company Name": "LendingTree", - "Company Link ": "https://lendingtree.com" - }, - { - "Company Name": "Lightyear.fm", - "Company Link ": "https://lightyear.fm" - }, - { - "Company Name": "LittleSis", - "Company Link ": "https://littlesis.org" - }, - { - "Company Name": "Looria", - "Company Link ": "https://looria.com" - }, - { - "Company Name": "Lucidchart", - "Company Link ": "https://lucidchart.com" - }, - { - "Company Name": "Lunar", - "Company Link ": "https://lunar.fyi" - }, - { - "Company Name": "Manuals Lib", - "Company Link ": "https://manualslib.com" - }, - { - "Company Name": "Map Crunch", - "Company Link ": "https://mapcrunch.com" - }, - { - "Company Name": "Masterworks", - "Company Link ": "https://masterworks.com" - }, - { - "Company Name": "MediaFire", - "Company Link ": "https://mediafire.com" - }, - { - "Company Name": "Mind Mup", - "Company Link ": "https://mindmup.com" - }, - { - "Company Name": "Mixlr", - "Company Link ": "https://mixlr.com" - }, - { - "Company Name": "Moises AI", - "Company Link ": "https://moises.ai" - }, - { - "Company Name": "Money", - "Company Link ": "https://money.com" - }, - { - "Company Name": "Mountain Project", - "Company Link ": "https://mountainproject.com" - }, - { - "Company Name": "Movie Map", - "Company Link ": "https://movie-map.com" - }, - { - "Company Name": "Movie Sounds", - "Company Link ": "https://movie-sounds.org" - }, - { - "Company Name": "MP3Cut", - "Company Link ": "https://mp3cut.net" - }, - { - "Company Name": "Murmel", - "Company Link ": "https://murmel.social" - }, - { - "Company Name": "Muscle Wiki", - "Company Link ": "https://musclewiki.com" - }, - { - "Company Name": "Music-Map", - "Company Link ": "https://music-map.com" - }, - { - "Company Name": "MusicTheory.net", - "Company Link ": "https://musictheory.net" - }, - { - "Company Name": "MyFonts", - "Company Link ": "https://myfonts.com" - }, - { - "Company Name": "MyFridgeFood", - "Company Link ": "https://myfridgefood.com" - }, - { - "Company Name": "Nameberry", - "Company Link ": "https://nameberry.com" - }, - { - "Company Name": "Namechk", - "Company Link ": "https://namechk.com" - }, - { - "Company Name": "Ncase", - "Company Link ": "https://ncase.me" - }, - { - "Company Name": "News in Levels", - "Company Link ": "https://newsinlevels.com" - }, - { - "Company Name": "Noisli", - "Company Link ": "https://noisli.com" - }, - { - "Company Name": "Notes.io", - "Company Link ": "https://notes.io" - }, - { - "Company Name": "Novoresume", - "Company Link ": "https://novoresume.com" - }, - { - "Company Name": "Ocoya", - "Company Link ": "https://ocoya.com" - }, - { - "Company Name": "Old Computers Museum", - "Company Link ": "https://oldcomputers.net" - }, - { - "Company Name": "Online Tone Generator", - "Company Link ": "https://onlinetonegenerator.com" - }, - { - "Company Name": "Online-Convert", - "Company Link ": "https://online-convert.com" - }, - { - "Company Name": "OnlineConversion", - "Company Link ": "https://onlineconversion.com" - }, - { - "Company Name": "Online OCR", - "Company Link ": "https://onlineocr.net" - }, - { - "Company Name": "OpenWeatherMap", - "Company Link ": "https://openweathermap.org" - }, - { - "Company Name": "OrgPad", - "Company Link ": "https://orgpad.com" - }, - { - "Company Name": "Passport Index", - "Company Link ": "https://passportindex.org" - }, - { - "Company Name": "PDF Candy", - "Company Link ": "https://pdfcandy.com" - }, - { - "Company Name": "PDF2DOC", - "Company Link ": "https://pdf2doc.com" - }, - { - "Company Name": "PDFescape", - "Company Link ": "https://pdfescape.com" - }, - { - "Company Name": "PfpMaker", - "Company Link ": "https://pfpmaker.com" - }, - { - "Company Name": "PIDGI Wiki ", - "Company Link ": "https://pidgi.net" - }, - { - "Company Name": "PimEyes", - "Company Link ": "https://pimeyes.com" - }, - { - "Company Name": "Pipl ", - "Company Link ": "https://pipl.com" - }, - { - "Company Name": "PixelBazaar", - "Company Link ": "https://pixelbazaar.com" - }, - { - "Company Name": "PixelPaper", - "Company Link ": "https://pixelpaper.io" - }, - { - "Company Name": "Ponly", - "Company Link ": "https://ponly.com" - }, - { - "Company Name": "PowerToFly", - "Company Link ": "https://powertofly.com" - }, - { - "Company Name": "Pretzel Rocks", - "Company Link ": "https://pretzel.rocks" - }, - { - "Company Name": "PrintIt", - "Company Link ": "https://printit.work" - }, - { - "Company Name": "Prismatext", - "Company Link ": "https://prismatext.com" - }, - { - "Company Name": "Puffin Maps", - "Company Link ": "https://puffinmaps.com" - }, - { - "Company Name": "Puzzle Loop ", - "Company Link ": "https://puzzle-loop.com" - }, - { - "Company Name": "QuoteMaster", - "Company Link ": "https://quotemaster.org" - }, - { - "Company Name": "Radio Garden", - "Company Link ": "https://radio.garden" - }, - { - "Company Name": "Radiooooo", - "Company Link ": "https://radiooooo.com" - }, - { - "Company Name": "Radiosondy", - "Company Link ": "https://radiosondy.info" - }, - { - "Company Name": "Rainy Mood", - "Company Link ": "https://rainymood.com" - }, - { - "Company Name": "Random Street View", - "Company Link ": "https://randomstreetview.com" - }, - { - "Company Name": "Rap4Ever", - "Company Link ": "https://rap4all.com" - }, - { - "Company Name": "RareFilm", - "Company Link ": "https://rarefilm.net" - }, - { - "Company Name": "Rattibha", - "Company Link ": "https://rattibha.com" - }, - { - "Company Name": "Reddit List ", - "Company Link ": "https://redditlist.com" - }, - { - "Company Name": "RedditSearch.io", - "Company Link ": "https://redditsearch.io" - }, - { - "Company Name": "Reelgood", - "Company Link ": "https://reelgood.com" - }, - { - "Company Name": "Reface", - "Company Link ": "https://reface.ai" - }, - { - "Company Name": "Rejected.us", - "Company Link ": "https://rejected.us" - }, - { - "Company Name": "Relanote", - "Company Link ": "https://relanote.com" - }, - { - "Company Name": "Remote Leaf", - "Company Link ": "https://remoteleaf.com" - }, - { - "Company Name": "Remote OK", - "Company Link ": "https://remoteok.com" - }, - { - "Company Name": "Remote Starter Kit ", - "Company Link ": "https://remotestarterkit.com" - }, - { - "Company Name": "Remote.co", - "Company Link ": "https://remote.co" - }, - { - "Company Name": "Remote Base ", - "Company Link ": "https://remotebase.com" - }, - { - "Company Name": "Remote Bear", - "Company Link ": "https://remotebear.io" - }, - { - "Company Name": "Remove.bg", - "Company Link ": "https://remove.bg" - }, - { - "Company Name": "Respresso", - "Company Link ": "https://respresso.io" - }, - { - "Company Name": "Reveddit", - "Company Link ": "https://reveddit.com" - }, - { - "Company Name": "Rhymer", - "Company Link ": "https://rhymer.com" - }, - { - "Company Name": "RhymeZone", - "Company Link ": "https://rhymezone.com" - }, - { - "Company Name": "Ribbet", - "Company Link ": "https://ribbet.com" - }, - { - "Company Name": "Roadmap.sh", - "Company Link ": "https://roadmap.sh" - }, - { - "Company Name": "Roadtrippers", - "Company Link ": "https://roadtrippers.com" - }, - { - "Company Name": "RxResu.me", - "Company Link ": "https://rxresu.me" - }, - { - "Company Name": "SchemeColor", - "Company Link ": "https://schemecolor.com" - }, - { - "Company Name": "Screenshot.Guru", - "Company Link ": "https://screenshot.guru" - }, - { - "Company Name": "SeatGuru", - "Company Link ": "https://seatguru.com" - }, - { - "Company Name": "Sessions", - "Company Link ": "https://sessions.us" - }, - { - "Company Name": "Shottr", - "Company Link ": "https://shottr.cc" - }, - { - "Company Name": "Signature Maker", - "Company Link ": "https://signature-maker.net" - }, - { - "Company Name": "Skip The Drive", - "Company Link ": "https://skipthedrive.com" - }, - { - "Company Name": "Slowby", - "Company Link ": "https://slowby.travel" - }, - { - "Company Name": "Small World", - "Company Link ": "https://smallworld.kiwi" - }, - { - "Company Name": "SmallPDF", - "Company Link ": "https://smallpdf.com" - }, - { - "Company Name": "Social Image Maker", - "Company Link ": "https://socialimagemaker.io" - }, - { - "Company Name": "Social Sizes", - "Company Link ": "https://socialsizes.io" - }, - { - "Company Name": "SoundLove", - "Company Link ": "https://soundlove.se" - }, - { - "Company Name": "Spline", - "Company Link ": "https://spline.design" - }, - { - "Company Name": "Starkey Comics", - "Company Link ": "https://starkeycomics.com" - }, - { - "Company Name": "Startups List", - "Company Link ": "https://startups-list.com" - }, - { - "Company Name": "Statista", - "Company Link ": "https://statista.com" - }, - { - "Company Name": "Stolen Camera Finder", - "Company Link ": "https://stolencamerafinder.com" - }, - { - "Company Name": "Strobe.Cool", - "Company Link ": "https://strobe.cool" - }, - { - "Company Name": "Sumo", - "Company Link ": "https://sumo.app" - }, - { - "Company Name": "SuperMeme AI", - "Company Link ": "https://supermeme.ai" - }, - { - "Company Name": "Synthesia", - "Company Link ": "https://synthesia.io" - }, - { - "Company Name": "TablerIcons", - "Company Link ": "https://tablericons.com" - }, - { - "Company Name": "Tango", - "Company Link ": "https://tango.us" - }, - { - "Company Name": "TasteDive", - "Company Link ": "https://tastedive.com" - }, - { - "Company Name": "TechSpecs", - "Company Link ": "https://techspecs.io" - }, - { - "Company Name": "Teoria", - "Company Link ": "https://teoria.com" - }, - { - "Company Name": "Text Faces", - "Company Link ": "https://textfac.es" - }, - { - "Company Name": "The Balance Money", - "Company Link ": "https://thebalancemoney.com" - }, - { - "Company Name": "The Punctuation Guide", - "Company Link ": "https://thepunctuationguide.com" - }, - { - "Company Name": "This to That", - "Company Link ": "https://thistothat.com" - }, - { - "Company Name": "This vs That", - "Company Link ": "https://thisvsthat.io" - }, - { - "Company Name": "ThreadReaderApp ", - "Company Link ": "https://threadreaderapp.com" - }, - { - "Company Name": "Thumbly", - "Company Link ": "https://tokee.ai" - }, - { - "Company Name": "Tiii.me", - "Company Link ": "https://tiii.me" - }, - { - "Company Name": "TikTok Video Downloader", - "Company Link ": "https://ttvdl.com" - }, - { - "Company Name": "Time and Date", - "Company Link ": "https://timeanddate.com" - }, - { - "Company Name": "Time.is", - "Company Link ": "https://time.is" - }, - { - "Company Name": "Title Case", - "Company Link ": "https://titlecase.com" - }, - { - "Company Name": "Toaster Central", - "Company Link ": "https://toastercentral.com" - }, - { - "Company Name": "Tongue-Twister ", - "Company Link ": "https://tongue-twister.net" - }, - { - "Company Name": "TradingView", - "Company Link ": "https://tradingview.com" - }, - { - "Company Name": "Transparent Textures", - "Company Link ": "https://transparenttextures.com" - }, - { - "Company Name": "Tubi TV", - "Company Link ": "https://tubitv.com" - }, - { - "Company Name": "Tunefind", - "Company Link ": "https://tunefind.com" - }, - { - "Company Name": "TuneMyMusic", - "Company Link ": "https://tunemymusic.com" - }, - { - "Company Name": "Tweepsmap", - "Company Link ": "https://fedica.com" - }, - { - "Company Name": "Two Peas and Their Pod", - "Company Link ": "https://twopeasandtheirpod.com" - }, - { - "Company Name": "Typatone", - "Company Link ": "https://typatone.com" - }, - { - "Company Name": "Under Glass", - "Company Link ": "https://underglass.io" - }, - { - "Company Name": "UniCorner", - "Company Link ": "https://unicorner.news" - }, - { - "Company Name": "Unita", - "Company Link ": "https://unita.co" - }, - { - "Company Name": "UnitConverters", - "Company Link ": "https://unitconverters.net" - }, - { - "Company Name": "Unreadit", - "Company Link ": "https://unreadit.com" - }, - { - "Company Name": "Unscreen", - "Company Link ": "https://unscreen.com" - }, - { - "Company Name": "UnTools ", - "Company Link ": "https://untools.co" - }, - { - "Company Name": "Upwork", - "Company Link ": "https://upwork.com" - }, - { - "Company Name": "UTF8 Icons", - "Company Link ": "https://utf8icons.com" - }, - { - "Company Name": "Vector Magic", - "Company Link ": "https://vectormagic.com" - }, - { - "Company Name": "Virtual Vacation", - "Company Link ": "https://virtualvacation.us" - }, - { - "Company Name": "Virtual Vocations", - "Company Link ": "https://virtualvocations.com" - }, - { - "Company Name": "Visiwig", - "Company Link ": "https://visiwig.com" - }, - { - "Company Name": "Visual CV", - "Company Link ": "https://visualcv.com" - }, - { - "Company Name": "Vocus.io", - "Company Link ": "https://vocus.io" - }, - { - "Company Name": "Voscreen", - "Company Link ": "https://voscreen.com" - }, - { - "Company Name": "Wanderprep", - "Company Link ": "https://wanderprep.com" - }, - { - "Company Name": "Warmshowers", - "Company Link ": "https:/warmshowers.org" - }, - { - "Company Name": "Watch Documentaries", - "Company Link ": "https://watchdocumentaries.com" - }, - { - "Company Name": "We Work Remotely", - "Company Link ": "https://weworkremotely.com" - }, - { - "Company Name": "Web2PDFConvert", - "Company Link ": "https://web2pdfconvert.com" - }, - { - "Company Name": "Welcome to My Garden", - "Company Link ": "https://welcometomygarden.org" - }, - { - "Company Name": "When2meet ", - "Company Link ": "https://when2meet.com" - }, - { - "Company Name": "Where's George", - "Company Link ": "https://wheresgeorge.com" - }, - { - "Company Name": "Where's Willy", - "Company Link ": "https://whereswilly.com" - }, - { - "Company Name": "WikiHow", - "Company Link ": "https://wikihow.com" - }, - { - "Company Name": "Windy", - "Company Link ": "https://www.windy.com" - }, - { - "Company Name": "WonderHowTo", - "Company Link ": "https://wonderhowto.com" - }, - { - "Company Name": "Working Nomads", - "Company Link ": "https://workingnomads.com" - }, - { - "Company Name": "Wormhole", - "Company Link ": "https://wormhole.app" - }, - { - "Company Name": "Y Combinator Jobs", - "Company Link ": "https://ycombinator.com" - }, - { - "Company Name": "Yes Promo", - "Company Link ": "https://yespromo.me" - }, - { - "Company Name": "YouGlish", - "Company Link ": "https://youglish.com" - }, - { - "Company Name": "Zamzar", - "Company Link ": "https://zamzar.com" - }, - { - "Company Name": "Zippyshare", - "Company Link ": "https://zippyshare.com" - }, - { - "Company Name": "Zoom Earth", - "Company Link ": "https://zoom.earth" - }, - { - "Company Name": "Zoom.it", - "Company Link ": "https://zoom.it" - } -] \ No newline at end of file diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index fe406a6b6..b3a809a09 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -17,6 +17,7 @@ require("dotenv").config(); const { errorMessages, successMessages } = require("../utils/messages"); var jwt = require("jsonwebtoken"); const SERVICE_NAME = "auth"; +const { getTokenFromHeaders } = require("../utils/utils"); /** * Creates and returns JWT token with an arbitrary payload @@ -30,17 +31,6 @@ const issueToken = (payload) => { return jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: tokenTTL }); }; -const getTokenFromHeaders = (headers) => { - const authorizationHeader = headers.authorization; - if (!authorizationHeader) throw new Error("No auth headers"); - - const parts = authorizationHeader.split(" "); - if (parts.length !== 2 || parts[0] !== "Bearer") - throw new Error("Invalid auth headers"); - - return parts[1]; -}; - /** * @function * @param {express.Request} req diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 4571a9a65..0b03488fd 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -18,6 +18,9 @@ const { const sslChecker = require("ssl-checker"); const SERVICE_NAME = "monitorController"; const { errorMessages, successMessages } = require("../utils/messages"); +const jwt = require("jsonwebtoken"); +const { getTokenFromHeaders } = require("../utils/utils"); + /** * Returns all monitors * @async @@ -466,6 +469,27 @@ const pauseMonitor = async (req, res, next) => { } }; +const addDemoMonitors = async (req, res, next) => { + try { + const token = getTokenFromHeaders(req.headers); + // Get email from token + const { _id, teamId } = jwt.verify(token, process.env.JWT_SECRET); + const demoMonitors = await req.db.addDemoMonitors(_id, teamId); + await demoMonitors.forEach(async (monitor) => { + await req.jobQueue.addJob(monitor._id, monitor); + }); + return res.status(200).json({ + success: true, + message: successMessages.MONITOR_DEMO_ADDED, + data: demoMonitors.length, + }); + } catch (error) { + error.service = SERVICE_NAME; + error.method === undefined && error.method === "addDemoMonitors"; + next(error); + } +}; + module.exports = { getAllMonitors, getMonitorAggregateStats, @@ -479,4 +503,5 @@ module.exports = { deleteAllMonitors, editMonitor, pauseMonitor, + addDemoMonitors, }; diff --git a/Server/db/mongo/MongoDB.js b/Server/db/mongo/MongoDB.js index d6a4a243f..73d55d509 100644 --- a/Server/db/mongo/MongoDB.js +++ b/Server/db/mongo/MongoDB.js @@ -73,6 +73,7 @@ const { deleteAllMonitors, deleteMonitorsByUserId, editMonitor, + addDemoMonitors, } = require("./modules/monitorModule"); //**************************************** @@ -153,6 +154,7 @@ module.exports = { deleteMonitor, deleteAllMonitors, editMonitor, + addDemoMonitors, createCheck, getChecksCount, getChecks, diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index e77ccc696..b3d48c543 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -4,6 +4,7 @@ const PageSpeedCheck = require("../../../models/PageSpeedCheck"); const { errorMessages } = require("../../../utils/messages"); const Notification = require("../../../models/Notification"); const { NormalizeData } = require("../../../utils/dataUtils"); +const demoMonitors = require("../../../utils/demoMonitors.json"); /** * Get all monitors @@ -493,6 +494,28 @@ const editMonitor = async (candidateId, candidateMonitor) => { ); return editedMonitor; } catch (error) { + error.method = "editMonitor"; + throw error; + } +}; + +const addDemoMonitors = async (userId, teamId) => { + try { + const demoMonitorsToInsert = demoMonitors.map((monitor) => { + return { + userId, + teamId, + name: monitor.name, + description: monitor.name, + type: "http", + url: monitor.url, + interval: 60000, + }; + }); + const insertedMonitors = await Monitor.insertMany(demoMonitorsToInsert); + return insertedMonitors; + } catch (error) { + error.method = "addDemoMonitors"; throw error; } }; @@ -508,4 +531,5 @@ module.exports = { deleteAllMonitors, deleteMonitorsByUserId, editMonitor, + addDemoMonitors, }; diff --git a/Server/routes/monitorRoute.js b/Server/routes/monitorRoute.js index b29b7130a..47c4c525c 100644 --- a/Server/routes/monitorRoute.js +++ b/Server/routes/monitorRoute.js @@ -43,4 +43,10 @@ router.post( monitorController.pauseMonitor ); +router.post( + "/demo", + isAllowed(["admin", "superadmin"]), + monitorController.addDemoMonitors +); + module.exports = router; diff --git a/Server/utils/demoMonitors.json b/Server/utils/demoMonitors.json new file mode 100644 index 000000000..413ffc76a --- /dev/null +++ b/Server/utils/demoMonitors.json @@ -0,0 +1,1290 @@ +[ + { + "name": "0to255", + "url": "https://0to255.com" + }, + { + "name": "10015.io", + "url": "https://10015.io" + }, + { + "name": "3DIcons", + "url": "https://3dicons.co" + }, + { + "name": "About.me", + "url": "https://about.me" + }, + { + "name": "Alias", + "url": "https://alias.co" + }, + { + "name": "All About Berlin", + "url": "https://allaboutberlin.com" + }, + { + "name": "All Acronyms", + "url": "https://allacronyms.com" + }, + { + "name": "All You Can Read ", + "url": "https://allyoucanread.com" + }, + { + "name": "AllTrails", + "url": "https://alltrails.com" + }, + { + "name": "Anotepad", + "url": "https://anotepad.com" + }, + { + "name": "AnswerSocrates", + "url": "https://answersocrates.com" + }, + { + "name": "AnswerThePublic ", + "url": "https://answerthepublic.com" + }, + { + "name": "Apollo ", + "url": "https://apollo.io" + }, + { + "name": "ArrayList", + "url": "https://arraylist.org" + }, + { + "name": "Ask Difference", + "url": "https://askdifference.com" + }, + { + "name": "Audd.io", + "url": "https://audd.io" + }, + { + "name": "Audiocheck", + "url": "https://audiocheck.net" + }, + { + "name": "Audionautix", + "url": "https://audionautix.com" + }, + { + "name": "Authentic Jobs", + "url": "https://authenticjobs.com" + }, + { + "name": "Behind the Name", + "url": "https://behindthename.com" + }, + { + "name": "Bilim Terimleri", + "url": "https://terimler.org" + }, + { + "name": "BitBof", + "url": "https://bitbof.com" + }, + { + "name": "Blank Page", + "url": "https://blank.page" + }, + { + "name": "Bonanza", + "url": "https://bonanza.com" + }, + { + "name": "BookCrossing", + "url": "https://bookcrossing.com" + }, + { + "name": "Browse AI", + "url": "https://browse.ai" + }, + { + "name": "Bubbl.us", + "url": "https://bubbl.us" + }, + { + "name": "Business Model Toolbox", + "url": "https://bmtoolbox.net" + }, + { + "name": "ByClickDownloader", + "url": "https://byclickdownloader.com" + }, + { + "name": "Calligraphr", + "url": "https://calligraphr.com" + }, + { + "name": "CertificateClaim", + "url": "https://certificateclaim.com" + }, + { + "name": "Chosic", + "url": "https://chosic.com" + }, + { + "name": "ClipDrop", + "url": "https://clipdrop.co" + }, + { + "name": "CloudConvert", + "url": "https://cloudconvert.com" + }, + { + "name": "CodingFont", + "url": "https://codingfont.com" + }, + { + "name": "Color Hunt", + "url": "https://colorhunt.co" + }, + { + "name": "ColorHexa", + "url": "https://colorhexa.com" + }, + { + "name": "Conversion-Tool", + "url": "https://conversion-tool.com" + }, + { + "name": "Cool Startup Jobs", + "url": "https://coolstartupjobs.com" + }, + { + "name": "Coroflot", + "url": "https://coroflot.com" + }, + { + "name": "Corrupt-a-File", + "url": "https://corrupt-a-file.net" + }, + { + "name": "Couchsurfing", + "url": "https://couchsurfing.com" + }, + { + "name": "Countries Been", + "url": "https://countriesbeen.com" + }, + { + "name": "Country Code", + "url": "https://countrycode.org" + }, + { + "name": "Creately", + "url": "https://creately.com" + }, + { + "name": "Creately ", + "url": "https://creately.com" + }, + { + "name": "Crossfade.io", + "url": "https://crossfade.io" + }, + { + "name": "Crunchbase", + "url": "https://crunchbase.com" + }, + { + "name": "CVmkr", + "url": "https://cvwizard.com" + }, + { + "name": "Daily Remote", + "url": "https://dailyremote.com" + }, + { + "name": "David Li", + "url": "https://david.li" + }, + { + "name": "DemandHunt", + "url": "https://demandhunt.com" + }, + { + "name": "Designify", + "url": "https://designify.com" + }, + { + "name": "Diff Checker", + "url": "https://diffchecker.com" + }, + { + "name": "DifferenceBetween.info", + "url": "https://differencebetween.info" + }, + { + "name": "Digital Glossary", + "url": "https://digital-glossary.com" + }, + { + "name": "Dimensions", + "url": "https://dimensions.com" + }, + { + "name": "Discoverify Music", + "url": "https://discoverifymusic.com" + }, + { + "name": "discu.eu", + "url": "https://discu.eu" + }, + { + "name": "Do It Yourself", + "url": "https://doityourself.com" + }, + { + "name": "Donkey Car", + "url": "https://donkeycar.com" + }, + { + "name": "draw.io", + "url": "https://drawio.com" + }, + { + "name": "Drumeo", + "url": "https://drumeo.com" + }, + { + "name": "Dummies", + "url": "https://dummies.com" + }, + { + "name": "Easel.ly", + "url": "https://easel.ly" + }, + { + "name": "Educalingo", + "url": "https://educalingo.com" + }, + { + "name": "Emoji Combos", + "url": "https://emojicombos.com" + }, + { + "name": "EquityBee", + "url": "https://equitybee.com" + }, + { + "name": "EquityZen", + "url": "https://equityzen.com" + }, + { + "name": "Escape Room Tips", + "url": "https://escaperoomtips.com" + }, + { + "name": "Every Noise", + "url": "https://everynoise.com" + }, + { + "name": "Every Time Zone", + "url": "https://everytimezone.com" + }, + { + "name": "Excalideck", + "url": "https://excalideck.com" + }, + { + "name": "Excalidraw", + "url": "https://excalidraw.com" + }, + { + "name": "Extract pics", + "url": "https://extract.pics" + }, + { + "name": "EZGIF", + "url": "https://ezgif.com" + }, + { + "name": "FactSlides", + "url": "https://factslides.com" + }, + { + "name": "FIGR ", + "url": "https://figr.app" + }, + { + "name": "Fine Dictionary", + "url": "https://finedictionary.com" + }, + { + "name": "Fiverr", + "url": "https://fiverr.com" + }, + { + "name": "Fix It Club", + "url": "https://fixitclub.com" + }, + { + "name": "FlexJobs", + "url": "https://flexjobs.com" + }, + { + "name": "Flightradar24", + "url": "https://flightradar24.com" + }, + { + "name": "FlowCV ", + "url": "https://flowcv.com" + }, + { + "name": "Foco Clipping", + "url": "https://fococlipping.com" + }, + { + "name": "Font Squirrel", + "url": "https://fontsquirrel.com" + }, + { + "name": "FontAwesome", + "url": "https://fontawesome.com" + }, + { + "name": "Fontello ", + "url": "https://fontello.com" + }, + { + "name": "Form to Chatbot", + "url": "https://formtochatbot.com" + }, + { + "name": "Founder Resources", + "url": "https://founderresources.io" + }, + { + "name": "Franz", + "url": "https://meetfranz.com" + }, + { + "name": "Fraze It", + "url": "https://fraze.it" + }, + { + "name": "Freecycle", + "url": "https://freecycle.org" + }, + { + "name": "FreeType", + "url": "https://freetype.org" + }, + { + "name": "FutureM", + "url": "https://futureme.org" + }, + { + "name": "Generated.Photos", + "url": "https://generated.photos" + }, + { + "name": "Get Human", + "url": "https://gethuman.com" + }, + { + "name": "Go Bento", + "url": "https://gobento.com" + }, + { + "name": "Good CV", + "url": "https://goodcv.com" + }, + { + "name": "Grammar Monster", + "url": "https://grammar-monster.com" + }, + { + "name": "Grammar Book", + "url": "https://grammarbook.com" + }, + { + "name": "Gummy Search", + "url": "https://gummysearch.com" + }, + { + "name": "Gumroad", + "url": "https://gumroad.com" + }, + { + "name": "HealthIcons", + "url": "https://healthicons.org" + }, + { + "name": "HexColor", + "url": "https://hexcolor.co" + }, + { + "name": "Hidden Life Radio", + "url": "https://hiddenliferadio.com" + }, + { + "name": "Hired", + "url": "https://lhh.com" + }, + { + "name": "Honey", + "url": "https://joinhoney.com" + }, + { + "name": "HowStuffWorks", + "url": "https://howstuffworks.com" + }, + { + "name": "HugeIcons Pro", + "url": "https://hugeicons.com" + }, + { + "name": "Humble Bundle", + "url": "https://humblebundle.com" + }, + { + "name": "I Have No TV", + "url": "https://ihavenotv.com" + }, + { + "name": "I Miss the Office", + "url": "https://imisstheoffice.eu" + }, + { + "name": "IcoMoon", + "url": "https://icomoon.io" + }, + { + "name": "Iconfinder", + "url": "https://iconfinder.com" + }, + { + "name": "Icon Packs", + "url": "https://iconpacks.net" + }, + { + "name": "Iconshock", + "url": "https://iconshock.com" + }, + { + "name": "Iconz Design", + "url": "https://iconz.design" + }, + { + "name": "iFixit", + "url": "https://ifixit.com" + }, + { + "name": "IFTTT", + "url": "https://ifttt.com" + }, + { + "name": "Illlustrations", + "url": "https://illlustrations.co" + }, + { + "name": "Illustration Kit", + "url": "https://illustrationkit.com" + }, + { + "name": "IMSDB", + "url": "https://imsdb.com" + }, + { + "name": "Incompetech", + "url": "https://incompetech.com" + }, + { + "name": "Incredibox", + "url": "https://incredibox.com" + }, + { + "name": "InnerBod", + "url": "https://innerbody.com" + }, + { + "name": "Instructables", + "url": "https://instructables.com" + }, + { + "name": "Integromat", + "url": "https://make.com" + }, + { + "name": "Investopedia", + "url": "https://investopedia.com" + }, + { + "name": "Japanese Wiki Corpus", + "url": "https://japanesewiki.com" + }, + { + "name": "Jitter.Video", + "url": "https://jitter.video" + }, + { + "name": "Jobspresso", + "url": "https://jobspresso.co" + }, + { + "name": "JPEG-Optimizer", + "url": "https://jpeg-optimizer.com" + }, + { + "name": "JS Remotely", + "url": "https://jsremotely.com" + }, + { + "name": "JScreenFix", + "url": "https://jscreenfix.com" + }, + { + "name": "JSON Resume", + "url": "https://jsonresume.io" + }, + { + "name": "Just Join", + "url": "https://justjoin.it" + }, + { + "name": "Just the Recipe", + "url": "https://justtherecipe.com" + }, + { + "name": "JustRemote", + "url": "https://justremote.co" + }, + { + "name": "JustWatch", + "url": "https://justwatch.com" + }, + { + "name": "Kanopy", + "url": "https://kanopy.com" + }, + { + "name": "Kassellabs", + "url": "https://kassellabs.io" + }, + { + "name": "Key Differences", + "url": "https://keydifferences.com" + }, + { + "name": "Keybase", + "url": "https://keybase.io" + }, + { + "name": "KeyValues", + "url": "https://keyvalues.com" + }, + { + "name": "KHInsider", + "url": "https://khinsider.com" + }, + { + "name": "Killed by Google", + "url": "https://killedbygoogle.com" + }, + { + "name": "Kimovil", + "url": "https://kimovil.com" + }, + { + "name": "Lalal.ai", + "url": "https://www.lalal.ai" + }, + { + "name": "Learn Anything", + "url": "https://learn-anything.xyz" + }, + { + "name": "LendingTree", + "url": "https://lendingtree.com" + }, + { + "name": "Lightyear.fm", + "url": "https://lightyear.fm" + }, + { + "name": "LittleSis", + "url": "https://littlesis.org" + }, + { + "name": "Looria", + "url": "https://looria.com" + }, + { + "name": "Lucidchart", + "url": "https://lucidchart.com" + }, + { + "name": "Lunar", + "url": "https://lunar.fyi" + }, + { + "name": "Manuals Lib", + "url": "https://manualslib.com" + }, + { + "name": "Map Crunch", + "url": "https://mapcrunch.com" + }, + { + "name": "Masterworks", + "url": "https://masterworks.com" + }, + { + "name": "MediaFire", + "url": "https://mediafire.com" + }, + { + "name": "Mind Mup", + "url": "https://mindmup.com" + }, + { + "name": "Mixlr", + "url": "https://mixlr.com" + }, + { + "name": "Moises AI", + "url": "https://moises.ai" + }, + { + "name": "Money", + "url": "https://money.com" + }, + { + "name": "Mountain Project", + "url": "https://mountainproject.com" + }, + { + "name": "Movie Map", + "url": "https://movie-map.com" + }, + { + "name": "Movie Sounds", + "url": "https://movie-sounds.org" + }, + { + "name": "MP3Cut", + "url": "https://mp3cut.net" + }, + { + "name": "Murmel", + "url": "https://murmel.social" + }, + { + "name": "Muscle Wiki", + "url": "https://musclewiki.com" + }, + { + "name": "Music-Map", + "url": "https://music-map.com" + }, + { + "name": "MusicTheory.net", + "url": "https://musictheory.net" + }, + { + "name": "MyFonts", + "url": "https://myfonts.com" + }, + { + "name": "MyFridgeFood", + "url": "https://myfridgefood.com" + }, + { + "name": "Nameberry", + "url": "https://nameberry.com" + }, + { + "name": "Namechk", + "url": "https://namechk.com" + }, + { + "name": "Ncase", + "url": "https://ncase.me" + }, + { + "name": "News in Levels", + "url": "https://newsinlevels.com" + }, + { + "name": "Noisli", + "url": "https://noisli.com" + }, + { + "name": "Notes.io", + "url": "https://notes.io" + }, + { + "name": "Novoresume", + "url": "https://novoresume.com" + }, + { + "name": "Ocoya", + "url": "https://ocoya.com" + }, + { + "name": "Old Computers Museum", + "url": "https://oldcomputers.net" + }, + { + "name": "Online Tone Generator", + "url": "https://onlinetonegenerator.com" + }, + { + "name": "Online-Convert", + "url": "https://online-convert.com" + }, + { + "name": "OnlineConversion", + "url": "https://onlineconversion.com" + }, + { + "name": "Online OCR", + "url": "https://onlineocr.net" + }, + { + "name": "OpenWeatherMap", + "url": "https://openweathermap.org" + }, + { + "name": "OrgPad", + "url": "https://orgpad.com" + }, + { + "name": "Passport Index", + "url": "https://passportindex.org" + }, + { + "name": "PDF Candy", + "url": "https://pdfcandy.com" + }, + { + "name": "PDF2DOC", + "url": "https://pdf2doc.com" + }, + { + "name": "PDFescape", + "url": "https://pdfescape.com" + }, + { + "name": "PfpMaker", + "url": "https://pfpmaker.com" + }, + { + "name": "PIDGI Wiki ", + "url": "https://pidgi.net" + }, + { + "name": "PimEyes", + "url": "https://pimeyes.com" + }, + { + "name": "Pipl ", + "url": "https://pipl.com" + }, + { + "name": "PixelBazaar", + "url": "https://pixelbazaar.com" + }, + { + "name": "PixelPaper", + "url": "https://pixelpaper.io" + }, + { + "name": "Ponly", + "url": "https://ponly.com" + }, + { + "name": "PowerToFly", + "url": "https://powertofly.com" + }, + { + "name": "Pretzel Rocks", + "url": "https://pretzel.rocks" + }, + { + "name": "PrintIt", + "url": "https://printit.work" + }, + { + "name": "Prismatext", + "url": "https://prismatext.com" + }, + { + "name": "Puffin Maps", + "url": "https://puffinmaps.com" + }, + { + "name": "Puzzle Loop ", + "url": "https://puzzle-loop.com" + }, + { + "name": "QuoteMaster", + "url": "https://quotemaster.org" + }, + { + "name": "Radio Garden", + "url": "https://radio.garden" + }, + { + "name": "Radiooooo", + "url": "https://radiooooo.com" + }, + { + "name": "Radiosondy", + "url": "https://radiosondy.info" + }, + { + "name": "Rainy Mood", + "url": "https://rainymood.com" + }, + { + "name": "Random Street View", + "url": "https://randomstreetview.com" + }, + { + "name": "Rap4Ever", + "url": "https://rap4all.com" + }, + { + "name": "RareFilm", + "url": "https://rarefilm.net" + }, + { + "name": "Rattibha", + "url": "https://rattibha.com" + }, + { + "name": "Reddit List ", + "url": "https://redditlist.com" + }, + { + "name": "RedditSearch.io", + "url": "https://redditsearch.io" + }, + { + "name": "Reelgood", + "url": "https://reelgood.com" + }, + { + "name": "Reface", + "url": "https://reface.ai" + }, + { + "name": "Rejected.us", + "url": "https://rejected.us" + }, + { + "name": "Relanote", + "url": "https://relanote.com" + }, + { + "name": "Remote Leaf", + "url": "https://remoteleaf.com" + }, + { + "name": "Remote OK", + "url": "https://remoteok.com" + }, + { + "name": "Remote Starter Kit ", + "url": "https://remotestarterkit.com" + }, + { + "name": "Remote.co", + "url": "https://remote.co" + }, + { + "name": "Remote Base ", + "url": "https://remotebase.com" + }, + { + "name": "Remote Bear", + "url": "https://remotebear.io" + }, + { + "name": "Remove.bg", + "url": "https://remove.bg" + }, + { + "name": "Respresso", + "url": "https://respresso.io" + }, + { + "name": "Reveddit", + "url": "https://reveddit.com" + }, + { + "name": "Rhymer", + "url": "https://rhymer.com" + }, + { + "name": "RhymeZone", + "url": "https://rhymezone.com" + }, + { + "name": "Ribbet", + "url": "https://ribbet.com" + }, + { + "name": "Roadmap.sh", + "url": "https://roadmap.sh" + }, + { + "name": "Roadtrippers", + "url": "https://roadtrippers.com" + }, + { + "name": "RxResu.me", + "url": "https://rxresu.me" + }, + { + "name": "SchemeColor", + "url": "https://schemecolor.com" + }, + { + "name": "Screenshot.Guru", + "url": "https://screenshot.guru" + }, + { + "name": "SeatGuru", + "url": "https://seatguru.com" + }, + { + "name": "Sessions", + "url": "https://sessions.us" + }, + { + "name": "Shottr", + "url": "https://shottr.cc" + }, + { + "name": "Signature Maker", + "url": "https://signature-maker.net" + }, + { + "name": "Skip The Drive", + "url": "https://skipthedrive.com" + }, + { + "name": "Slowby", + "url": "https://slowby.travel" + }, + { + "name": "Small World", + "url": "https://smallworld.kiwi" + }, + { + "name": "SmallPDF", + "url": "https://smallpdf.com" + }, + { + "name": "Social Image Maker", + "url": "https://socialimagemaker.io" + }, + { + "name": "Social Sizes", + "url": "https://socialsizes.io" + }, + { + "name": "SoundLove", + "url": "https://soundlove.se" + }, + { + "name": "Spline", + "url": "https://spline.design" + }, + { + "name": "Starkey Comics", + "url": "https://starkeycomics.com" + }, + { + "name": "Startups List", + "url": "https://startups-list.com" + }, + { + "name": "Statista", + "url": "https://statista.com" + }, + { + "name": "Stolen Camera Finder", + "url": "https://stolencamerafinder.com" + }, + { + "name": "Strobe.Cool", + "url": "https://strobe.cool" + }, + { + "name": "Sumo", + "url": "https://sumo.app" + }, + { + "name": "SuperMeme AI", + "url": "https://supermeme.ai" + }, + { + "name": "Synthesia", + "url": "https://synthesia.io" + }, + { + "name": "TablerIcons", + "url": "https://tablericons.com" + }, + { + "name": "Tango", + "url": "https://tango.us" + }, + { + "name": "TasteDive", + "url": "https://tastedive.com" + }, + { + "name": "TechSpecs", + "url": "https://techspecs.io" + }, + { + "name": "Teoria", + "url": "https://teoria.com" + }, + { + "name": "Text Faces", + "url": "https://textfac.es" + }, + { + "name": "The Balance Money", + "url": "https://thebalancemoney.com" + }, + { + "name": "The Punctuation Guide", + "url": "https://thepunctuationguide.com" + }, + { + "name": "This to That", + "url": "https://thistothat.com" + }, + { + "name": "This vs That", + "url": "https://thisvsthat.io" + }, + { + "name": "ThreadReaderApp ", + "url": "https://threadreaderapp.com" + }, + { + "name": "Thumbly", + "url": "https://tokee.ai" + }, + { + "name": "Tiii.me", + "url": "https://tiii.me" + }, + { + "name": "TikTok Video Downloader", + "url": "https://ttvdl.com" + }, + { + "name": "Time and Date", + "url": "https://timeanddate.com" + }, + { + "name": "Time.is", + "url": "https://time.is" + }, + { + "name": "Title Case", + "url": "https://titlecase.com" + }, + { + "name": "Toaster Central", + "url": "https://toastercentral.com" + }, + { + "name": "Tongue-Twister ", + "url": "https://tongue-twister.net" + }, + { + "name": "TradingView", + "url": "https://tradingview.com" + }, + { + "name": "Transparent Textures", + "url": "https://transparenttextures.com" + }, + { + "name": "Tubi TV", + "url": "https://tubitv.com" + }, + { + "name": "Tunefind", + "url": "https://tunefind.com" + }, + { + "name": "TuneMyMusic", + "url": "https://tunemymusic.com" + }, + { + "name": "Tweepsmap", + "url": "https://fedica.com" + }, + { + "name": "Two Peas and Their Pod", + "url": "https://twopeasandtheirpod.com" + }, + { + "name": "Typatone", + "url": "https://typatone.com" + }, + { + "name": "Under Glass", + "url": "https://underglass.io" + }, + { + "name": "UniCorner", + "url": "https://unicorner.news" + }, + { + "name": "Unita", + "url": "https://unita.co" + }, + { + "name": "UnitConverters", + "url": "https://unitconverters.net" + }, + { + "name": "Unreadit", + "url": "https://unreadit.com" + }, + { + "name": "Unscreen", + "url": "https://unscreen.com" + }, + { + "name": "UnTools ", + "url": "https://untools.co" + }, + { + "name": "Upwork", + "url": "https://upwork.com" + }, + { + "name": "UTF8 Icons", + "url": "https://utf8icons.com" + }, + { + "name": "Vector Magic", + "url": "https://vectormagic.com" + }, + { + "name": "Virtual Vacation", + "url": "https://virtualvacation.us" + }, + { + "name": "Virtual Vocations", + "url": "https://virtualvocations.com" + }, + { + "name": "Visiwig", + "url": "https://visiwig.com" + }, + { + "name": "Visual CV", + "url": "https://visualcv.com" + }, + { + "name": "Vocus.io", + "url": "https://vocus.io" + }, + { + "name": "Voscreen", + "url": "https://voscreen.com" + }, + { + "name": "Wanderprep", + "url": "https://wanderprep.com" + }, + { + "name": "Warmshowers", + "url": "https:/warmshowers.org" + }, + { + "name": "Watch Documentaries", + "url": "https://watchdocumentaries.com" + }, + { + "name": "We Work Remotely", + "url": "https://weworkremotely.com" + }, + { + "name": "Web2PDFConvert", + "url": "https://web2pdfconvert.com" + }, + { + "name": "Welcome to My Garden", + "url": "https://welcometomygarden.org" + }, + { + "name": "When2meet ", + "url": "https://when2meet.com" + }, + { + "name": "Where's George", + "url": "https://wheresgeorge.com" + }, + { + "name": "Where's Willy", + "url": "https://whereswilly.com" + }, + { + "name": "WikiHow", + "url": "https://wikihow.com" + }, + { + "name": "Windy", + "url": "https://www.windy.com" + }, + { + "name": "WonderHowTo", + "url": "https://wonderhowto.com" + }, + { + "name": "Working Nomads", + "url": "https://workingnomads.com" + }, + { + "name": "Wormhole", + "url": "https://wormhole.app" + }, + { + "name": "Y Combinator Jobs", + "url": "https://ycombinator.com" + }, + { + "name": "Yes Promo", + "url": "https://yespromo.me" + }, + { + "name": "YouGlish", + "url": "https://youglish.com" + }, + { + "name": "Zamzar", + "url": "https://zamzar.com" + }, + { + "name": "Zippyshare", + "url": "https://zippyshare.com" + }, + { + "name": "Zoom Earth", + "url": "https://zoom.earth" + }, + { + "name": "Zoom.it", + "url": "https://zoom.it" + } +] diff --git a/Server/utils/messages.js b/Server/utils/messages.js index 53a8f689f..e67e4e7e7 100644 --- a/Server/utils/messages.js +++ b/Server/utils/messages.js @@ -83,6 +83,7 @@ const successMessages = { MONITOR_DELETE: "Monitor deleted successfully", MONITOR_EDIT: "Monitor edited successfully", MONITOR_CERTIFICATE: "Got monitor certificate successfully", + MONITOR_DEMO_ADDED: "Successfully added demo monitors", //Job Queue JOB_QUEUE_DELETE_JOB: "Job removed successfully", diff --git a/Server/utils/utils.js b/Server/utils/utils.js index 934c99492..4331a4610 100644 --- a/Server/utils/utils.js +++ b/Server/utils/utils.js @@ -16,6 +16,18 @@ const ParseBoolean = (value) => { } }; +const getTokenFromHeaders = (headers) => { + const authorizationHeader = headers.authorization; + if (!authorizationHeader) throw new Error("No auth headers"); + + const parts = authorizationHeader.split(" "); + if (parts.length !== 2 || parts[0] !== "Bearer") + throw new Error("Invalid auth headers"); + + return parts[1]; +}; + module.exports = { ParseBoolean, + getTokenFromHeaders, }; From 3f5dc337a099858a5d901927676c50461f5c4e25 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 11 Sep 2024 11:22:33 +0800 Subject: [PATCH 07/82] Update delete all method --- Server/controllers/monitorController.js | 15 ++++++++++++--- Server/db/mongo/modules/monitorModule.js | 8 +++++--- Server/routes/monitorRoute.js | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 0b03488fd..27f306178 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -368,10 +368,20 @@ const deleteMonitor = async (req, res, next) => { const deleteAllMonitors = async (req, res) => { try { - const deleteCount = await req.db.deleteAllMonitors(); + const token = getTokenFromHeaders(req.headers); + const { teamId } = jwt.verify(token, process.env.JWT_SECRET); + const { monitors, deletedCount } = await req.db.deleteAllMonitors(teamId); + await monitors.forEach(async (monitor) => { + await req.jobQueue.deleteJob(monitor); + await req.db.deleteChecks(monitor._id); + await req.db.deleteAlertByMonitorId(monitor._id); + await req.db.deletePageSpeedChecksByMonitorId(monitor._id); + await req.db.deleteNotificationsByMonitorId(monitor._id); + }); + return res .status(200) - .json({ success: true, msg: `Deleted ${deleteCount} monitors` }); + .json({ success: true, msg: `Deleted ${deletedCount} monitors` }); } catch (error) { error.service = SERVICE_NAME; next(error); @@ -472,7 +482,6 @@ const pauseMonitor = async (req, res, next) => { const addDemoMonitors = async (req, res, next) => { try { const token = getTokenFromHeaders(req.headers); - // Get email from token const { _id, teamId } = jwt.verify(token, process.env.JWT_SECRET); const demoMonitors = await req.db.addDemoMonitors(_id, teamId); await demoMonitors.forEach(async (monitor) => { diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index b3d48c543..5eaec7bf9 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -451,10 +451,12 @@ const deleteMonitor = async (req, res) => { * DELETE ALL MONITORS (TEMP) */ -const deleteAllMonitors = async (req, res) => { +const deleteAllMonitors = async (teamId) => { try { - const deletedCount = await Monitor.deleteMany({}); - return deletedCount.deletedCount; + const monitors = await Monitor.find({ teamId }); + const { deletedCount } = await Monitor.deleteMany({ teamId }); + + return { monitors, deletedCount }; } catch (error) { throw error; } diff --git a/Server/routes/monitorRoute.js b/Server/routes/monitorRoute.js index 47c4c525c..c6bec5f0f 100644 --- a/Server/routes/monitorRoute.js +++ b/Server/routes/monitorRoute.js @@ -32,7 +32,7 @@ router.put( ); router.delete( - "/all", + "/", isAllowed(["superadmin"]), monitorController.deleteAllMonitors ); From 65cc70cbdda1e99bcc5307ea5d75db191d30a820 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 11 Sep 2024 11:39:32 +0800 Subject: [PATCH 08/82] remove unresponsive sites from demo list --- Server/db/mongo/modules/checkModule.js | 15 ++++++++++----- Server/service/networkService.js | 7 +++++-- Server/utils/demoMonitors.json | 21 +-------------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index 32968431d..da3ccb8f3 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -1,6 +1,7 @@ const Check = require("../../../models/Check"); const Monitor = require("../../../models/Monitor"); -const mongoose = require("mongoose"); +const logger = require("../../../utils/logger"); +const SERVICE_NAME = "checkModule"; const dateRangeLookup = { day: new Date(new Date().setDate(new Date().getDate() - 1)), week: new Date(new Date().setDate(new Date().getDate() - 7)), @@ -24,21 +25,25 @@ const createCheck = async (checkData) => { try { const { monitorId, status } = checkData; - const n = await Check.countDocuments({ monitorId }) + 1; + const n = (await Check.countDocuments({ monitorId })) + 1; const check = await new Check({ ...checkData }).save(); const monitor = await Monitor.findById(monitorId); if (!monitor) { - throw new Error("Monitor not found"); + logger.error("Monitor not found", { + service: SERVICE_NAME, + monitorId, + }); + return; } if (monitor.uptimePercentage === undefined) { - monitor.uptimePercentage = (status === true) ? 1 : 0; + monitor.uptimePercentage = status === true ? 1 : 0; } else { monitor.uptimePercentage = - (monitor.uptimePercentage * (n - 1) + (status === true ? 1: 0)) / n; + (monitor.uptimePercentage * (n - 1) + (status === true ? 1 : 0)) / n; } await monitor.save(); diff --git a/Server/service/networkService.js b/Server/service/networkService.js index e25a63ce5..0664ee05a 100644 --- a/Server/service/networkService.js +++ b/Server/service/networkService.js @@ -278,6 +278,7 @@ class NetworkService { default: logger.error(`Unsupported type: ${job.data.type}`, { service: this.SERVICE_NAME, + method: "getStatus", jobId: job.id, }); return false; @@ -296,11 +297,13 @@ class NetworkService { async logAndStoreCheck(data, writeToDB) { try { const insertedCheck = await writeToDB(data); - return insertedCheck.status; + if (insertedCheck !== null && insertedCheck !== undefined) { + return insertedCheck.status; + } } catch (error) { - console.log(error); logger.error(`Error wrtiting check for ${data.monitorId}`, { service: this.SERVICE_NAME, + method: "logAndStoreCheck", monitorId: data.monitorId, error: error, }); diff --git a/Server/utils/demoMonitors.json b/Server/utils/demoMonitors.json index 413ffc76a..6f57940f2 100644 --- a/Server/utils/demoMonitors.json +++ b/Server/utils/demoMonitors.json @@ -239,10 +239,6 @@ "name": "Do It Yourself", "url": "https://doityourself.com" }, - { - "name": "Donkey Car", - "url": "https://donkeycar.com" - }, { "name": "draw.io", "url": "https://drawio.com" @@ -323,10 +319,6 @@ "name": "Fix It Club", "url": "https://fixitclub.com" }, - { - "name": "FlexJobs", - "url": "https://flexjobs.com" - }, { "name": "Flightradar24", "url": "https://flightradar24.com" @@ -335,10 +327,6 @@ "name": "FlowCV ", "url": "https://flowcv.com" }, - { - "name": "Foco Clipping", - "url": "https://fococlipping.com" - }, { "name": "Font Squirrel", "url": "https://fontsquirrel.com" @@ -639,10 +627,6 @@ "name": "MediaFire", "url": "https://mediafire.com" }, - { - "name": "Mind Mup", - "url": "https://mindmup.com" - }, { "name": "Mixlr", "url": "https://mixlr.com" @@ -1003,10 +987,7 @@ "name": "Starkey Comics", "url": "https://starkeycomics.com" }, - { - "name": "Startups List", - "url": "https://startups-list.com" - }, + { "name": "Statista", "url": "https://statista.com" From c35157ffb47fef8077a26b13a792af90bd2427ec Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 11 Sep 2024 12:03:13 +0800 Subject: [PATCH 09/82] Add thunks for adding and removing demo monitors --- .../UptimeMonitors/uptimeMonitorsSlice.js | 74 +++++++++++++++++++ Client/src/Pages/Settings/index.jsx | 40 ++++++++-- Client/src/Utils/NetworkService.js | 40 ++++++++++ Server/controllers/monitorController.js | 2 + 4 files changed, 150 insertions(+), 6 deletions(-) diff --git a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js index ac3ce1d6f..a8b1ea737 100644 --- a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js +++ b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js @@ -164,6 +164,44 @@ export const deleteMonitorChecksByTeamId = createAsyncThunk( } } ); +export const addDemoMonitors = createAsyncThunk( + "monitors/addDemoMonitors", + async (data, thunkApi) => { + try { + const { authToken } = data; + const res = await networkService.addDemoMonitors(authToken); + return res.data; + } catch (error) { + if (error.response && error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); + } + } +); +export const deleteAllMonitors = createAsyncThunk( + "monitors/deleteAllMonitors", + async (data, thunkApi) => { + try { + const { authToken } = data; + const res = await networkService.deleteAllMonitors(authToken); + return res.data; + } catch (error) { + if (error.response && error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); + } + } +); const uptimeMonitorsSlice = createSlice({ name: "uptimeMonitors", @@ -306,6 +344,42 @@ const uptimeMonitorsSlice = createSlice({ state.msg = action.payload ? action.payload.msg : "Failed to pause uptime monitor"; + }) + // ***************************************************** + // Add Demo Monitors + // ***************************************************** + .addCase(addDemoMonitors.pending, (state) => { + state.isLoading = true; + }) + .addCase(addDemoMonitors.fulfilled, (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; + }) + .addCase(addDemoMonitors.rejected, (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to add demo uptime monitors"; + }) + // ***************************************************** + // Delete all Monitors + // ***************************************************** + .addCase(deleteAllMonitors.pending, (state) => { + state.isLoading = true; + }) + .addCase(deleteAllMonitors.fulfilled, (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; + }) + .addCase(deleteAllMonitors.rejected, (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to delete all monitors"; }); }, }); diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index 5f27abe26..cd00f440f 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -7,7 +7,11 @@ import { logger } from "../../Utils/Logger"; import "./index.css"; import { useDispatch, useSelector } from "react-redux"; import { createToast } from "../../Utils/toastUtils"; -import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; +import { + deleteMonitorChecksByTeamId, + addDemoMonitors, + deleteAllMonitors, +} from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; import PropTypes from "prop-types"; import LoadingButton from "@mui/lab/LoadingButton"; const Settings = ({ isAdmin }) => { @@ -36,8 +40,32 @@ const Settings = ({ isAdmin }) => { } }; - const addDemoMonitors = () => { - logger.warn("Click"); + const handleInsertDemoMonitors = async () => { + try { + const action = await dispatch(addDemoMonitors({ authToken })); + if (addDemoMonitors.fulfilled.match(action)) { + createToast({ body: "Successfully added demo monitors" }); + } else { + createToast({ body: "Failed to add demo monitors" }); + } + } catch (error) { + logger.error(error); + createToast({ Body: "Failed to add demo monitors" }); + } + }; + + const handleDeleteAllMonitors = async () => { + try { + const action = await dispatch(deleteAllMonitors({ authToken })); + if (deleteAllMonitors.fulfilled.match(action)) { + createToast({ body: "Successfully deleted all monitors" }); + } else { + createToast({ body: "Failed to add demo monitors" }); + } + } catch (error) { + logger.error(error); + createToast({ Body: "Failed to delete all monitors" }); + } }; const ConfigBox = styled("div")({ @@ -159,7 +187,7 @@ const Settings = ({ isAdmin }) => { variant="contained" color="primary" loading={isLoading} - onClick={addDemoMonitors} + onClick={handleInsertDemoMonitors} sx={{ mt: theme.spacing(4) }} > Add demo monitors @@ -169,9 +197,9 @@ const Settings = ({ isAdmin }) => { Remove all monitors {}} + onClick={handleDeleteAllMonitors} sx={{ mt: theme.spacing(4) }} > Remove all monitors diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index e4b7be526..a9d93b301 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -274,6 +274,46 @@ class NetworkService { ); } + /** + * ************************************ + * Adds demo monitors + * ************************************ + * + * @async + * @param {string} authToken - The authorization token to be used in the request header. + * @returns {Promise} The response from the axios POST request. + */ + async addDemoMonitors(authToken) { + return this.axiosInstance.post( + `/monitors/demo`, + {}, + { + headers: { + Authorization: `Bearer ${authToken}`, + "Content-Type": "application/json", + }, + } + ); + } + + /** + * ************************************ + * Deletes all monitors for a team by team ID + * ************************************ + * + * @async + * @param {string} authToken - The authorization token to be used in the request header. + * @returns {Promise} The response from the axios DELETE request. + */ + async deleteAllMonitors(authToken) { + return this.axiosInstance.delete(`/monitors/`, { + headers: { + Authorization: `Bearer ${authToken}`, + "Content-Type": "application/json", + }, + }); + } + /** * ************************************ * Gets the certificate expiry for a monitor diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 27f306178..c40135cdb 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -368,6 +368,7 @@ const deleteMonitor = async (req, res, next) => { const deleteAllMonitors = async (req, res) => { try { + console.log("WTF"); const token = getTokenFromHeaders(req.headers); const { teamId } = jwt.verify(token, process.env.JWT_SECRET); const { monitors, deletedCount } = await req.db.deleteAllMonitors(teamId); @@ -384,6 +385,7 @@ const deleteAllMonitors = async (req, res) => { .json({ success: true, msg: `Deleted ${deletedCount} monitors` }); } catch (error) { error.service = SERVICE_NAME; + error.method === undefined && error.method === "deleteAllMonitors"; next(error); } }; From 23dc8fed36aeabf5a17be3be8203ec13b9260002 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 11 Sep 2024 12:46:41 -0400 Subject: [PATCH 10/82] Finalized area chart, added custom tick --- .../Charts/MonitorDetailsAreaChart/index.jsx | 48 ++-- .../Charts/PagespeedLineChart/index.css | 0 .../Charts/PagespeedLineChart/index.jsx | 71 ------ Client/src/Pages/Monitors/Details/index.jsx | 10 +- Client/src/Pages/Monitors/Details/styled.jsx | 2 +- .../PageSpeed/Details/Charts/AreaChart.jsx | 209 ++++++++++++------ Client/src/Pages/PageSpeed/Details/index.jsx | 62 +++--- Client/src/Pages/PageSpeed/Details/styled.jsx | 28 ++- Client/src/Utils/Theme/darkTheme.js | 2 +- Client/src/assets/icons/ruler-icon.svg | 3 + 10 files changed, 245 insertions(+), 190 deletions(-) delete mode 100644 Client/src/Components/Charts/PagespeedLineChart/index.css delete mode 100644 Client/src/Components/Charts/PagespeedLineChart/index.jsx create mode 100644 Client/src/assets/icons/ruler-icon.svg diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index fd28b6e7e..023962cb0 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -6,10 +6,12 @@ import { Tooltip, CartesianGrid, ResponsiveContainer, + Text, } from "recharts"; import { Box, Stack, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useMemo } from "react"; +import { formatDate } from "../../../Utils/timeUtils"; import "./index.css"; const CustomToolTip = ({ active, payload, label }) => { @@ -87,20 +89,34 @@ const CustomToolTip = ({ active, payload, label }) => { return null; }; -const MonitorDetailsAreaChart = ({ checks }) => { - const formatDate = (timestamp) => { - const date = new Date(timestamp); - return date.toLocaleTimeString("en-US", { - hour: "numeric", - minute: "2-digit", - hour12: true, - }); - }; - - const memoizedChecks = useMemo(() => checks, [checks[0]]); - +const CustomTick = ({ x, y, payload, index }) => { const theme = useTheme(); + // Render nothing for the first tick + if (index === 0) return null; + + return ( + + {formatDate(new Date(payload.value), { + year: undefined, + month: undefined, + day: undefined, + })} + + ); +}; + +const MonitorDetailsAreaChart = ({ checks }) => { + const theme = useTheme(); + const memoizedChecks = useMemo(() => checks, [checks[0]]); + return ( { } + minTickGap={0} + axisLine={false} tickLine={false} - height={18} + height={20} + interval="equidistantPreserveStart" /> { - const keyToLabel = { - performance: "Performance", - seo: "SEO", - bestPractices: "Best practices", - accessibility: "Accessibility", - }; - - const colors = { - performance: "#2aa02b", - seo: "#9467bd", - bestPractices: "#ff7f0e", - accessibility: "#1f76b3", - }; - - const customize = { - legend: { position: { vertical: "bottom", horizontal: "middle" } }, - margin: { bottom: 75 }, - }; - - const xLabels = pageSpeedChecks.map((check) => { - return check.createdAt; - }); - - return ( - ({ - dataKey: key, - label: keyToLabel[key], - color: colors[key], - showMark: false, - }))} - yAxis={[{ min: 0, max: 100 }]} - xAxis={[ - { - scaleType: "point", - data: xLabels, - valueFormatter: (val) => new Date(val).toLocaleDateString(), - }, - ]} - dataset={pageSpeedChecks} - {...customize} - grid={{ vertical: true, horizontal: true }} - tooltip={{ trigger: "none" }} - slotProps={{ - legend: { - direction: "row", - position: { vertical: "bottom", horizontal: "middle" }, - padding: 2, - itemMarkWidth: 8, - itemMarkHeight: 8, - markGap: 5, - itemGap: 15, - labelStyle: { - fontSize: 13, - color: "#344054" - } - }, - }} - /> - ); -}; - -PageSpeedLineChart.propTypes = { - pageSpeedChecks: PropTypes.array, -}; - -export default PageSpeedLineChart; diff --git a/Client/src/Pages/Monitors/Details/index.jsx b/Client/src/Pages/Monitors/Details/index.jsx index 41e529eb9..76e06b408 100644 --- a/Client/src/Pages/Monitors/Details/index.jsx +++ b/Client/src/Pages/Monitors/Details/index.jsx @@ -445,14 +445,8 @@ const DetailsPage = ({ isAdmin }) => { data={[{ response: monitor?.periodAvgResponseTime }]} /> - - + + diff --git a/Client/src/Pages/Monitors/Details/styled.jsx b/Client/src/Pages/Monitors/Details/styled.jsx index 7f580d7c7..728df4922 100644 --- a/Client/src/Pages/Monitors/Details/styled.jsx +++ b/Client/src/Pages/Monitors/Details/styled.jsx @@ -76,7 +76,7 @@ export const StatBox = styled(Box)(({ theme }) => ({ borderColor: theme.palette.border.light, borderRadius: 4, backgroundColor: theme.palette.background.main, - background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`, + background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 45%)`, "& h2": { fontSize: 13, fontWeight: 500, diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx index 6c26c43bd..b040d87a5 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -1,3 +1,4 @@ +import PropTypes from "prop-types"; import { AreaChart, Area, @@ -5,6 +6,7 @@ import { Tooltip, CartesianGrid, ResponsiveContainer, + Text, } from "recharts"; import { useTheme } from "@emotion/react"; import { useMemo } from "react"; @@ -12,28 +14,37 @@ import { Box, Stack, Typography } from "@mui/material"; import { formatDate } from "../../../../Utils/timeUtils"; const config = { - accessibility: { - id: "accessibility", - text: "accessibility", - color: "primary", - }, - bestPractices: { - id: "bestPractices", - text: "best practices", - color: "warning", + seo: { + id: "seo", + text: "SEO", + color: "unresolved", }, performance: { id: "performance", text: "performance", color: "success", }, - seo: { - id: "seo", - text: "SEO", - color: "unresolved", + bestPractices: { + id: "bestPractices", + text: "best practices", + color: "warning", + }, + accessibility: { + id: "accessibility", + text: "accessibility", + color: "primary", }, }; +/** + * Custom tooltip for the area chart. + * @param {Object} props + * @param {boolean} props.active - Whether the tooltip is active. + * @param {Array} props.payload - The payload data for the tooltip. + * @param {string} props.label - The label for the tooltip. + * @returns {JSX.Element|null} The tooltip element or null if not active. + */ + const CustomToolTip = ({ active, payload, label }) => { const theme = useTheme(); @@ -58,50 +69,64 @@ const CustomToolTip = ({ active, payload, label }) => { > {formatDate(new Date(label))} - {Object.keys(config).map((key) => { - const { color } = config[key]; - const dotColor = theme.palette[color].main; + {Object.keys(config) + .reverse() + .map((key) => { + const { color } = config[key]; + const dotColor = theme.palette[color].main; - return ( - - - - {config[key].text} - {" "} - - {payload[0].payload[key]} - - - ); - })} + + + {config[key].text} + {" "} + + {payload[0].payload[key]} + + + ); + })} ); } return null; }; +CustomToolTip.propTypes = { + active: PropTypes.bool, + payload: PropTypes.array, + label: PropTypes.string, +}; + +/** + * Processes data to insert gaps with null values based on the interval. + * @param {Array} data + * @param {number} interval - The interval in milliseconds for gaps. + * @returns {Array} The formatted data with gaps. + */ const processDataWithGaps = (data, interval) => { if (data.length === 0) return []; let formattedData = []; @@ -137,6 +162,57 @@ const processDataWithGaps = (data, interval) => { return formattedData; }; +/** + * Custom tick component to render ticks on the XAxis. + * + * @param {Object} props + * @param {number} props.x - The x coordinate for the tick. + * @param {number} props.y - The y coordinate for the tick. + * @param {Object} props.payload - The data object containing the tick value. + * @param {number} props.index - The index of the tick in the array of ticks. + * + * @returns {JSX.Element|null} The tick element or null if the tick should be hidden. + */ +const CustomTick = ({ x, y, payload, index }) => { + const theme = useTheme(); + + // Render nothing for the first tick + if (index === 0) return null; + + return ( + + {formatDate(new Date(payload.value), { + year: undefined, + month: undefined, + day: undefined, + })} + + ); +}; +CustomTick.propTypes = { + x: PropTypes.number, + y: PropTypes.number, + payload: PropTypes.shape({ + value: PropTypes.string.isRequired, + }), + index: PropTypes.number, +}; + +/** + * A chart displaying pagespeed details over time. + * @param {Object} props + * @param {Array} props.data - The data to display in the chart. + * @param {number} props.interval - The interval in milliseconds for processing gaps. + * @returns {JSX.Element} The area chart component. + */ + const PagespeedDetailsAreaChart = ({ data, interval }) => { const theme = useTheme(); const memoizedData = useMemo( @@ -162,23 +238,12 @@ const PagespeedDetailsAreaChart = ({ data, interval }) => { - formatDate(new Date(timestamp), { - year: undefined, - month: undefined, - day: undefined, - }) - } - tick={{ - fontSize: 11, - fontWeight: 100, - opacity: 0.8, - stroke: theme.palette.text.tertiary, - }} + tick={} + axisLine={false} tickLine={false} - minTickGap={20} height={18} - interval="preserveEnd" + minTickGap={0} + interval="equidistantPreserveStart" /> { ); }; +PagespeedDetailsAreaChart.propTypes = { + data: PropTypes.arrayOf( + PropTypes.shape({ + createdAt: PropTypes.string.isRequired, + accessibility: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + .isRequired, + bestPractices: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + .isRequired, + performance: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + .isRequired, + seo: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, + }) + ).isRequired, + interval: PropTypes.number.isRequired, +}; + export default PagespeedDetailsAreaChart; diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 657ecc36d..07953609a 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -15,9 +15,9 @@ import { logger } from "../../../Utils/Logger"; import { networkService } from "../../../main"; import SkeletonLayout from "./skeleton"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; +import MetricsIcon from "../../../assets/icons/ruler-icon.svg?react"; import ScoreIcon from "../../../assets/icons/monitor-graph-line.svg?react"; import PerformanceIcon from "../../../assets/icons/performance-report.svg?react"; -import PageSpeedLineChart from "../../../Components/Charts/PagespeedLineChart"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; import PagespeedDetailsAreaChart from "./Charts/AreaChart"; @@ -402,23 +402,44 @@ const PageSpeedDetails = () => { - + Showing statistics for past 24 hours. + + + + + + Score history + + + + + + + + + + Metrics + + + - - - - - - Score history - - - - + @@ -536,16 +557,7 @@ const PageSpeedDetails = () => { - + ({ - gap: theme.spacing(8), + display: "grid", height: 300, minWidth: 250, - padding: theme.spacing(8), border: 1, borderStyle: "solid", borderColor: theme.palette.border.light, borderRadius: 4, + borderTopRightRadius: 16, + borderBottomRightRadius: 16, backgroundColor: theme.palette.background.main, "& h2": { color: theme.palette.text.secondary, fontSize: 15, fontWeight: 500, }, - "& p": { - color: theme.palette.text.secondary, + "& p": { color: theme.palette.text.secondary }, + "& > :nth-of-type(1)": { + gridColumn: 1, + gridRow: 1, + height: "fit-content", + paddingTop: theme.spacing(8), + paddingLeft: theme.spacing(8), + }, + "& > :nth-of-type(2)": { gridColumn: 1, gridRow: 2 }, + "& > :nth-of-type(3)": { + gridColumn: 2, + gridRow: "span 2", + padding: theme.spacing(8), + borderLeft: 1, + borderLeftStyle: "solid", + borderLeftColor: theme.palette.border.light, + borderRadius: 16, + backgroundColor: theme.palette.background.main, + background: `linear-gradient(325deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 45%)`, }, })); @@ -52,7 +70,7 @@ export const StatBox = styled(Box)(({ theme }) => ({ borderColor: theme.palette.border.light, borderRadius: 4, backgroundColor: theme.palette.background.main, - background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`, + background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 45%)`, "& h2": { fontSize: 13, fontWeight: 500, diff --git a/Client/src/Utils/Theme/darkTheme.js b/Client/src/Utils/Theme/darkTheme.js index 261f8135f..2d1f80635 100644 --- a/Client/src/Utils/Theme/darkTheme.js +++ b/Client/src/Utils/Theme/darkTheme.js @@ -63,7 +63,7 @@ const darkTheme = createTheme({ uptimeGood: "#ffd600", uptimeExcellent: "#079455", }, - unresolved: { main: "#4e5ba6", light: "#e2eaf7", bg: "#f2f4f7" }, + unresolved: { main: "#664eff", light: "#3a1bff", bg: "#f2f4f7" }, divider: border.light, other: { icon: "#e6e6e6", diff --git a/Client/src/assets/icons/ruler-icon.svg b/Client/src/assets/icons/ruler-icon.svg new file mode 100644 index 000000000..7266d2876 --- /dev/null +++ b/Client/src/assets/icons/ruler-icon.svg @@ -0,0 +1,3 @@ + + + From 16e9b64161d072833e834b96d0a3dd00a54475a7 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 11 Sep 2024 15:47:46 -0400 Subject: [PATCH 11/82] Implemented score chart filter --- .../PageSpeed/Details/Charts/AreaChart.jsx | 23 ++++--- Client/src/Pages/PageSpeed/Details/index.jsx | 63 ++++++++++++++++++- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx index b040d87a5..9523a31d7 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -45,7 +45,7 @@ const config = { * @returns {JSX.Element|null} The tooltip element or null if not active. */ -const CustomToolTip = ({ active, payload, label }) => { +const CustomToolTip = ({ active, payload, label, config }) => { const theme = useTheme(); if (active && payload && payload.length) { @@ -213,13 +213,20 @@ CustomTick.propTypes = { * @returns {JSX.Element} The area chart component. */ -const PagespeedDetailsAreaChart = ({ data, interval }) => { +const PagespeedDetailsAreaChart = ({ data, interval, metrics }) => { const theme = useTheme(); const memoizedData = useMemo( () => processDataWithGaps(data, interval), - [data] + [data[0]] ); + const filteredConfig = Object.keys(config).reduce((result, key) => { + if (metrics[key]) { + result[key] = config[key]; + } + return result; + }, {}); + return ( { /> } + content={} /> - {Object.values(config).map(({ id, color }) => { + {Object.values(filteredConfig).map(({ id, color }) => { const startColor = theme.palette[color].main; const endColor = theme.palette[color].light; @@ -262,8 +269,8 @@ const PagespeedDetailsAreaChart = ({ data, interval }) => { ); })} - {Object.keys(config).map((key) => { - const { color } = config[key]; + {Object.keys(filteredConfig).map((key) => { + const { color } = filteredConfig[key]; const strokeColor = theme.palette[color].main; const bgColor = theme.palette.background.main; @@ -275,7 +282,7 @@ const PagespeedDetailsAreaChart = ({ data, interval }) => { stackId={1} stroke={strokeColor} strokeWidth={1.5} - fill={`url(#${config[key].id})`} + fill={`url(#${filteredConfig[key].id})`} activeDot={{ stroke: bgColor, fill: strokeColor, r: 4.5 }} /> ); diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 07953609a..f87b6dcf8 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -1,5 +1,12 @@ import PropTypes from "prop-types"; -import { Box, Button, Stack, Tooltip, Typography } from "@mui/material"; +import { + Box, + Button, + Divider, + Stack, + Tooltip, + Typography, +} from "@mui/material"; import { PieChart } from "@mui/x-charts/PieChart"; import { useDrawingArea } from "@mui/x-charts"; import { useEffect, useState } from "react"; @@ -22,6 +29,7 @@ import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; import PagespeedDetailsAreaChart from "./Charts/AreaChart"; import "./index.css"; +import Checkbox from "../../../Components/Inputs/Checkbox"; /** * Renders a centered label within a pie chart. @@ -275,6 +283,16 @@ const PageSpeedDetails = () => { ); }; + const [metrics, setMetrics] = useState({ + accessibility: true, + bestPractices: true, + performance: true, + seo: true, + }); + const handleMetrics = (id) => { + setMetrics((prev) => ({ ...prev, [id]: !prev[id] })); + }; + return ( {loading ? ( @@ -420,6 +438,7 @@ const PageSpeedDetails = () => { @@ -433,6 +452,48 @@ const PageSpeedDetails = () => { Metrics + + + + Shown + + + + handleMetrics("accessibility")} + /> + + handleMetrics("bestPractices")} + /> + + handleMetrics("performance")} + /> + + handleMetrics("seo")} + /> + + From c0c1cf64acf4ac50b98a3fae912ddae76e69064e Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 11 Sep 2024 17:41:37 -0400 Subject: [PATCH 12/82] Refactored pie chart --- .../PageSpeed/Details/Charts/PieChart.jsx | 298 ++++++++++++++++++ Client/src/Pages/PageSpeed/Details/index.jsx | 250 +++------------ Client/src/Pages/PageSpeed/Details/styled.jsx | 2 +- Client/src/Utils/Theme/lightTheme.js | 2 +- 4 files changed, 338 insertions(+), 214 deletions(-) create mode 100644 Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx diff --git a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx new file mode 100644 index 000000000..be3b0cbb8 --- /dev/null +++ b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx @@ -0,0 +1,298 @@ +import PropTypes from "prop-types"; +import { PieChart as MuiPieChart } from "@mui/x-charts/PieChart"; +import { useDrawingArea } from "@mui/x-charts"; +import { useState } from "react"; +import { useTheme } from "@emotion/react"; +import { Box } from "@mui/material"; + +/** + * Renders a centered label within a pie chart. + * + * @param {Object} props + * @param {string | number} props.value - The value to display in the label. + * @param {string} props.color - The color of the text. + * @returns {JSX.Element} + */ +const PieCenterLabel = ({ value, color, setExpand }) => { + const { width, height } = useDrawingArea(); + return ( + setExpand(true)} + > + + + {value} + + + ); +}; + +PieCenterLabel.propTypes = { + value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + color: PropTypes.string, + setExpand: PropTypes.func, +}; + +/** + * A component that renders a label on a pie chart slice. + * The label is positioned relative to the center of the pie chart and is optionally highlighted. + * + * @param {Object} props + * @param {number} props.value - The value to display inside the pie slice. + * @param {number} props.startAngle - The starting angle of the pie slice in degrees. + * @param {number} props.endAngle - The ending angle of the pie slice in degrees. + * @param {string} props.color - The color of the label text when highlighted. + * @param {boolean} props.highlighted - Determines if the label should be highlighted or not. + * @returns {JSX.Element} + */ +const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => { + const { width, height } = useDrawingArea(); + + // Compute the midpoint angle in radians + const angle = (((startAngle + endAngle) / 2) * Math.PI) / 180; + const radius = height / 3.5; // length from center of the circle to where the text is positioned + + // Calculate x and y positions + const x = Math.sin(angle) * radius; + const y = -Math.cos(angle) * radius; + + return ( + + + +{value} + + + ); +}; + +const PieChart = ({ audits }) => { + const theme = useTheme(); + + /** + * Weight constants for different performance metrics. + * @type {Object} + */ + const weights = { + fcp: 10, + si: 10, + lcp: 25, + tbt: 30, + cls: 25, + }; + + /** + * Retrieves color properties based on the performance value. + * + * @param {number} value - The performance score used to determine the color properties. + * @returns {{stroke: string, strokeBg: string, text: string, bg: string}} The color properties for the given performance value. + */ + const getColors = (value) => { + if (value >= 90 && value <= 100) + return { + stroke: theme.palette.success.main, + strokeBg: theme.palette.success.light, + text: theme.palette.success.text, + bg: theme.palette.success.bg, + }; + else if (value >= 50 && value < 90) + return { + stroke: theme.palette.warning.main, + strokeBg: theme.palette.warning.light, + text: theme.palette.warning.text, + bg: theme.palette.warning.bg, + }; + else if (value >= 0 && value < 50) + return { + stroke: theme.palette.error.text, + strokeBg: theme.palette.error.light, + text: theme.palette.error.text, + bg: theme.palette.error.bg, + }; + return { + stroke: theme.palette.unresolved.main, + strokeBg: theme.palette.unresolved.light, + text: theme.palette.unresolved.main, + bg: theme.palette.unresolved.bg, + }; + }; + + /** + * Calculates and formats the data needed for rendering a pie chart based on audit scores and weights. + * This function generates properties for each pie slice, including angles, radii, and colors. + * It also calculates performance based on the weighted values. + * + * @returns {Array} An array of objects, each representing the properties for a slice of the pie chart. + * @returns {number} performance - A variable updated with the rounded sum of weighted values. + */ + let performance = 0; + const getPieData = (audits) => { + let props = []; + let startAngle = 0; + const padding = 3; // padding between arcs + const max = 360 - padding * (Object.keys(audits).length - 1); // _id is a child of audits + + Object.keys(audits).forEach((key) => { + if (audits[key].score) { + let value = audits[key].score * weights[key]; + let endAngle = startAngle + (weights[key] * max) / 100; + + let theme = getColors(audits[key].score * 100); + props.push({ + id: key, + data: [ + { + value: value, + color: theme.stroke, + label: key.toUpperCase(), + }, + { + value: weights[key] - value, + color: theme.strokeBg, + label: "", + }, + ], + arcLabel: (item) => `${item.label}`, + arcLabelRadius: 95, + startAngle: startAngle, + endAngle: endAngle, + innerRadius: 73, + outerRadius: 80, + cornerRadius: 2, + highlightScope: { faded: "global", highlighted: "series" }, + faded: { + innerRadius: 63, + outerRadius: 70, + additionalRadius: -20, + arcLabelRadius: 5, + }, + cx: pieSize.width / 2, + }); + + performance += Math.floor(value); + startAngle = endAngle + padding; + } + }); + + return props; + }; + + const pieSize = { width: 210, height: 200 }; + const pieData = getPieData(audits); + const colorMap = getColors(performance); + + const [highlightedItem, setHighLightedItem] = useState(null); + const [expand, setExpand] = useState(false); + return ( + setExpand(false)}> + {expand ? ( + + + {pieData?.map((pie) => ( + + ))} + + ) : ( + + + + )} + + ); +}; + +export default PieChart; diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index f87b6dcf8..f5ab4c987 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -7,7 +7,6 @@ import { Tooltip, Typography, } from "@mui/material"; -import { PieChart } from "@mui/x-charts/PieChart"; import { useDrawingArea } from "@mui/x-charts"; import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; @@ -30,6 +29,7 @@ import PulseDot from "../../../Components/Animated/PulseDot"; import PagespeedDetailsAreaChart from "./Charts/AreaChart"; import "./index.css"; import Checkbox from "../../../Components/Inputs/Checkbox"; +import PieChart from "./Charts/PieChart"; /** * Renders a centered label within a pie chart. @@ -151,125 +151,6 @@ const PageSpeedDetails = () => { fetchMonitor(); }, [monitorId, authToken, navigate]); - /** - * Weight constants for different performance metrics. - * @type {Object} - */ - const weights = { - fcp: 10, - si: 10, - lcp: 25, - tbt: 30, - cls: 25, - }; - - /** - * Retrieves color properties based on the performance value. - * - * @param {number} value - The performance score used to determine the color properties. - * @returns {{stroke: string, text: string, bg: string}} The color properties for the given performance value. - */ - const getColors = (value) => { - if (value >= 90 && value <= 100) - return { - stroke: theme.palette.success.main, - strokeBg: theme.palette.success.light, - text: theme.palette.success.text, - bg: theme.palette.success.bg, - shape: "circle", - }; - else if (value >= 50 && value < 90) - return { - stroke: theme.palette.warning.main, - strokeBg: theme.palette.warning.bg, - text: theme.palette.warning.text, - bg: theme.palette.warning.light, - shape: "square", - }; - else if (value >= 0 && value < 50) - return { - stroke: theme.palette.error.text, - strokeBg: theme.palette.error.light, - text: theme.palette.error.text, - bg: theme.palette.error.bg, - shape: "circle", - }; - return { - stroke: theme.palette.unresolved.main, - strokeBg: theme.palette.unresolved.light, - text: theme.palette.unresolved.main, - bg: theme.palette.unresolved.bg, - shape: "", - }; - }; - - /** - * Calculates and formats the data needed for rendering a pie chart based on audit scores and weights. - * This function generates properties for each pie slice, including angles, radii, and colors. - * It also calculates performance based on the weighted values. - * - * @returns {Array} An array of objects, each representing the properties for a slice of the pie chart. - * @returns {number} performance - A variable updated with the rounded sum of weighted values. - */ - let performance = 0; - const getPieData = (audits) => { - let props = []; - let startAngle = 0; - const padding = 3; // padding between arcs - const max = 360 - padding * (Object.keys(audits).length - 1); // _id is a child of audits - - Object.keys(audits).forEach((key) => { - if (audits[key].score) { - let value = audits[key].score * weights[key]; - let endAngle = startAngle + (weights[key] * max) / 100; - - let theme = getColors(audits[key].score * 100); - props.push({ - id: key, - data: [ - { - value: value, - color: theme.stroke, - label: key.toUpperCase(), - }, - { - value: weights[key] - value, - color: theme.strokeBg, - label: "", - }, - ], - arcLabel: (item) => `${item.label}`, - arcLabelRadius: 95, - startAngle: startAngle, - endAngle: endAngle, - innerRadius: 73, - outerRadius: 80, - cornerRadius: 2, - highlightScope: { faded: "global", highlighted: "series" }, - faded: { - innerRadius: 63, - outerRadius: 70, - additionalRadius: -20, - arcLabelRadius: 5, - }, - cx: pieSize.width / 2, - }); - - performance += Math.floor(value); - startAngle = endAngle + padding; - } - }); - - return props; - }; - - const pieSize = { width: 210, height: 200 }; - const pieData = getPieData(audits); - const colorMap = getColors(performance); - - const [highlightedItem, setHighLightedItem] = useState(null); - const [expand, setExpand] = useState(false); - let loading = Object.keys(monitor).length === 0; const data = monitor?.checks ? [...monitor.checks].reverse() : []; @@ -293,6 +174,38 @@ const PageSpeedDetails = () => { setMetrics((prev) => ({ ...prev, [id]: !prev[id] })); }; + /** + * Retrieves color properties based on the performance value. + * + * @param {number} value - The performance score used to determine the color properties. + * @returns {{stroke: string, text: string, shape: string}} The color properties for the given performance value. + */ + const getColors = (value) => { + if (value >= 90 && value <= 100) + return { + stroke: theme.palette.success.main, + text: theme.palette.success.text, + shape: "circle", + }; + else if (value >= 50 && value < 90) + return { + stroke: theme.palette.warning.main, + text: theme.palette.warning.text, + shape: "square", + }; + else if (value >= 0 && value < 50) + return { + stroke: theme.palette.error.text, + text: theme.palette.error.text, + shape: "circle", + }; + return { + stroke: theme.palette.unresolved.main, + text: theme.palette.unresolved.main, + shape: "", + }; + }; + return ( {loading ? ( @@ -499,7 +412,8 @@ const PageSpeedDetails = () => { @@ -512,98 +426,10 @@ const PageSpeedDetails = () => { textAlign="center" minWidth="300px" flex={1} - px={theme.spacing(20)} - py={theme.spacing(8)} + p={theme.spacing(12)} > - setExpand(false)}> - {expand ? ( - - - {pieData?.map((pie) => ( - - ))} - - ) : ( - - - - )} - - + + Values are estimated and may vary.{" "} ({ fontSize: 15, fontWeight: 500, }, - "& p": { color: theme.palette.text.secondary }, + "& p": { color: theme.palette.text.tertiary }, "& > :nth-of-type(1)": { gridColumn: 1, gridRow: 1, diff --git a/Client/src/Utils/Theme/lightTheme.js b/Client/src/Utils/Theme/lightTheme.js index f00ece091..92e7f7817 100644 --- a/Client/src/Utils/Theme/lightTheme.js +++ b/Client/src/Utils/Theme/lightTheme.js @@ -51,7 +51,7 @@ const lightTheme = createTheme({ text: "#DC6803", main: "#fdb022", light: "#ffecbc", - bg: "#fffcf5", + bg: "#fef8ea", border: "#fec84b", }, percentage: { From 40076e177203d1bc9dc63b42f5467854355e2d61 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 11:36:22 +0800 Subject: [PATCH 13/82] add timezone to UI slize --- Client/src/Features/UI/uiSlice.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Client/src/Features/UI/uiSlice.js b/Client/src/Features/UI/uiSlice.js index 947055ddc..2b6a08e8d 100644 --- a/Client/src/Features/UI/uiSlice.js +++ b/Client/src/Features/UI/uiSlice.js @@ -14,6 +14,7 @@ const initialState = { }, mode: "light", greeting: { index: 0, lastUpdate: null }, + timezone: "America/Toronto", }; const uiSlice = createSlice({ @@ -36,9 +37,17 @@ const uiSlice = createSlice({ state.greeting.index = action.payload.index; state.greeting.lastUpdate = action.payload.lastUpdate; }, + setTimezone(state, action) { + state.timezone = action.payload.timezone; + }, }, }); export default uiSlice.reducer; -export const { setRowsPerPage, toggleSidebar, setMode, setGreeting } = - uiSlice.actions; +export const { + setRowsPerPage, + toggleSidebar, + setMode, + setGreeting, + setTimezone, +} = uiSlice.actions; From 40cb5ba189210818997b5862f750c1f4e0b820ce Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 11:36:42 +0800 Subject: [PATCH 14/82] Add timzones file --- Client/src/Utils/timezones.json | 1698 +++++++++++++++++++++++++++++++ 1 file changed, 1698 insertions(+) create mode 100644 Client/src/Utils/timezones.json diff --git a/Client/src/Utils/timezones.json b/Client/src/Utils/timezones.json new file mode 100644 index 000000000..361acbba7 --- /dev/null +++ b/Client/src/Utils/timezones.json @@ -0,0 +1,1698 @@ +[ + { + "_id": "Africa/Abidjan", + "name": "Africa/Abidjan" + }, + { + "_id": "Africa/Accra", + "name": "Africa/Accra" + }, + { + "_id": "Africa/Addis_Ababa", + "name": "Africa/Addis_Ababa" + }, + { + "_id": "Africa/Algiers", + "name": "Africa/Algiers" + }, + { + "_id": "Africa/Asmara", + "name": "Africa/Asmara" + }, + { + "_id": "Africa/Bamako", + "name": "Africa/Bamako" + }, + { + "_id": "Africa/Bangui", + "name": "Africa/Bangui" + }, + { + "_id": "Africa/Banjul", + "name": "Africa/Banjul" + }, + { + "_id": "Africa/Bissau", + "name": "Africa/Bissau" + }, + { + "_id": "Africa/Blantyre", + "name": "Africa/Blantyre" + }, + { + "_id": "Africa/Brazzaville", + "name": "Africa/Brazzaville" + }, + { + "_id": "Africa/Bujumbura", + "name": "Africa/Bujumbura" + }, + { + "_id": "Africa/Cairo", + "name": "Africa/Cairo" + }, + { + "_id": "Africa/Casablanca", + "name": "Africa/Casablanca" + }, + { + "_id": "Africa/Ceuta", + "name": "Africa/Ceuta" + }, + { + "_id": "Africa/Conakry", + "name": "Africa/Conakry" + }, + { + "_id": "Africa/Dakar", + "name": "Africa/Dakar" + }, + { + "_id": "Africa/Dar_es_Salaam", + "name": "Africa/Dar_es_Salaam" + }, + { + "_id": "Africa/Djibouti", + "name": "Africa/Djibouti" + }, + { + "_id": "Africa/Douala", + "name": "Africa/Douala" + }, + { + "_id": "Africa/El_Aaiun", + "name": "Africa/El_Aaiun" + }, + { + "_id": "Africa/Freetown", + "name": "Africa/Freetown" + }, + { + "_id": "Africa/Gaborone", + "name": "Africa/Gaborone" + }, + { + "_id": "Africa/Harare", + "name": "Africa/Harare" + }, + { + "_id": "Africa/Johannesburg", + "name": "Africa/Johannesburg" + }, + { + "_id": "Africa/Juba", + "name": "Africa/Juba" + }, + { + "_id": "Africa/Kampala", + "name": "Africa/Kampala" + }, + { + "_id": "Africa/Khartoum", + "name": "Africa/Khartoum" + }, + { + "_id": "Africa/Kigali", + "name": "Africa/Kigali" + }, + { + "_id": "Africa/Kinshasa", + "name": "Africa/Kinshasa" + }, + { + "_id": "Africa/Lagos", + "name": "Africa/Lagos" + }, + { + "_id": "Africa/Libreville", + "name": "Africa/Libreville" + }, + { + "_id": "Africa/Lome", + "name": "Africa/Lome" + }, + { + "_id": "Africa/Luanda", + "name": "Africa/Luanda" + }, + { + "_id": "Africa/Lubumbashi", + "name": "Africa/Lubumbashi" + }, + { + "_id": "Africa/Lusaka", + "name": "Africa/Lusaka" + }, + { + "_id": "Africa/Malabo", + "name": "Africa/Malabo" + }, + { + "_id": "Africa/Maputo", + "name": "Africa/Maputo" + }, + { + "_id": "Africa/Maseru", + "name": "Africa/Maseru" + }, + { + "_id": "Africa/Mbabane", + "name": "Africa/Mbabane" + }, + { + "_id": "Africa/Mogadishu", + "name": "Africa/Mogadishu" + }, + { + "_id": "Africa/Monrovia", + "name": "Africa/Monrovia" + }, + { + "_id": "Africa/Nairobi", + "name": "Africa/Nairobi" + }, + { + "_id": "Africa/Ndjamena", + "name": "Africa/Ndjamena" + }, + { + "_id": "Africa/Niamey", + "name": "Africa/Niamey" + }, + { + "_id": "Africa/Nouakchott", + "name": "Africa/Nouakchott" + }, + { + "_id": "Africa/Ouagadougou", + "name": "Africa/Ouagadougou" + }, + { + "_id": "Africa/Porto-Novo", + "name": "Africa/Porto-Novo" + }, + { + "_id": "Africa/Sao_Tome", + "name": "Africa/Sao_Tome" + }, + { + "_id": "Africa/Tripoli", + "name": "Africa/Tripoli" + }, + { + "_id": "Africa/Tunis", + "name": "Africa/Tunis" + }, + { + "_id": "Africa/Windhoek", + "name": "Africa/Windhoek" + }, + { + "_id": "America/Adak", + "name": "America/Adak" + }, + { + "_id": "America/Anchorage", + "name": "America/Anchorage" + }, + { + "_id": "America/Anguilla", + "name": "America/Anguilla" + }, + { + "_id": "America/Antigua", + "name": "America/Antigua" + }, + { + "_id": "America/Araguaina", + "name": "America/Araguaina" + }, + { + "_id": "America/Argentina/Buenos_Aires", + "name": "America/Argentina/Buenos_Aires" + }, + { + "_id": "America/Argentina/Catamarca", + "name": "America/Argentina/Catamarca" + }, + { + "_id": "America/Argentina/Cordoba", + "name": "America/Argentina/Cordoba" + }, + { + "_id": "America/Argentina/Jujuy", + "name": "America/Argentina/Jujuy" + }, + { + "_id": "America/Argentina/La_Rioja", + "name": "America/Argentina/La_Rioja" + }, + { + "_id": "America/Argentina/Mendoza", + "name": "America/Argentina/Mendoza" + }, + { + "_id": "America/Argentina/Rio_Gallegos", + "name": "America/Argentina/Rio_Gallegos" + }, + { + "_id": "America/Argentina/Salta", + "name": "America/Argentina/Salta" + }, + { + "_id": "America/Argentina/San_Juan", + "name": "America/Argentina/San_Juan" + }, + { + "_id": "America/Argentina/San_Luis", + "name": "America/Argentina/San_Luis" + }, + { + "_id": "America/Argentina/Tucuman", + "name": "America/Argentina/Tucuman" + }, + { + "_id": "America/Argentina/Ushuaia", + "name": "America/Argentina/Ushuaia" + }, + { + "_id": "America/Aruba", + "name": "America/Aruba" + }, + { + "_id": "America/Asuncion", + "name": "America/Asuncion" + }, + { + "_id": "America/Atikokan", + "name": "America/Atikokan" + }, + { + "_id": "America/Bahia", + "name": "America/Bahia" + }, + { + "_id": "America/Bahia_Banderas", + "name": "America/Bahia_Banderas" + }, + { + "_id": "America/Barbados", + "name": "America/Barbados" + }, + { + "_id": "America/Belem", + "name": "America/Belem" + }, + { + "_id": "America/Belize", + "name": "America/Belize" + }, + { + "_id": "America/Blanc-Sablon", + "name": "America/Blanc-Sablon" + }, + { + "_id": "America/Boa_Vista", + "name": "America/Boa_Vista" + }, + { + "_id": "America/Bogota", + "name": "America/Bogota" + }, + { + "_id": "America/Boise", + "name": "America/Boise" + }, + { + "_id": "America/Cambridge_Bay", + "name": "America/Cambridge_Bay" + }, + { + "_id": "America/Campo_Grande", + "name": "America/Campo_Grande" + }, + { + "_id": "America/Cancun", + "name": "America/Cancun" + }, + { + "_id": "America/Caracas", + "name": "America/Caracas" + }, + { + "_id": "America/Cayenne", + "name": "America/Cayenne" + }, + { + "_id": "America/Cayman", + "name": "America/Cayman" + }, + { + "_id": "America/Chicago", + "name": "America/Chicago" + }, + { + "_id": "America/Chihuahua", + "name": "America/Chihuahua" + }, + { + "_id": "America/Costa_Rica", + "name": "America/Costa_Rica" + }, + { + "_id": "America/Creston", + "name": "America/Creston" + }, + { + "_id": "America/Cuiaba", + "name": "America/Cuiaba" + }, + { + "_id": "America/Curacao", + "name": "America/Curacao" + }, + { + "_id": "America/Danmarkshavn", + "name": "America/Danmarkshavn" + }, + { + "_id": "America/Dawson", + "name": "America/Dawson" + }, + { + "_id": "America/Dawson_Creek", + "name": "America/Dawson_Creek" + }, + { + "_id": "America/Denver", + "name": "America/Denver" + }, + { + "_id": "America/Detroit", + "name": "America/Detroit" + }, + { + "_id": "America/Dominica", + "name": "America/Dominica" + }, + { + "_id": "America/Edmonton", + "name": "America/Edmonton" + }, + { + "_id": "America/Eirunepe", + "name": "America/Eirunepe" + }, + { + "_id": "America/El_Salvador", + "name": "America/El_Salvador" + }, + { + "_id": "America/Fort_Nelson", + "name": "America/Fort_Nelson" + }, + { + "_id": "America/Fortaleza", + "name": "America/Fortaleza" + }, + { + "_id": "America/Glace_Bay", + "name": "America/Glace_Bay" + }, + { + "_id": "America/Godthab", + "name": "America/Godthab" + }, + { + "_id": "America/Goose_Bay", + "name": "America/Goose_Bay" + }, + { + "_id": "America/Grand_Turk", + "name": "America/Grand_Turk" + }, + { + "_id": "America/Grenada", + "name": "America/Grenada" + }, + { + "_id": "America/Guadeloupe", + "name": "America/Guadeloupe" + }, + { + "_id": "America/Guatemala", + "name": "America/Guatemala" + }, + { + "_id": "America/Guayaquil", + "name": "America/Guayaquil" + }, + { + "_id": "America/Guyana", + "name": "America/Guyana" + }, + { + "_id": "America/Halifax", + "name": "America/Halifax" + }, + { + "_id": "America/Havana", + "name": "America/Havana" + }, + { + "_id": "America/Hermosillo", + "name": "America/Hermosillo" + }, + { + "_id": "America/Indiana/Indianapolis", + "name": "America/Indiana/Indianapolis" + }, + { + "_id": "America/Indiana/Knox", + "name": "America/Indiana/Knox" + }, + { + "_id": "America/Indiana/Marengo", + "name": "America/Indiana/Marengo" + }, + { + "_id": "America/Indiana/Petersburg", + "name": "America/Indiana/Petersburg" + }, + { + "_id": "America/Indiana/Tell_City", + "name": "America/Indiana/Tell_City" + }, + { + "_id": "America/Indiana/Vevay", + "name": "America/Indiana/Vevay" + }, + { + "_id": "America/Indiana/Vincennes", + "name": "America/Indiana/Vincennes" + }, + { + "_id": "America/Indiana/Winamac", + "name": "America/Indiana/Winamac" + }, + { + "_id": "America/Inuvik", + "name": "America/Inuvik" + }, + { + "_id": "America/Iqaluit", + "name": "America/Iqaluit" + }, + { + "_id": "America/Jamaica", + "name": "America/Jamaica" + }, + { + "_id": "America/Juneau", + "name": "America/Juneau" + }, + { + "_id": "America/Kentucky/Louisville", + "name": "America/Kentucky/Louisville" + }, + { + "_id": "America/Kentucky/Monticello", + "name": "America/Kentucky/Monticello" + }, + { + "_id": "America/Kralendijk", + "name": "America/Kralendijk" + }, + { + "_id": "America/La_Paz", + "name": "America/La_Paz" + }, + { + "_id": "America/Lima", + "name": "America/Lima" + }, + { + "_id": "America/Los_Angeles", + "name": "America/Los_Angeles" + }, + { + "_id": "America/Lower_Princes", + "name": "America/Lower_Princes" + }, + { + "_id": "America/Maceio", + "name": "America/Maceio" + }, + { + "_id": "America/Managua", + "name": "America/Managua" + }, + { + "_id": "America/Manaus", + "name": "America/Manaus" + }, + { + "_id": "America/Marigot", + "name": "America/Marigot" + }, + { + "_id": "America/Martinique", + "name": "America/Martinique" + }, + { + "_id": "America/Matamoros", + "name": "America/Matamoros" + }, + { + "_id": "America/Mazatlan", + "name": "America/Mazatlan" + }, + { + "_id": "America/Menominee", + "name": "America/Menominee" + }, + { + "_id": "America/Merida", + "name": "America/Merida" + }, + { + "_id": "America/Metlakatla", + "name": "America/Metlakatla" + }, + { + "_id": "America/Mexico_City", + "name": "America/Mexico_City" + }, + { + "_id": "America/Miquelon", + "name": "America/Miquelon" + }, + { + "_id": "America/Moncton", + "name": "America/Moncton" + }, + { + "_id": "America/Monterrey", + "name": "America/Monterrey" + }, + { + "_id": "America/Montevideo", + "name": "America/Montevideo" + }, + { + "_id": "America/Montserrat", + "name": "America/Montserrat" + }, + { + "_id": "America/Nassau", + "name": "America/Nassau" + }, + { + "_id": "America/New_York", + "name": "America/New_York" + }, + { + "_id": "America/Nipigon", + "name": "America/Nipigon" + }, + { + "_id": "America/Nome", + "name": "America/Nome" + }, + { + "_id": "America/Noronha", + "name": "America/Noronha" + }, + { + "_id": "America/North_Dakota/Beulah", + "name": "America/North_Dakota/Beulah" + }, + { + "_id": "America/North_Dakota/Center", + "name": "America/North_Dakota/Center" + }, + { + "_id": "America/North_Dakota/New_Salem", + "name": "America/North_Dakota/New_Salem" + }, + { + "_id": "America/Ojinaga", + "name": "America/Ojinaga" + }, + { + "_id": "America/Panama", + "name": "America/Panama" + }, + { + "_id": "America/Pangnirtung", + "name": "America/Pangnirtung" + }, + { + "_id": "America/Paramaribo", + "name": "America/Paramaribo" + }, + { + "_id": "America/Phoenix", + "name": "America/Phoenix" + }, + { + "_id": "America/Port_of_Spain", + "name": "America/Port_of_Spain" + }, + { + "_id": "America/Port-au-Prince", + "name": "America/Port-au-Prince" + }, + { + "_id": "America/Porto_Velho", + "name": "America/Porto_Velho" + }, + { + "_id": "America/Puerto_Rico", + "name": "America/Puerto_Rico" + }, + { + "_id": "America/Punta_Arenas", + "name": "America/Punta_Arenas" + }, + { + "_id": "America/Rainy_River", + "name": "America/Rainy_River" + }, + { + "_id": "America/Rankin_Inlet", + "name": "America/Rankin_Inlet" + }, + { + "_id": "America/Recife", + "name": "America/Recife" + }, + { + "_id": "America/Regina", + "name": "America/Regina" + }, + { + "_id": "America/Resolute", + "name": "America/Resolute" + }, + { + "_id": "America/Rio_Branco", + "name": "America/Rio_Branco" + }, + { + "_id": "America/Santarem", + "name": "America/Santarem" + }, + { + "_id": "America/Santiago", + "name": "America/Santiago" + }, + { + "_id": "America/Santo_Domingo", + "name": "America/Santo_Domingo" + }, + { + "_id": "America/Sao_Paulo", + "name": "America/Sao_Paulo" + }, + { + "_id": "America/Scoresbysund", + "name": "America/Scoresbysund" + }, + { + "_id": "America/Sitka", + "name": "America/Sitka" + }, + { + "_id": "America/St_Barthelemy", + "name": "America/St_Barthelemy" + }, + { + "_id": "America/St_Johns", + "name": "America/St_Johns" + }, + { + "_id": "America/St_Kitts", + "name": "America/St_Kitts" + }, + { + "_id": "America/St_Lucia", + "name": "America/St_Lucia" + }, + { + "_id": "America/St_Thomas", + "name": "America/St_Thomas" + }, + { + "_id": "America/St_Vincent", + "name": "America/St_Vincent" + }, + { + "_id": "America/Swift_Current", + "name": "America/Swift_Current" + }, + { + "_id": "America/Tegucigalpa", + "name": "America/Tegucigalpa" + }, + { + "_id": "America/Thule", + "name": "America/Thule" + }, + { + "_id": "America/Thunder_Bay", + "name": "America/Thunder_Bay" + }, + { + "_id": "America/Tijuana", + "name": "America/Tijuana" + }, + { + "_id": "America/Toronto", + "name": "America/Toronto" + }, + { + "_id": "America/Tortola", + "name": "America/Tortola" + }, + { + "_id": "America/Vancouver", + "name": "America/Vancouver" + }, + { + "_id": "America/Whitehorse", + "name": "America/Whitehorse" + }, + { + "_id": "America/Winnipeg", + "name": "America/Winnipeg" + }, + { + "_id": "America/Yakutat", + "name": "America/Yakutat" + }, + { + "_id": "America/Yellowknife", + "name": "America/Yellowknife" + }, + { + "_id": "Antarctica/Casey", + "name": "Antarctica/Casey" + }, + { + "_id": "Antarctica/Davis", + "name": "Antarctica/Davis" + }, + { + "_id": "Antarctica/DumontDUrville", + "name": "Antarctica/DumontDUrville" + }, + { + "_id": "Antarctica/Macquarie", + "name": "Antarctica/Macquarie" + }, + { + "_id": "Antarctica/Mawson", + "name": "Antarctica/Mawson" + }, + { + "_id": "Antarctica/McMurdo", + "name": "Antarctica/McMurdo" + }, + { + "_id": "Antarctica/Palmer", + "name": "Antarctica/Palmer" + }, + { + "_id": "Antarctica/Rothera", + "name": "Antarctica/Rothera" + }, + { + "_id": "Antarctica/Syowa", + "name": "Antarctica/Syowa" + }, + { + "_id": "Antarctica/Troll", + "name": "Antarctica/Troll" + }, + { + "_id": "Antarctica/Vostok", + "name": "Antarctica/Vostok" + }, + { + "_id": "Arctic/Longyearbyen", + "name": "Arctic/Longyearbyen" + }, + { + "_id": "Asia/Aden", + "name": "Asia/Aden" + }, + { + "_id": "Asia/Almaty", + "name": "Asia/Almaty" + }, + { + "_id": "Asia/Amman", + "name": "Asia/Amman" + }, + { + "_id": "Asia/Anadyr", + "name": "Asia/Anadyr" + }, + { + "_id": "Asia/Aqtau", + "name": "Asia/Aqtau" + }, + { + "_id": "Asia/Aqtobe", + "name": "Asia/Aqtobe" + }, + { + "_id": "Asia/Ashgabat", + "name": "Asia/Ashgabat" + }, + { + "_id": "Asia/Atyrau", + "name": "Asia/Atyrau" + }, + { + "_id": "Asia/Baghdad", + "name": "Asia/Baghdad" + }, + { + "_id": "Asia/Bahrain", + "name": "Asia/Bahrain" + }, + { + "_id": "Asia/Baku", + "name": "Asia/Baku" + }, + { + "_id": "Asia/Bangkok", + "name": "Asia/Bangkok" + }, + { + "_id": "Asia/Barnaul", + "name": "Asia/Barnaul" + }, + { + "_id": "Asia/Beirut", + "name": "Asia/Beirut" + }, + { + "_id": "Asia/Bishkek", + "name": "Asia/Bishkek" + }, + { + "_id": "Asia/Brunei", + "name": "Asia/Brunei" + }, + { + "_id": "Asia/Chita", + "name": "Asia/Chita" + }, + { + "_id": "Asia/Choibalsan", + "name": "Asia/Choibalsan" + }, + { + "_id": "Asia/Colombo", + "name": "Asia/Colombo" + }, + { + "_id": "Asia/Damascus", + "name": "Asia/Damascus" + }, + { + "_id": "Asia/Dhaka", + "name": "Asia/Dhaka" + }, + { + "_id": "Asia/Dili", + "name": "Asia/Dili" + }, + { + "_id": "Asia/Dubai", + "name": "Asia/Dubai" + }, + { + "_id": "Asia/Dushanbe", + "name": "Asia/Dushanbe" + }, + { + "_id": "Asia/Famagusta", + "name": "Asia/Famagusta" + }, + { + "_id": "Asia/Gaza", + "name": "Asia/Gaza" + }, + { + "_id": "Asia/Hebron", + "name": "Asia/Hebron" + }, + { + "_id": "Asia/Ho_Chi_Minh", + "name": "Asia/Ho_Chi_Minh" + }, + { + "_id": "Asia/Hong_Kong", + "name": "Asia/Hong_Kong" + }, + { + "_id": "Asia/Hovd", + "name": "Asia/Hovd" + }, + { + "_id": "Asia/Irkutsk", + "name": "Asia/Irkutsk" + }, + { + "_id": "Asia/Jakarta", + "name": "Asia/Jakarta" + }, + { + "_id": "Asia/Jayapura", + "name": "Asia/Jayapura" + }, + { + "_id": "Asia/Jerusalem", + "name": "Asia/Jerusalem" + }, + { + "_id": "Asia/Kabul", + "name": "Asia/Kabul" + }, + { + "_id": "Asia/Kamchatka", + "name": "Asia/Kamchatka" + }, + { + "_id": "Asia/Karachi", + "name": "Asia/Karachi" + }, + { + "_id": "Asia/Kathmandu", + "name": "Asia/Kathmandu" + }, + { + "_id": "Asia/Khandyga", + "name": "Asia/Khandyga" + }, + { + "_id": "Asia/Kolkata", + "name": "Asia/Kolkata" + }, + { + "_id": "Asia/Krasnoyarsk", + "name": "Asia/Krasnoyarsk" + }, + { + "_id": "Asia/Kuala_Lumpur", + "name": "Asia/Kuala_Lumpur" + }, + { + "_id": "Asia/Kuching", + "name": "Asia/Kuching" + }, + { + "_id": "Asia/Kuwait", + "name": "Asia/Kuwait" + }, + { + "_id": "Asia/Macau", + "name": "Asia/Macau" + }, + { + "_id": "Asia/Magadan", + "name": "Asia/Magadan" + }, + { + "_id": "Asia/Makassar", + "name": "Asia/Makassar" + }, + { + "_id": "Asia/Manila", + "name": "Asia/Manila" + }, + { + "_id": "Asia/Muscat", + "name": "Asia/Muscat" + }, + { + "_id": "Asia/Nicosia", + "name": "Asia/Nicosia" + }, + { + "_id": "Asia/Novokuznetsk", + "name": "Asia/Novokuznetsk" + }, + { + "_id": "Asia/Novosibirsk", + "name": "Asia/Novosibirsk" + }, + { + "_id": "Asia/Omsk", + "name": "Asia/Omsk" + }, + { + "_id": "Asia/Oral", + "name": "Asia/Oral" + }, + { + "_id": "Asia/Phnom_Penh", + "name": "Asia/Phnom_Penh" + }, + { + "_id": "Asia/Pontianak", + "name": "Asia/Pontianak" + }, + { + "_id": "Asia/Pyongyang", + "name": "Asia/Pyongyang" + }, + { + "_id": "Asia/Qatar", + "name": "Asia/Qatar" + }, + { + "_id": "Asia/Qostanay", + "name": "Asia/Qostanay" + }, + { + "_id": "Asia/Qyzylorda", + "name": "Asia/Qyzylorda" + }, + { + "_id": "Asia/Riyadh", + "name": "Asia/Riyadh" + }, + { + "_id": "Asia/Sakhalin", + "name": "Asia/Sakhalin" + }, + { + "_id": "Asia/Samarkand", + "name": "Asia/Samarkand" + }, + { + "_id": "Asia/Seoul", + "name": "Asia/Seoul" + }, + { + "_id": "Asia/Shanghai", + "name": "Asia/Shanghai" + }, + { + "_id": "Asia/Singapore", + "name": "Asia/Singapore" + }, + { + "_id": "Asia/Srednekolymsk", + "name": "Asia/Srednekolymsk" + }, + { + "_id": "Asia/Taipei", + "name": "Asia/Taipei" + }, + { + "_id": "Asia/Tashkent", + "name": "Asia/Tashkent" + }, + { + "_id": "Asia/Tbilisi", + "name": "Asia/Tbilisi" + }, + { + "_id": "Asia/Tehran", + "name": "Asia/Tehran" + }, + { + "_id": "Asia/Thimphu", + "name": "Asia/Thimphu" + }, + { + "_id": "Asia/Tokyo", + "name": "Asia/Tokyo" + }, + { + "_id": "Asia/Tomsk", + "name": "Asia/Tomsk" + }, + { + "_id": "Asia/Ulaanbaatar", + "name": "Asia/Ulaanbaatar" + }, + { + "_id": "Asia/Urumqi", + "name": "Asia/Urumqi" + }, + { + "_id": "Asia/Ust-Nera", + "name": "Asia/Ust-Nera" + }, + { + "_id": "Asia/Vientiane", + "name": "Asia/Vientiane" + }, + { + "_id": "Asia/Vladivostok", + "name": "Asia/Vladivostok" + }, + { + "_id": "Asia/Yakutsk", + "name": "Asia/Yakutsk" + }, + { + "_id": "Asia/Yangon", + "name": "Asia/Yangon" + }, + { + "_id": "Asia/Yekaterinburg", + "name": "Asia/Yekaterinburg" + }, + { + "_id": "Asia/Yerevan", + "name": "Asia/Yerevan" + }, + { + "_id": "Atlantic/Azores", + "name": "Atlantic/Azores" + }, + { + "_id": "Atlantic/Bermuda", + "name": "Atlantic/Bermuda" + }, + { + "_id": "Atlantic/Canary", + "name": "Atlantic/Canary" + }, + { + "_id": "Atlantic/Cape_Verde", + "name": "Atlantic/Cape_Verde" + }, + { + "_id": "Atlantic/Faroe", + "name": "Atlantic/Faroe" + }, + { + "_id": "Atlantic/Madeira", + "name": "Atlantic/Madeira" + }, + { + "_id": "Atlantic/Reykjavik", + "name": "Atlantic/Reykjavik" + }, + { + "_id": "Atlantic/South_Georgia", + "name": "Atlantic/South_Georgia" + }, + { + "_id": "Atlantic/St_Helena", + "name": "Atlantic/St_Helena" + }, + { + "_id": "Atlantic/Stanley", + "name": "Atlantic/Stanley" + }, + { + "_id": "Australia/Adelaide", + "name": "Australia/Adelaide" + }, + { + "_id": "Australia/Brisbane", + "name": "Australia/Brisbane" + }, + { + "_id": "Australia/Broken_Hill", + "name": "Australia/Broken_Hill" + }, + { + "_id": "Australia/Currie", + "name": "Australia/Currie" + }, + { + "_id": "Australia/Darwin", + "name": "Australia/Darwin" + }, + { + "_id": "Australia/Eucla", + "name": "Australia/Eucla" + }, + { + "_id": "Australia/Hobart", + "name": "Australia/Hobart" + }, + { + "_id": "Australia/Lindeman", + "name": "Australia/Lindeman" + }, + { + "_id": "Australia/Lord_Howe", + "name": "Australia/Lord_Howe" + }, + { + "_id": "Australia/Melbourne", + "name": "Australia/Melbourne" + }, + { + "_id": "Australia/Perth", + "name": "Australia/Perth" + }, + { + "_id": "Australia/Sydney", + "name": "Australia/Sydney" + }, + { + "_id": "Europe/Amsterdam", + "name": "Europe/Amsterdam" + }, + { + "_id": "Europe/Andorra", + "name": "Europe/Andorra" + }, + { + "_id": "Europe/Astrakhan", + "name": "Europe/Astrakhan" + }, + { + "_id": "Europe/Athens", + "name": "Europe/Athens" + }, + { + "_id": "Europe/Belgrade", + "name": "Europe/Belgrade" + }, + { + "_id": "Europe/Berlin", + "name": "Europe/Berlin" + }, + { + "_id": "Europe/Bratislava", + "name": "Europe/Bratislava" + }, + { + "_id": "Europe/Brussels", + "name": "Europe/Brussels" + }, + { + "_id": "Europe/Bucharest", + "name": "Europe/Bucharest" + }, + { + "_id": "Europe/Budapest", + "name": "Europe/Budapest" + }, + { + "_id": "Europe/Chisinau", + "name": "Europe/Chisinau" + }, + { + "_id": "Europe/Copenhagen", + "name": "Europe/Copenhagen" + }, + { + "_id": "Europe/Dublin", + "name": "Europe/Dublin" + }, + { + "_id": "Europe/Gibraltar", + "name": "Europe/Gibraltar" + }, + { + "_id": "Europe/Guernsey", + "name": "Europe/Guernsey" + }, + { + "_id": "Europe/Helsinki", + "name": "Europe/Helsinki" + }, + { + "_id": "Europe/Isle_of_Man", + "name": "Europe/Isle_of_Man" + }, + { + "_id": "Europe/Istanbul", + "name": "Europe/Istanbul" + }, + { + "_id": "Europe/Jersey", + "name": "Europe/Jersey" + }, + { + "_id": "Europe/Kaliningrad", + "name": "Europe/Kaliningrad" + }, + { + "_id": "Europe/Kirov", + "name": "Europe/Kirov" + }, + { + "_id": "Europe/Kyiv", + "name": "Europe/Kyiv" + }, + { + "_id": "Europe/Lisbon", + "name": "Europe/Lisbon" + }, + { + "_id": "Europe/Ljubljana", + "name": "Europe/Ljubljana" + }, + { + "_id": "Europe/London", + "name": "Europe/London" + }, + { + "_id": "Europe/Luxembourg", + "name": "Europe/Luxembourg" + }, + { + "_id": "Europe/Madrid", + "name": "Europe/Madrid" + }, + { + "_id": "Europe/Malta", + "name": "Europe/Malta" + }, + { + "_id": "Europe/Mariehamn", + "name": "Europe/Mariehamn" + }, + { + "_id": "Europe/Minsk", + "name": "Europe/Minsk" + }, + { + "_id": "Europe/Monaco", + "name": "Europe/Monaco" + }, + { + "_id": "Europe/Moscow", + "name": "Europe/Moscow" + }, + { + "_id": "Europe/Oslo", + "name": "Europe/Oslo" + }, + { + "_id": "Europe/Paris", + "name": "Europe/Paris" + }, + { + "_id": "Europe/Podgorica", + "name": "Europe/Podgorica" + }, + { + "_id": "Europe/Prague", + "name": "Europe/Prague" + }, + { + "_id": "Europe/Riga", + "name": "Europe/Riga" + }, + { + "_id": "Europe/Rome", + "name": "Europe/Rome" + }, + { + "_id": "Europe/Samara", + "name": "Europe/Samara" + }, + { + "_id": "Europe/San_Marino", + "name": "Europe/San_Marino" + }, + { + "_id": "Europe/Sarajevo", + "name": "Europe/Sarajevo" + }, + { + "_id": "Europe/Saratov", + "name": "Europe/Saratov" + }, + { + "_id": "Europe/Simferopol", + "name": "Europe/Simferopol" + }, + { + "_id": "Europe/Skopje", + "name": "Europe/Skopje" + }, + { + "_id": "Europe/Sofia", + "name": "Europe/Sofia" + }, + { + "_id": "Europe/Stockholm", + "name": "Europe/Stockholm" + }, + { + "_id": "Europe/Tallinn", + "name": "Europe/Tallinn" + }, + { + "_id": "Europe/Tirane", + "name": "Europe/Tirane" + }, + { + "_id": "Europe/Ulyanovsk", + "name": "Europe/Ulyanovsk" + }, + { + "_id": "Europe/Uzhgorod", + "name": "Europe/Uzhgorod" + }, + { + "_id": "Europe/Vaduz", + "name": "Europe/Vaduz" + }, + { + "_id": "Europe/Vatican", + "name": "Europe/Vatican" + }, + { + "_id": "Europe/Vienna", + "name": "Europe/Vienna" + }, + { + "_id": "Europe/Vilnius", + "name": "Europe/Vilnius" + }, + { + "_id": "Europe/Volgograd", + "name": "Europe/Volgograd" + }, + { + "_id": "Europe/Warsaw", + "name": "Europe/Warsaw" + }, + { + "_id": "Europe/Zagreb", + "name": "Europe/Zagreb" + }, + { + "_id": "Europe/Zaporizhzhia", + "name": "Europe/Zaporizhzhia" + }, + { + "_id": "Europe/Zurich", + "name": "Europe/Zurich" + }, + { + "_id": "Indian/Antananarivo", + "name": "Indian/Antananarivo" + }, + { + "_id": "Indian/Chagos", + "name": "Indian/Chagos" + }, + { + "_id": "Indian/Christmas", + "name": "Indian/Christmas" + }, + { + "_id": "Indian/Cocos", + "name": "Indian/Cocos" + }, + { + "_id": "Indian/Comoro", + "name": "Indian/Comoro" + }, + { + "_id": "Indian/Kerguelen", + "name": "Indian/Kerguelen" + }, + { + "_id": "Indian/Mahe", + "name": "Indian/Mahe" + }, + { + "_id": "Indian/Maldives", + "name": "Indian/Maldives" + }, + { + "_id": "Indian/Mauritius", + "name": "Indian/Mauritius" + }, + { + "_id": "Indian/Mayotte", + "name": "Indian/Mayotte" + }, + { + "_id": "Indian/Reunion", + "name": "Indian/Reunion" + }, + { + "_id": "Pacific/Apia", + "name": "Pacific/Apia" + }, + { + "_id": "Pacific/Auckland", + "name": "Pacific/Auckland" + }, + { + "_id": "Pacific/Bougainville", + "name": "Pacific/Bougainville" + }, + { + "_id": "Pacific/Chatham", + "name": "Pacific/Chatham" + }, + { + "_id": "Pacific/Chuuk", + "name": "Pacific/Chuuk" + }, + { + "_id": "Pacific/Easter", + "name": "Pacific/Easter" + }, + { + "_id": "Pacific/Efate", + "name": "Pacific/Efate" + }, + { + "_id": "Pacific/Enderbury", + "name": "Pacific/Enderbury" + }, + { + "_id": "Pacific/Fakaofo", + "name": "Pacific/Fakaofo" + }, + { + "_id": "Pacific/Fiji", + "name": "Pacific/Fiji" + }, + { + "_id": "Pacific/Funafuti", + "name": "Pacific/Funafuti" + }, + { + "_id": "Pacific/Galapagos", + "name": "Pacific/Galapagos" + }, + { + "_id": "Pacific/Gambier", + "name": "Pacific/Gambier" + }, + { + "_id": "Pacific/Guadalcanal", + "name": "Pacific/Guadalcanal" + }, + { + "_id": "Pacific/Guam", + "name": "Pacific/Guam" + }, + { + "_id": "Pacific/Honolulu", + "name": "Pacific/Honolulu" + }, + { + "_id": "Pacific/Kiritimati", + "name": "Pacific/Kiritimati" + }, + { + "_id": "Pacific/Kosrae", + "name": "Pacific/Kosrae" + }, + { + "_id": "Pacific/Kwajalein", + "name": "Pacific/Kwajalein" + }, + { + "_id": "Pacific/Majuro", + "name": "Pacific/Majuro" + }, + { + "_id": "Pacific/Marquesas", + "name": "Pacific/Marquesas" + }, + { + "_id": "Pacific/Midway", + "name": "Pacific/Midway" + }, + { + "_id": "Pacific/Nauru", + "name": "Pacific/Nauru" + }, + { + "_id": "Pacific/Niue", + "name": "Pacific/Niue" + }, + { + "_id": "Pacific/Norfolk", + "name": "Pacific/Norfolk" + }, + { + "_id": "Pacific/Noumea", + "name": "Pacific/Noumea" + }, + { + "_id": "Pacific/Pago_Pago", + "name": "Pacific/Pago_Pago" + }, + { + "_id": "Pacific/Palau", + "name": "Pacific/Palau" + }, + { + "_id": "Pacific/Pitcairn", + "name": "Pacific/Pitcairn" + }, + { + "_id": "Pacific/Pohnpei", + "name": "Pacific/Pohnpei" + }, + { + "_id": "Pacific/Port_Moresby", + "name": "Pacific/Port_Moresby" + }, + { + "_id": "Pacific/Rarotonga", + "name": "Pacific/Rarotonga" + }, + { + "_id": "Pacific/Saipan", + "name": "Pacific/Saipan" + }, + { + "_id": "Pacific/Tahiti", + "name": "Pacific/Tahiti" + }, + { + "_id": "Pacific/Tarawa", + "name": "Pacific/Tarawa" + }, + { + "_id": "Pacific/Tongatapu", + "name": "Pacific/Tongatapu" + }, + { + "_id": "Pacific/Wake", + "name": "Pacific/Wake" + }, + { + "_id": "Pacific/Wallis", + "name": "Pacific/Wallis" + } +] From 30cb62a93b7efb10e3aa02413984ec85f7ff21e0 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 11:37:09 +0800 Subject: [PATCH 15/82] Use timezones for incidents table --- .../src/Pages/Incidents/IncidentTable/index.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx index d10c79c68..2f79c5983 100644 --- a/Client/src/Pages/Incidents/IncidentTable/index.jsx +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -21,7 +21,15 @@ import { networkService } from "../../../main"; import { StatusLabel } from "../../../Components/Label"; import { logger } from "../../../Utils/Logger"; import { useTheme } from "@emotion/react"; +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; + const IncidentTable = ({ monitors, selectedMonitor, filter }) => { + dayjs.extend(utc); + dayjs.extend(timezone); + const uiTimezone = useSelector((state) => state.ui.timezone); + const theme = useTheme(); const { authToken, user } = useSelector((state) => state.auth); const [checks, setChecks] = useState([]); @@ -151,6 +159,9 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { {checks.map((check) => { const status = check.status === true ? "up" : "down"; + const formattedDate = dayjs(check.createdAt) + .tz(uiTimezone) + .format("YYYY-MM-DD HH:mm:ss"); return ( @@ -162,9 +173,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { customStyles={{ textTransform: "capitalize" }} /> - - {new Date(check.createdAt).toLocaleString()} - + {formattedDate} {check.statusCode ? check.statusCode : "N/A"} From e8bb31b007e9eaa06b2905ecba0c7e9153126022 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 11:38:45 +0800 Subject: [PATCH 16/82] Implement timezone in incident table in details page --- .../Details/PaginationTable/index.jsx | 12 ++++++--- Client/src/Pages/Settings/index.jsx | 26 ++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx b/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx index d7b91d09b..40b9e93e8 100644 --- a/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx +++ b/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx @@ -18,10 +18,13 @@ import { StatusLabel } from "../../../../Components/Label"; import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded"; import { logger } from "../../../../Utils/Logger"; -import { useTheme } from "@emotion/react"; +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; +dayjs.extend(utc); +dayjs.extend(timezone); const PaginationTable = ({ monitorId, dateRange }) => { - const theme = useTheme(); const { authToken } = useSelector((state) => state.auth); const [checks, setChecks] = useState([]); const [checksCount, setChecksCount] = useState(0); @@ -29,6 +32,7 @@ const PaginationTable = ({ monitorId, dateRange }) => { page: 0, rowsPerPage: 5, }); + const uiTimezone = useSelector((state) => state.ui.timezone); useEffect(() => { setPaginationController((prevPaginationController) => ({ @@ -119,7 +123,9 @@ const PaginationTable = ({ monitorId, dateRange }) => { /> - {new Date(check.createdAt).toLocaleString()} + {dayjs(check.createdAt) + .tz(uiTimezone) + .format("ddd, MMMM D, YYYY, HH:mm A")} {check.statusCode ? check.statusCode : "N/A"} diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index cd00f440f..a9f11f072 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -14,14 +14,18 @@ import { } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; import PropTypes from "prop-types"; import LoadingButton from "@mui/lab/LoadingButton"; +import { setTimezone } from "../../Features/UI/uiSlice"; +import timezones from "../../Utils/timezones.json"; + const Settings = ({ isAdmin }) => { const theme = useTheme(); const { user, authToken } = useSelector((state) => state.auth); const { isLoading } = useSelector((state) => state.uptimeMonitors); + const { timezone } = useSelector((state) => state.ui); const dispatch = useDispatch(); - // TODO Handle saving + const handleSave = async () => {}; const handleClearStats = async () => { try { @@ -115,25 +119,16 @@ const Settings = ({ isAdmin }) => { Display timezone- The timezone of the dashboard you publicly display. - - Server timezone- The - timezone of your server. - logger.warn("disabled")} - items={[{ _id: "est", name: "America / Toronto" }]} + value={timezone} + onChange={(e) => { + dispatch(setTimezone({ timezone: e.target.value })); + }} + items={timezones} /> @@ -232,6 +227,7 @@ const Settings = ({ isAdmin }) => { variant="contained" color="primary" sx={{ px: theme.spacing(12), mt: theme.spacing(20) }} + onClick={handleSave} > Save From 2bdf01abd6c5f7f1c5ae9d3faed0fe083a4ad7b5 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 12:17:31 +0800 Subject: [PATCH 17/82] refactor formating to utils file --- .../Charts/MonitorDetailsAreaChart/index.jsx | 26 +++----- .../Pages/Incidents/IncidentTable/index.jsx | 14 ++--- .../Pages/Monitors/Details/Charts/index.jsx | 61 +++++++++++++++---- .../Details/PaginationTable/index.jsx | 14 ++--- Client/src/Pages/Monitors/Details/index.jsx | 33 +++++----- Client/src/Utils/timeUtils.js | 11 ++++ 6 files changed, 95 insertions(+), 64 deletions(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index fd28b6e7e..6742f9d90 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -11,10 +11,13 @@ import { Box, Stack, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useMemo } from "react"; import "./index.css"; +import { useSelector } from "react-redux"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; const CustomToolTip = ({ active, payload, label }) => { - const theme = useTheme(); + const uiTimezone = useSelector((state) => state.ui.timezone); + const theme = useTheme(); if (active && payload && payload.length) { return ( { fontWeight: 500, }} > - {new Date(label).toLocaleDateString("en-US", { - weekday: "short", // Mon - month: "long", // July - day: "numeric", // 17 - }) + - ", " + - new Date(label).toLocaleTimeString("en-US", { - hour: "numeric", // 12 - minute: "2-digit", // 15 - hour12: true, // AM/PM format - })} + {formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)} { }; const MonitorDetailsAreaChart = ({ checks }) => { + const uiTimezone = useSelector((state) => state.ui.timezone); + const formatDate = (timestamp) => { - const date = new Date(timestamp); - return date.toLocaleTimeString("en-US", { - hour: "numeric", - minute: "2-digit", - hour12: true, - }); + return formatDateWithTz(timestamp, "HH:mm:ss", uiTimezone); }; const memoizedChecks = useMemo(() => checks, [checks[0]]); diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx index 2f79c5983..b80fdee67 100644 --- a/Client/src/Pages/Incidents/IncidentTable/index.jsx +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -21,13 +21,9 @@ import { networkService } from "../../../main"; import { StatusLabel } from "../../../Components/Label"; import { logger } from "../../../Utils/Logger"; import { useTheme } from "@emotion/react"; -import dayjs from "dayjs"; -import utc from "dayjs/plugin/utc"; -import timezone from "dayjs/plugin/timezone"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; const IncidentTable = ({ monitors, selectedMonitor, filter }) => { - dayjs.extend(utc); - dayjs.extend(timezone); const uiTimezone = useSelector((state) => state.ui.timezone); const theme = useTheme(); @@ -159,9 +155,11 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { {checks.map((check) => { const status = check.status === true ? "up" : "down"; - const formattedDate = dayjs(check.createdAt) - .tz(uiTimezone) - .format("YYYY-MM-DD HH:mm:ss"); + const formattedDate = formatDateWithTz( + check.createdAt, + "YYYY-MM-DD HH:mm:ss A", + uiTimezone + ); return ( diff --git a/Client/src/Pages/Monitors/Details/Charts/index.jsx b/Client/src/Pages/Monitors/Details/Charts/index.jsx index cb0afb55b..b70712340 100644 --- a/Client/src/Pages/Monitors/Details/Charts/index.jsx +++ b/Client/src/Pages/Monitors/Details/Charts/index.jsx @@ -1,4 +1,5 @@ import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; import { BarChart, Bar, @@ -8,8 +9,9 @@ import { RadialBarChart, RadialBar, } from "recharts"; -import { formatDate } from "../../../../Utils/timeUtils"; import { memo, useMemo, useState } from "react"; +import { useSelector } from "react-redux"; +import { formatDateWithTz } from "../../../../Utils/timeUtils"; const CustomLabels = ({ x, @@ -19,27 +21,35 @@ const CustomLabels = ({ lastDataPoint, type, }) => { - let options = { - month: "short", - year: undefined, - hour: undefined, - minute: undefined, - }; - if (type === "day") delete options.hour; + const uiTimezone = useSelector((state) => state.ui.timezone); + const dateFormat = type === "day" ? "MMM D, h:mm A" : "MMM D"; return ( <> - {formatDate(new Date(firstDataPoint.time), options)} + {formatDateWithTz( + new Date(firstDataPoint.time), + dateFormat, + uiTimezone + )} - {formatDate(new Date(lastDataPoint.time), options)} + {formatDateWithTz(new Date(lastDataPoint.time), dateFormat, uiTimezone)} ); }; -export const UpBarChart = memo(({ data, type, onBarHover }) => { +CustomLabels.propTypes = { + x: PropTypes.number.isRequired, + width: PropTypes.number.isRequired, + height: PropTypes.number.isRequired, + firstDataPoint: PropTypes.object.isRequired, + lastDataPoint: PropTypes.object.isRequired, + type: PropTypes.string.isRequired, +}; + +const UpBarChart = memo(({ data, type, onBarHover }) => { const theme = useTheme(); const [chartHovered, setChartHovered] = useState(false); @@ -122,7 +132,18 @@ export const UpBarChart = memo(({ data, type, onBarHover }) => { ); }); -export const DownBarChart = memo(({ data, type, onBarHover }) => { +// Add display name for the component +UpBarChart.displayName = "UpBarChart"; + +// Validate props using PropTypes +UpBarChart.propTypes = { + data: PropTypes.arrayOf(PropTypes.object), + type: PropTypes.string, + onBarHover: PropTypes.func, +}; +export { UpBarChart }; + +const DownBarChart = memo(({ data, type, onBarHover }) => { const theme = useTheme(); const [chartHovered, setChartHovered] = useState(false); @@ -194,7 +215,15 @@ export const DownBarChart = memo(({ data, type, onBarHover }) => { ); }); -export const ResponseGaugeChart = ({ data }) => { +DownBarChart.displayName = "DownBarChart"; +DownBarChart.propTypes = { + data: PropTypes.arrayOf(PropTypes.object), + type: PropTypes.string, + onBarHover: PropTypes.func, +}; +export { DownBarChart }; + +const ResponseGaugeChart = ({ data }) => { const theme = useTheme(); let max = 1000; // max ms @@ -281,3 +310,9 @@ export const ResponseGaugeChart = ({ data }) => { ); }; + +ResponseGaugeChart.propTypes = { + data: PropTypes.arrayOf(PropTypes.object).isRequired, +}; + +export { ResponseGaugeChart }; diff --git a/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx b/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx index 40b9e93e8..b438f104b 100644 --- a/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx +++ b/Client/src/Pages/Monitors/Details/PaginationTable/index.jsx @@ -18,11 +18,7 @@ import { StatusLabel } from "../../../../Components/Label"; import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded"; import { logger } from "../../../../Utils/Logger"; -import dayjs from "dayjs"; -import utc from "dayjs/plugin/utc"; -import timezone from "dayjs/plugin/timezone"; -dayjs.extend(utc); -dayjs.extend(timezone); +import { formatDateWithTz } from "../../../../Utils/timeUtils"; const PaginationTable = ({ monitorId, dateRange }) => { const { authToken } = useSelector((state) => state.auth); @@ -123,9 +119,11 @@ const PaginationTable = ({ monitorId, dateRange }) => { /> - {dayjs(check.createdAt) - .tz(uiTimezone) - .format("ddd, MMMM D, YYYY, HH:mm A")} + {formatDateWithTz( + check.createdAt, + "ddd, MMMM D, YYYY, HH:mm A", + uiTimezone + )} {check.statusCode ? check.statusCode : "N/A"} diff --git a/Client/src/Pages/Monitors/Details/index.jsx b/Client/src/Pages/Monitors/Details/index.jsx index 41e529eb9..eb18e36fc 100644 --- a/Client/src/Pages/Monitors/Details/index.jsx +++ b/Client/src/Pages/Monitors/Details/index.jsx @@ -14,7 +14,6 @@ import { useNavigate, useParams } from "react-router-dom"; import { networkService } from "../../../main"; import { logger } from "../../../Utils/Logger"; import { - formatDate, formatDurationRounded, formatDurationSplit, } from "../../../Utils/timeUtils"; @@ -35,6 +34,8 @@ import { DownBarChart, ResponseGaugeChart, UpBarChart } from "./Charts"; import SkeletonLayout from "./skeleton"; import "./index.css"; import useUtils from "../utils"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; + /** * Details page component displaying monitor details and related information. * @component @@ -57,6 +58,9 @@ const DetailsPage = ({ isAdmin }) => { setAnchorEl(null); }; + const dateFormat = dateRange === "day" ? "MMM D, h A" : "MMM D"; + const uiTimezone = useSelector((state) => state.ui.timezone); + const fetchMonitor = useCallback(async () => { try { const res = await networkService.getStatsByMonitorId( @@ -95,10 +99,7 @@ const DetailsPage = ({ isAdmin }) => { const date = new Date(year, month - 1, day); setCertificateExpiry( - formatDate(date, { - hour: undefined, - minute: undefined, - }) ?? "N/A" + formatDateWithTz(date, dateFormat, uiTimezone) ?? "N/A" ); } } catch (error) { @@ -367,12 +368,11 @@ const DetailsPage = ({ isAdmin }) => { fontSize={11} color={theme.palette.text.tertiary} > - {formatDate(new Date(hoveredUptimeData.time), { - month: "short", - year: undefined, - minute: undefined, - hour: dateRange === "day" ? "numeric" : undefined, - })} + {formatDateWithTz( + hoveredUptimeData.time, + dateFormat, + uiTimezone + )} )} @@ -417,12 +417,11 @@ const DetailsPage = ({ isAdmin }) => { fontSize={11} color={theme.palette.text.tertiary} > - {formatDate(new Date(hoveredIncidentsData.time), { - month: "short", - year: undefined, - minute: undefined, - hour: dateRange === "day" ? "numeric" : undefined, - })} + {formatDateWithTz( + hoveredIncidentsData.time, + dateFormat, + uiTimezone + )} )} diff --git a/Client/src/Utils/timeUtils.js b/Client/src/Utils/timeUtils.js index f9f916d04..da2f7f9bb 100644 --- a/Client/src/Utils/timeUtils.js +++ b/Client/src/Utils/timeUtils.js @@ -1,3 +1,9 @@ +import dayjs from "dayjs"; +import utc from "dayjs/plugin/utc"; +import timezone from "dayjs/plugin/timezone"; +dayjs.extend(utc); +dayjs.extend(timezone); + export const formatDuration = (ms) => { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); @@ -76,3 +82,8 @@ export const formatDate = (date, customOptions) => { .toLocaleString("en-US", options) .replace(/\b(AM|PM)\b/g, (match) => match.toLowerCase()); }; + +export const formatDateWithTz = (timestamp, format, timezone) => { + const formattedDate = dayjs(timestamp, timezone).tz(timezone).format(format); + return formattedDate; +}; From 413494a7fb069a262271921d087f26d1978149b7 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 12:44:29 +0800 Subject: [PATCH 18/82] Remove last checked from pagesspeed car --- Client/src/Components/Charts/BarChart/index.jsx | 10 ++++++++-- Client/src/Pages/PageSpeed/card.jsx | 11 ----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Client/src/Components/Charts/BarChart/index.jsx b/Client/src/Components/Charts/BarChart/index.jsx index 54a9524af..e2d8c7b45 100644 --- a/Client/src/Components/Charts/BarChart/index.jsx +++ b/Client/src/Components/Charts/BarChart/index.jsx @@ -1,12 +1,14 @@ import { useTheme } from "@emotion/react"; import { Box, Stack, Tooltip, Typography } from "@mui/material"; -import { formatDate } from "../../../Utils/timeUtils"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; import { useEffect, useState } from "react"; import "./index.css"; +import { useSelector } from "react-redux"; const BarChart = ({ checks = [] }) => { const theme = useTheme(); const [animate, setAnimate] = useState(false); + const uiTimezone = useSelector((state) => state.ui.timezone); useEffect(() => { setAnimate(true); @@ -51,7 +53,11 @@ const BarChart = ({ checks = [] }) => { title={ <> - {formatDate(new Date(check.createdAt), { year: undefined })} + {formatDateWithTz( + check.createdAt, + "ddd, MMMM D, YYYY, HH:mm A", + uiTimezone + )} { {monitor.url.replace(/^https?:\/\//, "")} - - - Last checked:{" "} - - {formatDate(getLastChecked(monitor.checks, false))}{" "} - - ({formatDurationRounded(getLastChecked(monitor.checks))} ago) - - From 15e067c9bfad3881f8c7bc21085acfac894ffafb Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 12 Sep 2024 12:49:18 +0800 Subject: [PATCH 19/82] Add ttl --- Server/controllers/checkController.js | 35 ++++++++++++++++++++------ Server/db/mongo/MongoDB.js | 2 ++ Server/db/mongo/modules/checkModule.js | 15 +++++++++++ Server/routes/checkRoute.js | 6 +++++ Server/utils/messages.js | 1 + 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/Server/controllers/checkController.js b/Server/controllers/checkController.js index 85bce0b54..ae0969e6e 100644 --- a/Server/controllers/checkController.js +++ b/Server/controllers/checkController.js @@ -31,7 +31,8 @@ const createCheck = async (req, res, next) => { .status(200) .json({ success: true, msg: successMessages.CHECK_CREATE, data: check }); } catch (error) { - error.service = SERVICE_NAME; + error.service === undefined ? (error.serivce = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "createCheck") : null; next(error); } }; @@ -58,7 +59,8 @@ const getChecks = async (req, res, next) => { data: { checksCount, checks }, }); } catch (error) { - error.service = SERVICE_NAME; + error.service === undefined ? (error.serivce = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "getChecks") : null; next(error); } }; @@ -83,7 +85,8 @@ const getTeamChecks = async (req, res, next) => { data: checkData, }); } catch (error) { - error.service = SERVICE_NAME; + error.service === undefined ? (error.serivce = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "getTeamChecks") : null; next(error); } }; @@ -108,7 +111,8 @@ const deleteChecks = async (req, res, next) => { data: { deletedCount }, }); } catch (error) { - error.service = SERVICE_NAME; + error.service === undefined ? (error.serivce = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "deleteChecks") : null; next(error); } }; @@ -117,8 +121,8 @@ const deleteChecksByTeamId = async (req, res, next) => { try { await deleteChecksByTeamIdParamValidation.validateAsync(req.params); } catch (error) { - error.service = SERVICE_NAME; - error.method = "deleteChecksByTeam"; + error.service === undefined ? (error.service = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "deleteChecksByTeam") : null; error.status = 422; next(error); } @@ -131,8 +135,22 @@ const deleteChecksByTeamId = async (req, res, next) => { data: { deletedCount }, }); } catch (error) { - error.service = SERVICE_NAME; - error.method = "deleteChecksByTeamId"; + error.service === undefined ? (error.service = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "deleteChecksByTeamId") : null; + next(error); + } +}; + +const updateChecksTTL = async (req, res, next) => { + try { + await req.db.updateChecksTTL(1); + return res.status(200).json({ + success: true, + msg: successMessages.CHECK_UPDATE_TTL, + }); + } catch (error) { + error.service === undefined ? (error.service = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "updateTTL") : null; next(error); } }; @@ -143,4 +161,5 @@ module.exports = { getTeamChecks, deleteChecks, deleteChecksByTeamId, + updateChecksTTL, }; diff --git a/Server/db/mongo/MongoDB.js b/Server/db/mongo/MongoDB.js index 73d55d509..ebc50f7da 100644 --- a/Server/db/mongo/MongoDB.js +++ b/Server/db/mongo/MongoDB.js @@ -97,6 +97,7 @@ const { getTeamChecks, deleteChecks, deleteChecksByTeamId, + updateChecksTTL, } = require("./modules/checkModule"); //**************************************** @@ -161,6 +162,7 @@ module.exports = { getTeamChecks, deleteChecks, deleteChecksByTeamId, + updateChecksTTL, createAlert, getAlertsByUserId, getAlertsByMonitorId, diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index da3ccb8f3..9f5c687df 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -239,6 +239,20 @@ const deleteChecksByTeamId = async (teamId) => { } }; +const updateChecksTTL = async (teamId) => { + try { + await Check.collection.dropIndex("expiry_1"); + await Check.collection.createIndex( + { expiry: 1 }, // Field to index + { expireAfterSeconds: 60 } // TTL in seconds, adjust as necessary + ); + } catch (error) { + error.service = SERVICE_NAME; + error.method = updateTTL; + throw error; + } +}; + module.exports = { createCheck, getChecksCount, @@ -246,4 +260,5 @@ module.exports = { getTeamChecks, deleteChecks, deleteChecksByTeamId, + updateChecksTTL, }; diff --git a/Server/routes/checkRoute.js b/Server/routes/checkRoute.js index 649a68ccf..a26e9eb94 100644 --- a/Server/routes/checkRoute.js +++ b/Server/routes/checkRoute.js @@ -26,4 +26,10 @@ router.delete( checkController.deleteChecksByTeamId ); +router.put( + "/ttl", + isAllowed(["admin", "superadmin"]), + checkController.updateChecksTTL +); + module.exports = router; diff --git a/Server/utils/messages.js b/Server/utils/messages.js index e67e4e7e7..04da91491 100644 --- a/Server/utils/messages.js +++ b/Server/utils/messages.js @@ -73,6 +73,7 @@ const successMessages = { CHECK_CREATE: "Check created successfully", CHECK_GET: "Got checks successfully", CHECK_DELETE: "Checks deleted successfully", + CHECK_UPDATE_TTL: "Checks TTL updated successfully", //Monitor Controller MONITOR_GET_ALL: "Got all monitors successfully", From 06e1c35e770d4b79b5b14155fa067106f92ad133 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Thu, 12 Sep 2024 20:08:04 -0400 Subject: [PATCH 20/82] Revamped performance section and removed redundant code --- Client/src/Pages/PageSpeed/Details/index.css | 16 -- Client/src/Pages/PageSpeed/Details/index.jsx | 256 ++++--------------- Client/src/assets/icons/spedometer-icon.svg | 3 + 3 files changed, 49 insertions(+), 226 deletions(-) create mode 100644 Client/src/assets/icons/spedometer-icon.svg diff --git a/Client/src/Pages/PageSpeed/Details/index.css b/Client/src/Pages/PageSpeed/Details/index.css index 18b2f1f3a..2bd9bda44 100644 --- a/Client/src/Pages/PageSpeed/Details/index.css +++ b/Client/src/Pages/PageSpeed/Details/index.css @@ -1,14 +1,3 @@ -.page-speed-details h6 { - font-size: var(--env-var-font-size-large); -} -.page-speed-details h4, -.page-speed-details p > span { - font-size: var(--env-var-font-size-medium); -} -.page-speed-details h1 + span, -.page-speed-details h4 > span { - font-size: var(--env-var-font-size-small-plus); -} .page-speed-details button.MuiButtonBase-root { height: 34px; } @@ -27,8 +16,3 @@ .page-speed-details .MuiPieArc-root { stroke: inherit; } - -.page-speed-details .metric { - min-width: 200px; - flex: 1; -} diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index f5ab4c987..042347c67 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -21,104 +21,16 @@ import { logger } from "../../../Utils/Logger"; import { networkService } from "../../../main"; import SkeletonLayout from "./skeleton"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; +import SpedometerIcon from "../../../assets/icons/spedometer-icon.svg?react"; import MetricsIcon from "../../../assets/icons/ruler-icon.svg?react"; import ScoreIcon from "../../../assets/icons/monitor-graph-line.svg?react"; import PerformanceIcon from "../../../assets/icons/performance-report.svg?react"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import PulseDot from "../../../Components/Animated/PulseDot"; import PagespeedDetailsAreaChart from "./Charts/AreaChart"; -import "./index.css"; import Checkbox from "../../../Components/Inputs/Checkbox"; import PieChart from "./Charts/PieChart"; - -/** - * Renders a centered label within a pie chart. - * - * @param {Object} props - * @param {string | number} props.value - The value to display in the label. - * @param {string} props.color - The color of the text. - * @returns {JSX.Element} - */ -const PieCenterLabel = ({ value, color, setExpand }) => { - const { width, height } = useDrawingArea(); - return ( - setExpand(true)} - > - - - {value} - - - ); -}; - -PieCenterLabel.propTypes = { - value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), - color: PropTypes.string, - setExpand: PropTypes.func, -}; - -/** - * A component that renders a label on a pie chart slice. - * The label is positioned relative to the center of the pie chart and is optionally highlighted. - * - * @param {Object} props - * @param {number} props.value - The value to display inside the pie slice. - * @param {number} props.startAngle - The starting angle of the pie slice in degrees. - * @param {number} props.endAngle - The ending angle of the pie slice in degrees. - * @param {string} props.color - The color of the label text when highlighted. - * @param {boolean} props.highlighted - Determines if the label should be highlighted or not. - * @returns {JSX.Element} - */ -const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => { - const { width, height } = useDrawingArea(); - - // Compute the midpoint angle in radians - const angle = (((startAngle + endAngle) / 2) * Math.PI) / 180; - const radius = height / 3.5; // length from center of the circle to where the text is positioned - - // Calculate x and y positions - const x = Math.sin(angle) * radius; - const y = -Math.cos(angle) * radius; - - return ( - - - +{value} - - - ); -}; - -PieValueLabel.propTypes = { - value: PropTypes.number, - startAngle: PropTypes.number, - endAngle: PropTypes.number, - color: PropTypes.string, - highlighted: PropTypes.bool, -}; +import "./index.css"; const PageSpeedDetails = () => { const theme = useTheme(); @@ -174,38 +86,6 @@ const PageSpeedDetails = () => { setMetrics((prev) => ({ ...prev, [id]: !prev[id] })); }; - /** - * Retrieves color properties based on the performance value. - * - * @param {number} value - The performance score used to determine the color properties. - * @returns {{stroke: string, text: string, shape: string}} The color properties for the given performance value. - */ - const getColors = (value) => { - if (value >= 90 && value <= 100) - return { - stroke: theme.palette.success.main, - text: theme.palette.success.text, - shape: "circle", - }; - else if (value >= 50 && value < 90) - return { - stroke: theme.palette.warning.main, - text: theme.palette.warning.text, - shape: "square", - }; - else if (value >= 0 && value < 50) - return { - stroke: theme.palette.error.text, - text: theme.palette.error.text, - shape: "circle", - }; - return { - stroke: theme.palette.unresolved.main, - text: theme.palette.unresolved.main, - shape: "", - }; - }; - return ( {loading ? ( @@ -412,8 +292,7 @@ const PageSpeedDetails = () => { @@ -433,11 +312,17 @@ const PageSpeedDetails = () => { Values are estimated and may vary.{" "} See calculator @@ -445,84 +330,30 @@ const PageSpeedDetails = () => { - - The{" "} - - performance score is calculated - {" "} - directly from these{" "} - - metrics - - . - + + + + + Performance Metrics + {Object.keys(audits).map((key) => { if (key === "_id") return; let audit = audits[key]; - let metricParams = getColors(audit.score * 100); - - let shape = ( - - ); - if (metricParams.shape === "square") - shape = ( - - ); - else if (metricParams.shape === "triangle") - shape = ( - - ); + let score = audit.score * 100; + let bg = + score >= 90 + ? theme.palette.success.main + : score >= 50 + ? theme.palette.warning.main + : score >= 0 + ? theme.palette.error.text + : theme.palette.unresolved.main; // Find the position where the number ends and the unit begins const match = audit.displayValue.match( @@ -532,44 +363,49 @@ const PageSpeedDetails = () => { let unit; if (match) { value = match[1]; - unit = match[2]; + match[2] === "s" ? (unit = "seconds") : (unit = match[2]); } else { value = audit.displayValue; } return ( - {shape} - + {audit.title} {value} {unit} + ); })} diff --git a/Client/src/assets/icons/spedometer-icon.svg b/Client/src/assets/icons/spedometer-icon.svg new file mode 100644 index 000000000..19b13f44e --- /dev/null +++ b/Client/src/assets/icons/spedometer-icon.svg @@ -0,0 +1,3 @@ + + + From 146a6463651a487c676764a7c4cc6c9e298b190f Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Thu, 12 Sep 2024 20:38:59 -0400 Subject: [PATCH 21/82] Enlarged pie chart --- .../PageSpeed/Details/Charts/PieChart.jsx | 29 ++++++++++++------- Client/src/Pages/PageSpeed/Details/index.jsx | 3 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx index be3b0cbb8..ff9fa3df2 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx @@ -20,12 +20,18 @@ const PieCenterLabel = ({ value, color, setExpand }) => { transform={`translate(${width / 2}, ${height / 2})`} onMouseEnter={() => setExpand(true)} > - + { // Compute the midpoint angle in radians const angle = (((startAngle + endAngle) / 2) * Math.PI) / 180; - const radius = height / 3.5; // length from center of the circle to where the text is positioned + const radius = height / 4; // length from center of the circle to where the text is positioned // Calculate x and y positions const x = Math.sin(angle) * radius; @@ -74,10 +80,11 @@ const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => { y={y} style={{ fill: highlighted ? color : "rgba(0,0,0,0)", - fontSize: "12px", + fontSize: 12, textAnchor: "middle", dominantBaseline: "central", userSelect: "none", + pointerEvents: "none", }} > +{value} @@ -181,8 +188,8 @@ const PieChart = ({ audits }) => { cornerRadius: 2, highlightScope: { faded: "global", highlighted: "series" }, faded: { - innerRadius: 63, - outerRadius: 70, + innerRadius: 73, + outerRadius: 80, additionalRadius: -20, arcLabelRadius: 5, }, @@ -197,7 +204,7 @@ const PieChart = ({ audits }) => { return props; }; - const pieSize = { width: 210, height: 200 }; + const pieSize = { width: 230, height: 230 }; const pieData = getPieData(audits); const colorMap = getColors(performance); @@ -215,7 +222,7 @@ const PieChart = ({ audits }) => { color: colorMap.bg, }, ], - outerRadius: 67, + outerRadius: 77, cx: pieSize.width / 2, }, ...pieData, @@ -260,7 +267,7 @@ const PieChart = ({ audits }) => { color: colorMap.bg, }, ], - outerRadius: 67, + outerRadius: 77, cx: pieSize.width / 2, }, { @@ -270,8 +277,8 @@ const PieChart = ({ audits }) => { color: colorMap.stroke, }, ], - innerRadius: 63, - outerRadius: 70, + innerRadius: 73, + outerRadius: 80, paddingAngle: 5, cornerRadius: 2, startAngle: 0, diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 042347c67..372fbb720 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -305,7 +305,8 @@ const PageSpeedDetails = () => { textAlign="center" minWidth="300px" flex={1} - p={theme.spacing(12)} + pt={theme.spacing(6)} + pb={theme.spacing(12)} > From 5c3f7162430ee89c6f6777d8e39fcf8106057a5b Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Thu, 12 Sep 2024 20:51:00 -0400 Subject: [PATCH 22/82] Increased pointer event range --- Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx index ff9fa3df2..70aa441fd 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx @@ -20,13 +20,7 @@ const PieCenterLabel = ({ value, color, setExpand }) => { transform={`translate(${width / 2}, ${height / 2})`} onMouseEnter={() => setExpand(true)} > - + Date: Fri, 13 Sep 2024 11:23:03 +0800 Subject: [PATCH 23/82] Enabled incident in actions menu, set selected monitor in Incidents page --- Client/src/App.jsx | 2 +- Client/src/Pages/Incidents/index.jsx | 4 ++++ Client/src/Pages/Monitors/Home/actionsMenu.jsx | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Client/src/App.jsx b/Client/src/App.jsx index 8fb4bf932..d6fca146f 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -71,7 +71,7 @@ function App() { element={} /> } /> diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 1fd91c10a..afaea43eb 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -1,6 +1,8 @@ import { useState, useEffect } from "react"; import { useSelector } from "react-redux"; import { ButtonGroup, Stack, Typography, Button } from "@mui/material"; +import { useParams } from "react-router-dom"; + import { networkService } from "../../main"; import { useTheme } from "@emotion/react"; import Select from "../../Components/Inputs/Select"; @@ -11,6 +13,7 @@ import SkeletonLayout from "./skeleton"; const Incidents = () => { const theme = useTheme(); const authState = useSelector((state) => state.auth); + const { monitorId } = useParams(); const [monitors, setMonitors] = useState({}); const [selectedMonitor, setSelectedMonitor] = useState("0"); @@ -40,6 +43,7 @@ const Incidents = () => { return acc; }, {}); setMonitors(monitorLookup); + monitorId !== undefined && setSelectedMonitor(monitorId); } setLoading(false); }; diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx index a271a8a9a..45c358a6c 100644 --- a/Client/src/Pages/Monitors/Home/actionsMenu.jsx +++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx @@ -125,7 +125,14 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => { Details {/* TODO - pass monitor id to Incidents page */} - Incidents + { + e.stopPropagation(); + navigate(`/incidents/${actions.id}`); + }} + > + Incidents + {isAdmin && ( { From 4caf9a268119dedde79ece111923b5f33c06fcba Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Fri, 13 Sep 2024 11:26:37 -0400 Subject: [PATCH 24/82] Light UI style updates --- Client/src/Pages/Incidents/IncidentTable/index.jsx | 1 + Client/src/Pages/Incidents/index.jsx | 2 +- Client/src/Pages/Monitors/Details/index.jsx | 5 +++++ Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 2 -- Client/src/Pages/PageSpeed/Details/index.jsx | 6 +++--- Client/src/assets/icons/certificate.svg | 4 ++-- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx index d10c79c68..61bd60f87 100644 --- a/Client/src/Pages/Incidents/IncidentTable/index.jsx +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -109,6 +109,7 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { {...item} /> )} + sx={{ mt: "auto" }} /> ); } diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 1fd91c10a..c86cac543 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -54,7 +54,7 @@ const Incidents = () => { }; return ( - + {loading ? ( ) : ( diff --git a/Client/src/Pages/Monitors/Details/index.jsx b/Client/src/Pages/Monitors/Details/index.jsx index 76e06b408..ebf72744a 100644 --- a/Client/src/Pages/Monitors/Details/index.jsx +++ b/Client/src/Pages/Monitors/Details/index.jsx @@ -217,6 +217,11 @@ const DetailsPage = ({ isAdmin }) => { onClick={openCertificate} sx={{ cursor: "pointer", + "& svg": { + width: 23, + height: 23, + top: "52%", + }, }} > diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index f055a57a1..47c080284 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -223,8 +223,6 @@ const MonitorTable = ({ isAdmin }) => { status: determineState(monitor), }; - console.log(params); - return ( { {Object.keys(audits).map((key) => { if (key === "_id") return; @@ -374,7 +374,7 @@ const PageSpeedDetails = () => { key={`${key}-box`} justifyContent="space-between" direction="row" - gap={theme.spacing(3)} + gap={theme.spacing(4)} p={theme.spacing(3)} border={1} borderColor={theme.palette.border.light} diff --git a/Client/src/assets/icons/certificate.svg b/Client/src/assets/icons/certificate.svg index a985bef9f..2bc6c7e74 100644 --- a/Client/src/assets/icons/certificate.svg +++ b/Client/src/assets/icons/certificate.svg @@ -1,3 +1,3 @@ - - + + \ No newline at end of file From b068776ce704f4a63cb827f2e19e006736bbf071 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Fri, 13 Sep 2024 11:40:03 -0400 Subject: [PATCH 25/82] Removed line causing an error --- Client/src/Pages/PageSpeed/Details/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 2118f4197..06f59698e 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -38,7 +38,6 @@ const PageSpeedDetails = () => { const [audits, setAudits] = useState({}); const { monitorId } = useParams(); const { authToken } = useSelector((state) => state.auth); - const { determineState, statusColor, pagespeedStatusMsg } = useUtils(); useEffect(() => { const fetchMonitor = async () => { From 1e480a10e090a8af3de1d39c52c2bea904b72c0b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 14 Sep 2024 10:57:46 +0800 Subject: [PATCH 26/82] Update proptypes, use date function --- .../Components/Charts/MonitorDetailsAreaChart/index.jsx | 9 +++------ Client/src/Pages/Monitors/Details/Charts/index.jsx | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 595836f65..ed3d724e8 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -85,9 +85,10 @@ const CustomToolTip = ({ active, payload, label }) => { const CustomTick = ({ x, y, payload, index }) => { const theme = useTheme(); + const uiTimezone = useSelector((state) => state.ui.timezone); + // Render nothing for the first tick if (index === 0) return null; - return ( { fontSize={11} fontWeight={400} > - {formatDate(new Date(payload.value), { - year: undefined, - month: undefined, - day: undefined, - })} + {formatDateWithTz(payload?.value, "HH:mm:ss", uiTimezone)} ); }; diff --git a/Client/src/Pages/Monitors/Details/Charts/index.jsx b/Client/src/Pages/Monitors/Details/Charts/index.jsx index b70712340..d38335800 100644 --- a/Client/src/Pages/Monitors/Details/Charts/index.jsx +++ b/Client/src/Pages/Monitors/Details/Charts/index.jsx @@ -42,8 +42,8 @@ const CustomLabels = ({ CustomLabels.propTypes = { x: PropTypes.number.isRequired, - width: PropTypes.number.isRequired, - height: PropTypes.number.isRequired, + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), firstDataPoint: PropTypes.object.isRequired, lastDataPoint: PropTypes.object.isRequired, type: PropTypes.string.isRequired, From d942e3144f3d492c04073d7e05af123531ea8717 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 14 Sep 2024 11:20:28 +0800 Subject: [PATCH 27/82] Add proptypes --- Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx index 9523a31d7..fea80f5c4 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -47,7 +47,7 @@ const config = { const CustomToolTip = ({ active, payload, label, config }) => { const theme = useTheme(); - + console.log(payload); if (active && payload && payload.length) { return ( Date: Sat, 14 Sep 2024 11:23:38 +0800 Subject: [PATCH 28/82] Add proptypes to monitor details area chart" --- .../Components/Charts/MonitorDetailsAreaChart/index.jsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index ed3d724e8..2ecb2f6a8 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -11,7 +11,6 @@ import { import { Box, Stack, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useMemo } from "react"; -import { formatDate } from "../../../Utils/timeUtils"; import "./index.css"; import { useSelector } from "react-redux"; import { formatDateWithTz } from "../../../Utils/timeUtils"; @@ -103,6 +102,13 @@ const CustomTick = ({ x, y, payload, index }) => { ); }; +CustomTick.propTypes = { + x: PropTypes.number, + y: PropTypes.number, + payload: PropTypes.object, + index: PropTypes.number, +}; + const MonitorDetailsAreaChart = ({ checks }) => { const theme = useTheme(); const memoizedChecks = useMemo(() => checks, [checks[0]]); From 4b0ac5822a1bafc1230f24d1373abd721b48c20c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 14 Sep 2024 11:29:14 +0800 Subject: [PATCH 29/82] Rename reserved keyword prop to data --- .../PageSpeed/Details/Charts/PieChart.jsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx index 70aa441fd..37556f178 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/PieChart.jsx @@ -87,6 +87,15 @@ const PieValueLabel = ({ value, startAngle, endAngle, color, highlighted }) => { ); }; +// Validate props using PropTypes +PieValueLabel.propTypes = { + value: PropTypes.number.isRequired, + startAngle: PropTypes.number.isRequired, + endAngle: PropTypes.number.isRequired, + color: PropTypes.string.isRequired, + highlighted: PropTypes.bool.isRequired, +}; + const PieChart = ({ audits }) => { const theme = useTheme(); @@ -148,7 +157,7 @@ const PieChart = ({ audits }) => { */ let performance = 0; const getPieData = (audits) => { - let props = []; + let data = []; let startAngle = 0; const padding = 3; // padding between arcs const max = 360 - padding * (Object.keys(audits).length - 1); // _id is a child of audits @@ -159,7 +168,7 @@ const PieChart = ({ audits }) => { let endAngle = startAngle + (weights[key] * max) / 100; let theme = getColors(audits[key].score * 100); - props.push({ + data.push({ id: key, data: [ { @@ -195,7 +204,7 @@ const PieChart = ({ audits }) => { } }); - return props; + return data; }; const pieSize = { width: 230, height: 230 }; @@ -296,4 +305,8 @@ const PieChart = ({ audits }) => { ); }; +PieChart.propTypes = { + audits: PropTypes.object, +}; + export default PieChart; From 9bbd5ce12a7c4261dbdbb7802f5086bdd031d60b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 14 Sep 2024 12:16:13 +0800 Subject: [PATCH 30/82] Add validation for updateTTL body --- Server/controllers/checkController.js | 19 +++++++++++++++++-- Server/db/mongo/modules/checkModule.js | 8 ++++---- Server/db/mongo/modules/monitorModule.js | 2 +- Server/middleware/handleErrors.js | 2 +- Server/validation/joi.js | 5 +++++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Server/controllers/checkController.js b/Server/controllers/checkController.js index ae0969e6e..49dfad1af 100644 --- a/Server/controllers/checkController.js +++ b/Server/controllers/checkController.js @@ -7,9 +7,10 @@ const { getTeamChecksQueryValidation, deleteChecksParamValidation, deleteChecksByTeamIdParamValidation, + updateChecksTTLBodyValidation, } = require("../validation/joi"); const { successMessages } = require("../utils/messages"); -const SERVICE_NAME = "check"; +const SERVICE_NAME = "checkController"; const createCheck = async (req, res, next) => { try { @@ -125,6 +126,7 @@ const deleteChecksByTeamId = async (req, res, next) => { error.method === undefined ? (error.method = "deleteChecksByTeam") : null; error.status = 422; next(error); + return; } try { @@ -143,7 +145,20 @@ const deleteChecksByTeamId = async (req, res, next) => { const updateChecksTTL = async (req, res, next) => { try { - await req.db.updateChecksTTL(1); + await updateChecksTTLBodyValidation.validateAsync(req.body); + } catch (error) { + error.status = 422; + error.service === undefined ? (error.service = SERVICE_NAME) : null; + error.method === undefined ? (error.method = "updateChecksTTL") : null; + error.message = + error.details?.[0]?.message || error.message || "Validation Error"; + next(error); + return; + } + + try { + const ttl = req.body.ttl; + await req.db.updateChecksTTL(1, ttl); return res.status(200).json({ success: true, msg: successMessages.CHECK_UPDATE_TTL, diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index 9f5c687df..d12f26c0b 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -239,16 +239,16 @@ const deleteChecksByTeamId = async (teamId) => { } }; -const updateChecksTTL = async (teamId) => { +const updateChecksTTL = async (teamId, ttl) => { try { await Check.collection.dropIndex("expiry_1"); await Check.collection.createIndex( - { expiry: 1 }, // Field to index - { expireAfterSeconds: 60 } // TTL in seconds, adjust as necessary + { expiry: 1 }, + { expireAfterSeconds: ttl } // TTL in seconds, adjust as necessary ); } catch (error) { error.service = SERVICE_NAME; - error.method = updateTTL; + error.method = "upddateChecksTTL"; throw error; } }; diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 5eaec7bf9..19f26defe 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -262,7 +262,7 @@ const getMonitorStatsById = async (req) => { return monitorStats; } catch (error) { - error.methodName = "getMonitorStatsById"; + error.method = "getMonitorStatsById"; throw error; } }; diff --git a/Server/middleware/handleErrors.js b/Server/middleware/handleErrors.js index db51c1af6..3f1ba56f4 100644 --- a/Server/middleware/handleErrors.js +++ b/Server/middleware/handleErrors.js @@ -7,7 +7,7 @@ const handleErrors = (error, req, res, next) => { const service = error.service || errorMessages.UNKNOWN_SERVICE; logger.error(error.message, { service: service, - methodName: error.methodName, + method: error.method, }); res.status(status).json({ success: false, msg: message }); }; diff --git a/Server/validation/joi.js b/Server/validation/joi.js index 918400c21..dfb0e6fe7 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -335,6 +335,10 @@ const deleteChecksByTeamIdParamValidation = joi.object({ teamId: joi.string().required(), }); +const updateChecksTTLBodyValidation = joi.object({ + ttl: joi.number().required(), +}); + //**************************************** // PageSpeedCheckValidation //**************************************** @@ -423,6 +427,7 @@ module.exports = { getTeamChecksQueryValidation, deleteChecksParamValidation, deleteChecksByTeamIdParamValidation, + updateChecksTTLBodyValidation, deleteUserParamValidation, getPageSpeedCheckParamValidation, createPageSpeedCheckParamValidation, From d8664d3ed7a63bee2ec58572c9e8e7326881e323 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Sat, 14 Sep 2024 12:36:20 -0400 Subject: [PATCH 31/82] Added basic default font variants --- .../Charts/MonitorDetailsAreaChart/index.jsx | 2 +- Client/src/Components/Inputs/Field/index.jsx | 3 +- Client/src/Pages/Monitors/Configure/index.css | 3 -- Client/src/Pages/Monitors/Configure/index.jsx | 16 ++----- .../Pages/Monitors/CreateMonitor/index.css | 4 -- .../Pages/Monitors/CreateMonitor/index.jsx | 26 +++++------ Client/src/Pages/Monitors/Details/index.jsx | 24 +++-------- .../Monitors/Home/MonitorTable/index.jsx | 7 +-- .../src/Pages/Monitors/Home/actionsMenu.jsx | 6 +-- Client/src/Pages/Monitors/Home/fallback.jsx | 6 ++- Client/src/Pages/Monitors/Home/index.css | 11 ----- Client/src/Pages/Monitors/Home/index.jsx | 6 +-- Client/src/Pages/Monitors/Home/skeleton.jsx | 10 +---- Client/src/Pages/NotFound/index.jsx | 10 ++--- .../src/Pages/PageSpeed/Configure/index.css | 14 +----- .../src/Pages/PageSpeed/Configure/index.jsx | 11 ++--- .../Pages/PageSpeed/CreatePageSpeed/index.css | 43 ------------------- .../Pages/PageSpeed/CreatePageSpeed/index.jsx | 11 ++--- .../PageSpeed/Details/Charts/AreaChart.jsx | 1 - Client/src/Pages/PageSpeed/Details/index.jsx | 34 ++++----------- Client/src/Pages/PageSpeed/card.jsx | 14 +++++- Client/src/Pages/PageSpeed/index.css | 11 ----- Client/src/Utils/Theme/darkTheme.js | 10 ++++- Client/src/Utils/Theme/lightTheme.js | 10 ++++- Client/src/Utils/greeting.jsx | 22 +++------- Client/src/index.css | 2 - 26 files changed, 90 insertions(+), 227 deletions(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 2ecb2f6a8..7074b7771 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -97,7 +97,7 @@ const CustomTick = ({ x, y, payload, index }) => { fontSize={11} fontWeight={400} > - {formatDateWithTz(payload?.value, "HH:mm:ss", uiTimezone)} + {formatDateWithTz(payload?.value, "h:mm a", uiTimezone)} ); }; diff --git a/Client/src/Components/Inputs/Field/index.jsx b/Client/src/Components/Inputs/Field/index.jsx index 62c50eeff..e7326ec41 100644 --- a/Client/src/Components/Inputs/Field/index.jsx +++ b/Client/src/Components/Inputs/Field/index.jsx @@ -121,8 +121,9 @@ const Field = forwardRef( sx: { color: theme.palette.text.secondary, "&:-webkit-autofill": { - WebkitBoxShadow: `0 0 0 100px ${theme.palette.background.fill} inset`, + WebkitBoxShadow: `0 0 0 100px ${theme.palette.other.autofill} inset`, WebkitTextFillColor: theme.palette.text.secondary, + borderRadius: "0 5px 5px 0", }, }, }} diff --git a/Client/src/Pages/Monitors/Configure/index.css b/Client/src/Pages/Monitors/Configure/index.css index 032833924..c59936d46 100644 --- a/Client/src/Pages/Monitors/Configure/index.css +++ b/Client/src/Pages/Monitors/Configure/index.css @@ -1,6 +1,3 @@ -.configure-monitor h1.MuiTypography-root + span.MuiTypography-root { - font-size: var(--env-var-font-size-small-plus); -} .configure-monitor button.MuiButtonBase-root { height: var(--env-var-height-2); } diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx index 34076dd89..cd55837a7 100644 --- a/Client/src/Pages/Monitors/Configure/index.jsx +++ b/Client/src/Pages/Monitors/Configure/index.jsx @@ -223,12 +223,7 @@ const Configure = () => { > - + {monitor.name} { /> - + {monitor.url?.replace(/^https?:\/\//, "") || "..."} { ]; return ( - + { gap={theme.spacing(12)} mt={theme.spacing(6)} > - - + + Create your{" "} - + monitor @@ -262,7 +256,7 @@ const CreateMonitor = () => { onChange={(event) => handleChange(event)} /> {monitor.type === "http" ? ( - + From 205e82f1b33db89cb51da7854270c6968a33e2be Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 15:03:36 -0400 Subject: [PATCH 55/82] Added docs --- Client/src/Pages/PageSpeed/card.jsx | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Client/src/Pages/PageSpeed/card.jsx b/Client/src/Pages/PageSpeed/card.jsx index 00b717ce4..6b87703f5 100644 --- a/Client/src/Pages/PageSpeed/card.jsx +++ b/Client/src/Pages/PageSpeed/card.jsx @@ -1,13 +1,18 @@ +import PropTypes from "prop-types"; import PageSpeedIcon from "../../assets/icons/page-speed.svg?react"; import { StatusLabel } from "../../Components/Label"; import { Box, Grid, Typography } from "@mui/material"; import { useNavigate } from "react-router"; import { useTheme } from "@emotion/react"; import { IconBox } from "./Details/styled"; -import useUtils from "../Monitors/utils"; -import PropTypes from "prop-types"; import { Area, AreaChart, CartesianGrid, ResponsiveContainer } from "recharts"; +import useUtils from "../Monitors/utils"; +/** + * Processes the raw data to include a score for each entry. + * @param {Array} data - The raw data array. + * @returns {Array} - The formatted data array with scores. + */ const processData = (data) => { if (data.length === 0) return []; let formattedData = []; @@ -30,6 +35,13 @@ const processData = (data) => { return formattedData; }; +/** + * Renders an area chart displaying page speed scores. + * @param {Object} props + * @param {Array} props.data - The raw data to be displayed in the chart. + * @param {string} props.status - The status of the page speed which determines the chart's color scheme. + * @returns {JSX.Element} - The rendered area chart. + */ const PagespeedAreaChart = ({ data, status }) => { const theme = useTheme(); const { pagespeedStyles } = useUtils(); @@ -92,6 +104,24 @@ const PagespeedAreaChart = ({ data, status }) => { ); }; +PagespeedAreaChart.propTypes = { + data: PropTypes.arrayOf( + PropTypes.shape({ + accessibility: PropTypes.number.isRequired, + bestPractices: PropTypes.number.isRequired, + performance: PropTypes.number.isRequired, + seo: PropTypes.number.isRequired, + }) + ).isRequired, + status: PropTypes.string.isRequired, +}; + +/** + * Renders a card displaying monitor details and an area chart. + * @param {Object} props + * @param {Object} props.monitor - The monitor data to be displayed in the card. + * @returns {JSX.Element} - The rendered card. + */ const Card = ({ monitor }) => { const { determineState, pagespeedStatusMsg } = useUtils(); const theme = useTheme(); From 78914c9566da660733ed0744221db45019bfea67 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 15:18:41 -0400 Subject: [PATCH 56/82] Added tooltip --- Client/src/Pages/PageSpeed/card.jsx | 93 ++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 7 deletions(-) diff --git a/Client/src/Pages/PageSpeed/card.jsx b/Client/src/Pages/PageSpeed/card.jsx index 6b87703f5..e45cc3b45 100644 --- a/Client/src/Pages/PageSpeed/card.jsx +++ b/Client/src/Pages/PageSpeed/card.jsx @@ -1,13 +1,92 @@ import PropTypes from "prop-types"; import PageSpeedIcon from "../../assets/icons/page-speed.svg?react"; import { StatusLabel } from "../../Components/Label"; -import { Box, Grid, Typography } from "@mui/material"; +import { Box, Grid, Stack, Typography } from "@mui/material"; import { useNavigate } from "react-router"; import { useTheme } from "@emotion/react"; import { IconBox } from "./Details/styled"; -import { Area, AreaChart, CartesianGrid, ResponsiveContainer } from "recharts"; +import { + Area, + AreaChart, + CartesianGrid, + ResponsiveContainer, + Tooltip, +} from "recharts"; +import { useSelector } from "react-redux"; +import { formatDateWithTz } from "../../Utils/timeUtils"; import useUtils from "../Monitors/utils"; +/** + * CustomToolTip displays a tooltip with formatted date and score information. + * @param {Object} props + * @param {Array} props.payload - Data to display in the tooltip + * @returns {JSX.Element} The rendered tooltip component + */ +const CustomToolTip = ({ payload }) => { + const theme = useTheme(); + const uiTimezone = useSelector((state) => state.ui.timezone); + + return ( + + + {formatDateWithTz( + payload[0]?.payload.createdAt, + "ddd, MMMM D, YYYY, h:mm A", + uiTimezone + )} + + + + + + {payload[0]?.name} + {" "} + {payload[0]?.payload.score} + + + ); +}; + +CustomToolTip.propTypes = { + payload: PropTypes.array, +}; + /** * Processes the raw data to include a score for each entry. * @param {Array} data - The raw data array. @@ -64,10 +143,10 @@ const PagespeedAreaChart = ({ data, status }) => { fill="transparent" vertical={false} /> - {/* } - /> */} + content={} + /> { strokeWidth={1.5} fill={`url(#pagespeed-chart-${status})`} activeDot={{ - stroke: pagespeedStyles[status].stroke, + stroke: pagespeedStyles[status].light, fill: pagespeedStyles[status].stroke, r: 4.5, }} @@ -118,7 +197,7 @@ PagespeedAreaChart.propTypes = { /** * Renders a card displaying monitor details and an area chart. - * @param {Object} props + * @param {Object} props * @param {Object} props.monitor - The monitor data to be displayed in the card. * @returns {JSX.Element} - The rendered card. */ From 5bab1514fcc5431f2bd1bd7bf10e50959849ae78 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 17:06:45 -0400 Subject: [PATCH 57/82] Added monitor interval check --- Client/src/Pages/PageSpeed/card.jsx | 53 ++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/Client/src/Pages/PageSpeed/card.jsx b/Client/src/Pages/PageSpeed/card.jsx index e45cc3b45..5c688a041 100644 --- a/Client/src/Pages/PageSpeed/card.jsx +++ b/Client/src/Pages/PageSpeed/card.jsx @@ -13,7 +13,11 @@ import { Tooltip, } from "recharts"; import { useSelector } from "react-redux"; -import { formatDateWithTz } from "../../Utils/timeUtils"; +import { + formatDateWithTz, + formatDurationRounded, + formatDurationSplit, +} from "../../Utils/timeUtils"; import useUtils from "../Monitors/utils"; /** @@ -128,7 +132,7 @@ const PagespeedAreaChart = ({ data, status }) => { const formattedData = processData(data); return ( - + { return ( navigate(`/pagespeed/${monitor._id}`)} border={1} @@ -230,7 +235,12 @@ const Card = ({ monitor }) => { - + {monitor.name} { /> {monitor.url} @@ -258,6 +268,41 @@ const Card = ({ monitor }) => { > + + + Checking every{" "} + {(() => { + const { time, format } = formatDurationSplit(monitor?.interval); + return ( + <> + + {time}{" "} + + {format} + + ); + })()} + + ); From 60ffc2f1d218b007b5bee0788b1bff00ddb10597 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 17:46:03 -0400 Subject: [PATCH 58/82] Fixed pulse dot not displaying accurate status color --- Client/src/Pages/PageSpeed/Details/index.jsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Details/index.jsx b/Client/src/Pages/PageSpeed/Details/index.jsx index 9774bb97c..48d8aa86a 100644 --- a/Client/src/Pages/PageSpeed/Details/index.jsx +++ b/Client/src/Pages/PageSpeed/Details/index.jsx @@ -29,11 +29,13 @@ import PulseDot from "../../../Components/Animated/PulseDot"; import PagespeedDetailsAreaChart from "./Charts/AreaChart"; import Checkbox from "../../../Components/Inputs/Checkbox"; import PieChart from "./Charts/PieChart"; +import useUtils from "../../Monitors/utils"; import "./index.css"; const PageSpeedDetails = () => { const theme = useTheme(); const navigate = useNavigate(); + const { statusColor, pagespeedStatusMsg, determineState } = useUtils(); const [monitor, setMonitor] = useState({}); const [audits, setAudits] = useState({}); const { monitorId } = useParams(); @@ -109,11 +111,7 @@ const PageSpeedDetails = () => { gap={theme.spacing(2)} > { }} > - + From 6842c40fdc22b6681204290565b2cfabf091fd02 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 18:49:51 -0400 Subject: [PATCH 59/82] Fixed pulse dot styling --- .../src/Pages/PageSpeed/Configure/index.css | 24 ------- .../src/Pages/PageSpeed/Configure/index.jsx | 72 +++++++++++++++---- 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Configure/index.css b/Client/src/Pages/PageSpeed/Configure/index.css index 14c2df3de..c9790c3d8 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.css +++ b/Client/src/Pages/PageSpeed/Configure/index.css @@ -1,29 +1,6 @@ -.configure-pagespeed span.MuiTypography-root { - font-size: var(--env-var-font-size-small-plus); -} -.configure-pagespeed h3.MuiTypography-root { - font-weight: 500; -} -.configure-pagespeed .MuiBox-root > .field + p.MuiTypography-root { - font-size: var(--env-var-font-size-small-plus); -} -.configure-pagespeed .MuiBox-root > .field + p.MuiTypography-root, -.configure-pagespeed h3.MuiTypography-root > span.MuiTypography-root { - opacity: 0.6; -} .configure-pagespeed .checkbox-wrapper { margin-bottom: 1px; } - -/* to be removed */ -.configure-pagespeed .section-disabled { - opacity: 0.4; - padding: 10px; - border-radius: 8px; - user-select: none; - pointer-events: none; -} - .configure-pagespeed button { height: var(--env-var-height-2); } @@ -31,7 +8,6 @@ .configure-pagespeed h3.MuiTypography-root { flex: 0.7; } - .configure-pagespeed .field, .configure-pagespeed .section-disabled, .configure-pagespeed .select-wrapper { diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index 80786bc89..b056404eb 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; -import { Box, Button, Modal, Stack, Typography } from "@mui/material"; +import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material"; import { useDispatch, useSelector } from "react-redux"; import { useNavigate, useParams } from "react-router"; import { @@ -35,7 +35,7 @@ const PageSpeedConfigure = () => { const { monitorId } = useParams(); const [monitor, setMonitor] = useState({}); const [errors, setErrors] = useState({}); - const { determineState, statusColor } = useUtils(); + const { statusColor, pagespeedStatusMsg, determineState } = useUtils(); const frequencies = [ { _id: 3, name: "3 minutes" }, @@ -128,7 +128,7 @@ const PageSpeedConfigure = () => { }; return ( - + {Object.keys(monitor).length === 0 ? ( ) : ( @@ -146,22 +146,65 @@ const PageSpeedConfigure = () => { spellCheck="false" onSubmit={handleSave} flex={1} - gap={theme.spacing(12)} + gap={theme.spacing(10)} > - - - {monitor?.url} + + {monitor.name} - - Your pagespeed monitor is {determineState(monitor)}. - + + + + + + + {monitor.url?.replace(/^https?:\/\//, "") || "..."} + + + Editting... + + { id="modal-delete-pagespeed-monitor" component="h2" variant="h2" + fontWeight={500} > Do you really want to delete this monitor? From 1e659f6c64b476f9d61c0b99cf3705fa2144fa6d Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Mon, 16 Sep 2024 19:06:42 -0400 Subject: [PATCH 60/82] Fixed pagespeed config box styling --- .../src/Pages/PageSpeed/Configure/index.css | 6 - .../src/Pages/PageSpeed/Configure/index.jsx | 230 +++++++++++------- 2 files changed, 143 insertions(+), 93 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Configure/index.css b/Client/src/Pages/PageSpeed/Configure/index.css index c9790c3d8..ee04d7ab2 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.css +++ b/Client/src/Pages/PageSpeed/Configure/index.css @@ -1,13 +1,7 @@ -.configure-pagespeed .checkbox-wrapper { - margin-bottom: 1px; -} .configure-pagespeed button { height: var(--env-var-height-2); } -.configure-pagespeed h3.MuiTypography-root { - flex: 0.7; -} .configure-pagespeed .field, .configure-pagespeed .section-disabled, .configure-pagespeed .select-wrapper { diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index b056404eb..297940cd3 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -13,6 +13,7 @@ import { import { monitorValidation } from "../../../Validation/validation"; import { createToast } from "../../../Utils/toastUtils"; import { logger } from "../../../Utils/Logger"; +import { ConfigBox } from "../../Monitors/styled"; import Field from "../../../Components/Inputs/Field"; import Select from "../../../Components/Inputs/Select"; import Checkbox from "../../../Components/Inputs/Checkbox"; @@ -22,20 +23,27 @@ import PulseDot from "../../../Components/Animated/PulseDot"; import LoadingButton from "@mui/lab/LoadingButton"; import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded"; import SkeletonLayout from "./skeleton"; -import "./index.css"; import useUtils from "../../Monitors/utils"; +import "./index.css"; const PageSpeedConfigure = () => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); const MS_PER_MINUTE = 60000; - const { authToken } = useSelector((state) => state.auth); + const { user, authToken } = useSelector((state) => state.auth); const { isLoading } = useSelector((state) => state.pageSpeedMonitors); const { monitorId } = useParams(); const [monitor, setMonitor] = useState({}); const [errors, setErrors] = useState({}); const { statusColor, pagespeedStatusMsg, determineState } = useUtils(); + const idMap = { + "monitor-url": "url", + "monitor-name": "name", + "monitor-checks-http": "type", + "monitor-checks-ping": "type", + "notify-email-default": "notification-email", + }; const frequencies = [ { _id: 3, name: "3 minutes" }, @@ -68,24 +76,58 @@ const PageSpeedConfigure = () => { fetchMonitor(); }, [dispatch, authToken, monitorId, navigate]); - const handleChange = (event, id) => { - let { value } = event.target; - if (id === "interval") { - value = value * MS_PER_MINUTE; + const handleChange = (event, name) => { + let { value, id } = event.target; + if (!name) name = idMap[id]; + + if (name.includes("notification-")) { + name = name.replace("notification-", ""); + let hasNotif = monitor.notifications.some( + (notification) => notification.type === name + ); + setMonitor((prev) => { + const notifs = [...prev.notifications]; + if (hasNotif) { + return { + ...prev, + notifications: notifs.filter((notif) => notif.type !== name), + }; + } else { + return { + ...prev, + notifications: [ + ...notifs, + name === "email" + ? { type: name, address: value } + : // TODO - phone number + { type: name, phone: value }, + ], + }; + } + }); + } else { + if (name === "interval") { + value = value * MS_PER_MINUTE; + } + setMonitor((prev) => ({ + ...prev, + [name]: value, + })); + + const validation = monitorValidation.validate( + { [name]: value }, + { abortEarly: false } + ); + + setErrors((prev) => { + const updatedErrors = { ...prev }; + + if (validation.error) + updatedErrors[name] = validation.error.details[0].message; + else delete updatedErrors[name]; + return updatedErrors; + }); } - setMonitor((prev) => ({ ...prev, [id]: value })); - - const { error } = monitorValidation.validate( - { [id]: value }, - { abortEarly: false } - ); - - setErrors((prev) => { - const newErrors = { ...prev }; - if (error) newErrors[id] = error.details[0].message; - else delete newErrors[id]; - return newErrors; - }); }; const handlePause = async () => { @@ -249,102 +291,116 @@ const PageSpeedConfigure = () => { - - - Monitor display name - handleChange(event, "name")} - error={errors.name} - /> - + + + General settings + + Here you can select the URL of the host, together with the + type of monitor. + + .Mui-disabled)": { backgroundColor: theme.palette.background.accent, }, }} > - URL handleChange(event, "url")} + onChange={handleChange} error={errors.url} disabled={true} /> - - - Check frequency - handleChange(event, "interval")} + /> + + Date: Tue, 17 Sep 2024 08:12:23 +0800 Subject: [PATCH 61/82] Remove checks from monitor query --- Client/src/Pages/Incidents/index.jsx | 3 ++- Server/controllers/monitorController.js | 1 - Server/db/mongo/modules/monitorModule.js | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 8bd2928cb..f70703828 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -28,7 +28,7 @@ const Incidents = () => { const res = await networkService.getMonitorsByTeamId( authState.authToken, authState.user.teamId, - 1, + -1, null, null, null, @@ -36,6 +36,7 @@ const Incidents = () => { null, null ); + console.log(res.data.data); // Reduce to a lookup object for 0(1) lookup if (res?.data?.data?.monitors?.length > 0) { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { diff --git a/Server/controllers/monitorController.js b/Server/controllers/monitorController.js index 8011cec7d..f5bd98b74 100644 --- a/Server/controllers/monitorController.js +++ b/Server/controllers/monitorController.js @@ -271,7 +271,6 @@ const getMonitorsByTeamId = async (req, res, next) => { try { const teamId = req.params.teamId; const monitors = await req.db.getMonitorsByTeamId(req, res); - return res.json({ success: true, msg: successMessages.MONITOR_GET_BY_USER_ID(teamId), diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 42947f38e..58ac2e8c7 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -373,12 +373,18 @@ const getMonitorsByTeamId = async (req, res) => { sortOrder = -1; } else sortOrder = -1; - // This effectively removes limit, returning all checks - if (limit === undefined) limit = 0; - const monitors = await Monitor.find(monitorQuery) .skip(skip) .limit(rowsPerPage); + + // Early return if limit is set to -1, indicating we don't want any checks + if (limit === -1) { + return { monitors, monitorCount: monitorsCount }; + } + + // This effectively removes limit, returning all checks + if (limit === undefined) limit = 0; + // Map each monitor to include its associated checks const monitorsWithChecks = await Promise.all( monitors.map(async (monitor) => { From 3ba6f5a56b7e97de22564b49eee1ca762b47295e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 08:46:06 +0800 Subject: [PATCH 62/82] Fix type error --- Server/db/mongo/modules/monitorModule.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 58ac2e8c7..344fce188 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -378,7 +378,8 @@ const getMonitorsByTeamId = async (req, res) => { .limit(rowsPerPage); // Early return if limit is set to -1, indicating we don't want any checks - if (limit === -1) { + if (limit === "-1") { + console.log("early return"); return { monitors, monitorCount: monitorsCount }; } From 113d577ad25e8240463a8ac2a71a7a76a3d77d05 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 08:46:55 +0800 Subject: [PATCH 63/82] remove console log --- Server/db/mongo/modules/monitorModule.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 344fce188..a7c00d726 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -379,7 +379,6 @@ const getMonitorsByTeamId = async (req, res) => { // Early return if limit is set to -1, indicating we don't want any checks if (limit === "-1") { - console.log("early return"); return { monitors, monitorCount: monitorsCount }; } From 204e0bbf409a0e56179bcc6ec811395bcb50579a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 09:16:00 +0800 Subject: [PATCH 64/82] Add indices to DB --- Server/db/mongo/modules/checkModule.js | 5 ++--- Server/models/Check.js | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index 4bc405835..d057a4158 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -149,13 +149,12 @@ const getTeamChecks = async (req) => { let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query; // Get monitorIDs - const userMonitors = await Monitor.find({ teamId: teamId }); + const userMonitors = await Monitor.find({ teamId: teamId }).select("_id"); const monitorIds = userMonitors.map((monitor) => monitor._id); //Build check query // Default limit to 0 if not provided - limit = limit === "undefined" ? 0 : limit; - + limit = limit === undefined ? 0 : limit; // Default sort order is newest -> oldest sortOrder = sortOrder === "asc" ? 1 : -1; diff --git a/Server/models/Check.js b/Server/models/Check.js index 55bb2d988..acb20dfb9 100644 --- a/Server/models/Check.js +++ b/Server/models/Check.js @@ -19,6 +19,7 @@ const CheckSchema = mongoose.Schema( type: mongoose.Schema.Types.ObjectId, ref: "Monitor", immutable: true, + index: true, }, /** * Status of the check (true for up, false for down). @@ -27,6 +28,7 @@ const CheckSchema = mongoose.Schema( */ status: { type: Boolean, + index: true, }, /** * Response time of the check in milliseconds. @@ -43,6 +45,7 @@ const CheckSchema = mongoose.Schema( */ statusCode: { type: Number, + index: true, }, /** * Message or description of the check result. @@ -69,4 +72,6 @@ const CheckSchema = mongoose.Schema( } ); +CheckSchema.index({ createdAt: 1 }); + module.exports = mongoose.model("Check", CheckSchema); From b0942fdcaba815d4cfc09ed608754aa2f10961aa Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 17 Sep 2024 09:37:24 +0800 Subject: [PATCH 65/82] optimizations --- Server/db/mongo/modules/checkModule.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Server/db/mongo/modules/checkModule.js b/Server/db/mongo/modules/checkModule.js index d057a4158..6ab1fd51b 100644 --- a/Server/db/mongo/modules/checkModule.js +++ b/Server/db/mongo/modules/checkModule.js @@ -150,7 +150,6 @@ const getTeamChecks = async (req) => { // Get monitorIDs const userMonitors = await Monitor.find({ teamId: teamId }).select("_id"); - const monitorIds = userMonitors.map((monitor) => monitor._id); //Build check query // Default limit to 0 if not provided @@ -158,7 +157,7 @@ const getTeamChecks = async (req) => { // Default sort order is newest -> oldest sortOrder = sortOrder === "asc" ? 1 : -1; - checksQuery = { monitorId: { $in: monitorIds } }; + checksQuery = { monitorId: { $in: userMonitors } }; if (filter !== undefined) { checksQuery.status = false; @@ -191,8 +190,8 @@ const getTeamChecks = async (req) => { const checks = await Check.find(checksQuery) .skip(skip) .limit(rowsPerPage) - .sort({ createdAt: sortOrder }); - + .sort({ createdAt: sortOrder }) + .select(["monitorId", "status", "responseTime", "statusCode", "message"]); return { checksCount, checks }; }; From c81d359680a3e7668d368baf9e9f277c37086a08 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 17 Sep 2024 20:26:52 -0400 Subject: [PATCH 66/82] Added placeholder svg --- .../Pages/Incidents/IncidentTable/index.jsx | 9 +++++++++ Client/src/Pages/Incidents/index.jsx | 3 +-- Client/src/Pages/Monitors/Home/fallback.jsx | 12 ++++++++++-- Client/src/assets/Images/data_placeholder.svg | 19 +++++++++++++++++++ .../assets/Images/data_placeholder_dark.svg | 19 +++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 Client/src/assets/Images/data_placeholder.svg create mode 100644 Client/src/assets/Images/data_placeholder_dark.svg diff --git a/Client/src/Pages/Incidents/IncidentTable/index.jsx b/Client/src/Pages/Incidents/IncidentTable/index.jsx index f501c6f4e..6ca18a1e9 100644 --- a/Client/src/Pages/Incidents/IncidentTable/index.jsx +++ b/Client/src/Pages/Incidents/IncidentTable/index.jsx @@ -22,12 +22,15 @@ import { StatusLabel } from "../../../Components/Label"; import { logger } from "../../../Utils/Logger"; import { useTheme } from "@emotion/react"; import { formatDateWithTz } from "../../../Utils/timeUtils"; +import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react"; +import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react"; const IncidentTable = ({ monitors, selectedMonitor, filter }) => { const uiTimezone = useSelector((state) => state.ui.timezone); const theme = useTheme(); const { authToken, user } = useSelector((state) => state.auth); + const mode = useSelector((state) => state.ui.mode); const [checks, setChecks] = useState([]); const [checksCount, setChecksCount] = useState(0); const [paginationController, setPaginationController] = useState({ @@ -130,12 +133,18 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => { <> {checks?.length === 0 && selectedMonitor === "0" ? ( + + {mode === "light" ? : } + No incidents recorded yet. ) : checks?.length === 0 ? ( + + {mode === "light" ? : } + The monitor you have selected has no recorded incidents yet. diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index f70703828..4e7a37c6d 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -7,8 +7,8 @@ import { networkService } from "../../main"; import { useTheme } from "@emotion/react"; import Select from "../../Components/Inputs/Select"; import IncidentTable from "./IncidentTable"; -import "./index.css"; import SkeletonLayout from "./skeleton"; +import "./index.css"; const Incidents = () => { const theme = useTheme(); @@ -36,7 +36,6 @@ const Incidents = () => { null, null ); - console.log(res.data.data); // Reduce to a lookup object for 0(1) lookup if (res?.data?.data?.monitors?.length > 0) { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { diff --git a/Client/src/Pages/Monitors/Home/fallback.jsx b/Client/src/Pages/Monitors/Home/fallback.jsx index 088368b66..072677faa 100644 --- a/Client/src/Pages/Monitors/Home/fallback.jsx +++ b/Client/src/Pages/Monitors/Home/fallback.jsx @@ -1,25 +1,33 @@ -import { Button, Stack, Typography } from "@mui/material"; +import { Box, Button, Stack, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; +import { useSelector } from "react-redux"; +import PlaceholderLight from "../../../assets/Images/data_placeholder.svg?react"; +import PlaceholderDark from "../../../assets/Images/data_placeholder_dark.svg?react"; import PropTypes from "prop-types"; const Fallback = ({ isAdmin }) => { const theme = useTheme(); const navigate = useNavigate(); + const mode = useSelector((state) => state.ui.mode); return ( + + {mode === "light" ? : } + - No monitors found + No monitors found to display It looks like you don’t have any monitors set up yet. diff --git a/Client/src/assets/Images/data_placeholder.svg b/Client/src/assets/Images/data_placeholder.svg new file mode 100644 index 000000000..bf840b95f --- /dev/null +++ b/Client/src/assets/Images/data_placeholder.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Client/src/assets/Images/data_placeholder_dark.svg b/Client/src/assets/Images/data_placeholder_dark.svg new file mode 100644 index 000000000..7e2a811d5 --- /dev/null +++ b/Client/src/assets/Images/data_placeholder_dark.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + From e8cb09c16865a132e40e30aeec5cedaee788b2d5 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Tue, 17 Sep 2024 21:03:47 -0400 Subject: [PATCH 67/82] Increase stroke width on hover --- .../Charts/MonitorDetailsAreaChart/index.jsx | 8 ++++++-- Client/src/Pages/Monitors/Details/styled.jsx | 1 + Client/src/Pages/Monitors/utils.jsx | 6 +++--- .../Pages/PageSpeed/Details/Charts/AreaChart.jsx | 7 +++++-- Client/src/Pages/PageSpeed/Details/styled.jsx | 3 +++ Client/src/Pages/PageSpeed/card.jsx | 15 +++++++++------ 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 1114a84ff..30dae4b9a 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -10,7 +10,7 @@ import { } from "recharts"; import { Box, Stack, Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { useSelector } from "react-redux"; import { formatDateWithTz } from "../../../Utils/timeUtils"; import "./index.css"; @@ -112,6 +112,7 @@ CustomTick.propTypes = { const MonitorDetailsAreaChart = ({ checks }) => { const theme = useTheme(); const memoizedChecks = useMemo(() => checks, [checks[0]]); + const [isHovered, setIsHovered] = useState(false); return ( @@ -125,6 +126,8 @@ const MonitorDetailsAreaChart = ({ checks }) => { left: 0, bottom: 0, }} + onMouseMove={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} > { } + wrapperStyle={{ pointerEvents: "none" }} /> diff --git a/Client/src/Pages/Monitors/Details/styled.jsx b/Client/src/Pages/Monitors/Details/styled.jsx index 728df4922..42cc3560d 100644 --- a/Client/src/Pages/Monitors/Details/styled.jsx +++ b/Client/src/Pages/Monitors/Details/styled.jsx @@ -41,6 +41,7 @@ export const ChartBox = styled(Stack)(({ theme }) => ({ }, "& path": { transition: "fill 300ms ease", + transition: "stroke-width 400ms ease", }, })); diff --git a/Client/src/Pages/Monitors/utils.jsx b/Client/src/Pages/Monitors/utils.jsx index cc079fedc..49c551c6f 100644 --- a/Client/src/Pages/Monitors/utils.jsx +++ b/Client/src/Pages/Monitors/utils.jsx @@ -40,9 +40,9 @@ const useUtils = () => { "& h2": { color: theme.palette.error.main }, }, paused: { - backgroundColor: theme.palette.warning.light, - background: `linear-gradient(340deg, ${theme.palette.warning.dark} -60%, ${theme.palette.warning.light} 35%)`, - borderColor: theme.palette.warning.dark, + backgroundColor: theme.palette.warning.bg, + background: `linear-gradient(340deg, ${theme.palette.warning.light} -60%, ${theme.palette.warning.bg} 35%)`, + borderColor: theme.palette.warning.light, "& h2": { color: theme.palette.warning.main }, }, pending: { diff --git a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx index a0d230bf0..2b627b9d6 100644 --- a/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx +++ b/Client/src/Pages/PageSpeed/Details/Charts/AreaChart.jsx @@ -9,7 +9,7 @@ import { Text, } from "recharts"; import { useTheme } from "@emotion/react"; -import { useMemo } from "react"; +import { useMemo, useState } from "react"; import { Box, Stack, Typography } from "@mui/material"; import { formatDateWithTz } from "../../../../Utils/timeUtils"; import { useSelector } from "react-redux"; @@ -215,6 +215,7 @@ CustomTick.propTypes = { const PagespeedDetailsAreaChart = ({ data, interval, metrics }) => { const theme = useTheme(); + const [isHovered, setIsHovered] = useState(false); const memoizedData = useMemo( () => processDataWithGaps(data, interval), [data[0]] @@ -234,6 +235,8 @@ const PagespeedDetailsAreaChart = ({ data, interval, metrics }) => { height="100%" data={memoizedData} margin={{ top: 10 }} + onMouseMove={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} > { dataKey={key} stackId={1} stroke={strokeColor} - strokeWidth={1.5} + strokeWidth={isHovered ? 2.5 : 1.5} fill={`url(#${filteredConfig[key].id})`} activeDot={{ stroke: bgColor, fill: strokeColor, r: 4.5 }} /> diff --git a/Client/src/Pages/PageSpeed/Details/styled.jsx b/Client/src/Pages/PageSpeed/Details/styled.jsx index d4feb7c8d..cf0dda917 100644 --- a/Client/src/Pages/PageSpeed/Details/styled.jsx +++ b/Client/src/Pages/PageSpeed/Details/styled.jsx @@ -36,6 +36,9 @@ export const ChartBox = styled(Stack)(({ theme }) => ({ backgroundColor: theme.palette.background.main, background: `linear-gradient(325deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 45%)`, }, + "& path": { + transition: "stroke-width 400ms ease", + }, })); export const IconBox = styled(Box)(({ theme }) => ({ diff --git a/Client/src/Pages/PageSpeed/card.jsx b/Client/src/Pages/PageSpeed/card.jsx index 5c688a041..351ad45a1 100644 --- a/Client/src/Pages/PageSpeed/card.jsx +++ b/Client/src/Pages/PageSpeed/card.jsx @@ -13,12 +13,9 @@ import { Tooltip, } from "recharts"; import { useSelector } from "react-redux"; -import { - formatDateWithTz, - formatDurationRounded, - formatDurationSplit, -} from "../../Utils/timeUtils"; +import { formatDateWithTz, formatDurationSplit } from "../../Utils/timeUtils"; import useUtils from "../Monitors/utils"; +import { useState } from "react"; /** * CustomToolTip displays a tooltip with formatted date and score information. @@ -127,6 +124,7 @@ const processData = (data) => { */ const PagespeedAreaChart = ({ data, status }) => { const theme = useTheme(); + const [isHovered, setIsHovered] = useState(false); const { pagespeedStyles } = useUtils(); const formattedData = processData(data); @@ -139,6 +137,8 @@ const PagespeedAreaChart = ({ data, status }) => { data={formattedData} margin={{ top: 10, bottom: -5 }} style={{ cursor: "pointer" }} + onMouseMove={() => setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} > { { "&:hover": { backgroundColor: theme.palette.background.accent, }, + "& path": { + transition: "stroke-width 400ms ease", + }, }} > From 55588fde0d0c60d521087e03e65f808b0a8465a8 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 09:41:27 +0800 Subject: [PATCH 68/82] Combined transitions --- Client/src/Pages/Monitors/Details/styled.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Client/src/Pages/Monitors/Details/styled.jsx b/Client/src/Pages/Monitors/Details/styled.jsx index 42cc3560d..1e34fbbc9 100644 --- a/Client/src/Pages/Monitors/Details/styled.jsx +++ b/Client/src/Pages/Monitors/Details/styled.jsx @@ -40,8 +40,7 @@ export const ChartBox = styled(Stack)(({ theme }) => ({ fill: theme.palette.text.tertiary, }, "& path": { - transition: "fill 300ms ease", - transition: "stroke-width 400ms ease", + transition: "fill 300ms ease, stroke-width 400ms ease", }, })); From 7e1a5b6ec86d959f38c0c12715f05dc0d34297c3 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 10:32:41 +0800 Subject: [PATCH 69/82] add filter param, implement filter --- Client/src/Utils/NetworkService.js | 4 +-- Server/db/mongo/modules/monitorModule.js | 36 ++++++++++++++++-------- Server/validation/joi.js | 5 +++- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index 683ce1aba..2e257d366 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -98,7 +98,7 @@ class NetworkService { limit, types, status, - sortOrder, + checkOrder, normalize, page, rowsPerPage @@ -112,7 +112,7 @@ class NetworkService { }); } if (status) params.append("status", status); - if (sortOrder) params.append("sortOrder", sortOrder); + if (checkOrder) params.append("checkOrder", checkOrder); if (normalize) params.append("normalize", normalize); if (page) params.append("page", page); if (rowsPerPage) params.append("rowsPerPage", rowsPerPage); diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index a7c00d726..ccfe61f3e 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -347,13 +347,25 @@ const getMonitorsAndSummaryByTeamId = async (teamId, type) => { */ const getMonitorsByTeamId = async (req, res) => { try { - let { limit, type, status, sortOrder, normalize, page, rowsPerPage } = - req.query || {}; - const monitorQuery = { teamId: req.params.teamId }; - const monitorsCount = await Monitor.countDocuments({ - teamId: req.params.teamId, + let { + limit, type, - }); + status, + checkOrder, + normalize, + page, + rowsPerPage, + filter, + } = req.query || {}; + const monitorQuery = { teamId: req.params.teamId, type }; + // Add filter if provided + if (filter !== undefined) { + monitorQuery.$or = [ + { name: { $regex: filter, $options: "i" } }, + { url: { $regex: filter, $options: "i" } }, + ]; + } + const monitorsCount = await Monitor.countDocuments(monitorQuery); // Pagination let skip = 0; @@ -367,11 +379,11 @@ const getMonitorsByTeamId = async (req, res) => { } // Default sort order is newest -> oldest - if (sortOrder === "asc") { - sortOrder = 1; - } else if (sortOrder === "desc") { - sortOrder = -1; - } else sortOrder = -1; + if (checkOrder === "asc") { + checkOrder = 1; + } else if (checkOrder === "desc") { + checkOrder = -1; + } else checkOrder = -1; const monitors = await Monitor.find(monitorQuery) .skip(skip) @@ -402,7 +414,7 @@ const getMonitorsByTeamId = async (req, res) => { let checks = await model .find(checksQuery) .sort({ - createdAt: sortOrder, + createdAt: checkOrder, }) .limit(limit); diff --git a/Server/validation/joi.js b/Server/validation/joi.js index dfb0e6fe7..dc82dc73e 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -180,7 +180,7 @@ const getMonitorsByTeamIdValidation = joi.object({ const getMonitorsByTeamIdQueryValidation = joi.object({ status: joi.boolean(), - sortOrder: joi.string().valid("asc", "desc"), + checkOrder: joi.string().valid("asc", "desc"), limit: joi.number(), normalize: joi.boolean(), type: joi @@ -191,6 +191,9 @@ const getMonitorsByTeamIdQueryValidation = joi.object({ ), page: joi.number(), rowsPerPage: joi.number(), + filter: joi.string(), + field: joi.string(), + order: joi.string().valid("asc", "desc"), }); const getMonitorStatsByIdParamValidation = joi.object({ From 2d2b101eb7c52c9ec8ac3157ecb4a157fa515ee4 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 10:39:47 +0800 Subject: [PATCH 70/82] implement sorting --- .../src/Pages/Monitors/Home/MonitorTable/index.jsx | 5 ++++- Client/src/Utils/NetworkService.js | 8 +++++++- Server/db/mongo/modules/monitorModule.js | 13 ++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 5c43ad880..f09b98215 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -151,7 +151,10 @@ const MonitorTable = ({ isAdmin }) => { "desc", true, page, - rowsPerPage + rowsPerPage, + null, + "createdAt", + "desc" ); setMonitors(res?.data?.data?.monitors ?? []); setMonitorCount(res?.data?.data?.monitorCount ?? 0); diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index 2e257d366..02f009a36 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -101,7 +101,10 @@ class NetworkService { checkOrder, normalize, page, - rowsPerPage + rowsPerPage, + filter, + field, + order ) { const params = new URLSearchParams(); @@ -116,6 +119,9 @@ class NetworkService { if (normalize) params.append("normalize", normalize); if (page) params.append("page", page); if (rowsPerPage) params.append("rowsPerPage", rowsPerPage); + if (filter) params.append("filter", filter); + if (field) params.append("field", field); + if (order) params.append("order", order); return this.axiosInstance.get( `/monitors/team/${teamId}?${params.toString()}`, diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index ccfe61f3e..85fe8ab03 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -356,9 +356,13 @@ const getMonitorsByTeamId = async (req, res) => { page, rowsPerPage, filter, + field, + order, } = req.query || {}; + const monitorQuery = { teamId: req.params.teamId, type }; // Add filter if provided + // $options: "i" makes the search case-insensitive if (filter !== undefined) { monitorQuery.$or = [ { name: { $regex: filter, $options: "i" } }, @@ -385,9 +389,16 @@ const getMonitorsByTeamId = async (req, res) => { checkOrder = -1; } else checkOrder = -1; + // Sort order for monitors + let sort = {}; + if (field !== undefined && order !== undefined) { + sort[field] = order === "asc" ? 1 : -1; + } + const monitors = await Monitor.find(monitorQuery) .skip(skip) - .limit(rowsPerPage); + .limit(rowsPerPage) + .sort(sort); // Early return if limit is set to -1, indicating we don't want any checks if (limit === "-1") { From cab023709b4f2fb68189de09b6b57ce5a88a1afb Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 10:40:20 +0800 Subject: [PATCH 71/82] default no filtering or ordering --- Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index f09b98215..e93858d3e 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -153,8 +153,8 @@ const MonitorTable = ({ isAdmin }) => { page, rowsPerPage, null, - "createdAt", - "desc" + null, + null ); setMonitors(res?.data?.data?.monitors ?? []); setMonitorCount(res?.data?.data?.monitorCount ?? 0); From 4748afb93a29d65174a940f5ba846fff5a80e9dc Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 10:57:44 +0800 Subject: [PATCH 72/82] refactor networkSerivce.getMonitorsByTeamId to take a config objet --- Client/src/Pages/Incidents/index.jsx | 25 ++++++---- .../Monitors/Home/MonitorTable/index.jsx | 26 +++++----- Client/src/Pages/PageSpeed/index.jsx | 25 ++++++---- Client/src/Utils/NetworkService.js | 50 +++++++++++-------- Server/db/mongo/modules/monitorModule.js | 6 ++- 5 files changed, 74 insertions(+), 58 deletions(-) diff --git a/Client/src/Pages/Incidents/index.jsx b/Client/src/Pages/Incidents/index.jsx index 4e7a37c6d..10ab30ad5 100644 --- a/Client/src/Pages/Incidents/index.jsx +++ b/Client/src/Pages/Incidents/index.jsx @@ -25,17 +25,20 @@ const Incidents = () => { useEffect(() => { const fetchMonitors = async () => { setLoading(true); - const res = await networkService.getMonitorsByTeamId( - authState.authToken, - authState.user.teamId, - -1, - null, - null, - null, - null, - null, - null - ); + const res = await networkService.getMonitorsByTeamId({ + authToken: authState.authToken, + teamId: authState.user.teamId, + limit: -1, + types: null, + status: null, + checkOrder: null, + normalize: null, + page: null, + rowsPerPage: null, + filter: null, + field: null, + order: null, + }); // Reduce to a lookup object for 0(1) lookup if (res?.data?.data?.monitors?.length > 0) { const monitorLookup = res.data.data.monitors.reduce((acc, monitor) => { diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index e93858d3e..7203edda7 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -142,20 +142,20 @@ const MonitorTable = ({ isAdmin }) => { try { const { authToken } = authState; const user = jwtDecode(authToken); - const res = await networkService.getMonitorsByTeamId( + const res = await networkService.getMonitorsByTeamId({ authToken, - user.teamId, - 25, - ["http", "ping"], - null, - "desc", - true, - page, - rowsPerPage, - null, - null, - null - ); + teamId: user.teamId, + limit: 25, + types: ["http", "ping"], + status: null, + checkOrder: "desc", + normalize: true, + page: page, + rowsPerPage: rowsPerPage, + filter: null, + field: null, + order: null, + }); setMonitors(res?.data?.data?.monitors ?? []); setMonitorCount(res?.data?.data?.monitorCount ?? 0); } catch (error) { diff --git a/Client/src/Pages/PageSpeed/index.jsx b/Client/src/Pages/PageSpeed/index.jsx index a76e4cca1..3e78b1d6b 100644 --- a/Client/src/Pages/PageSpeed/index.jsx +++ b/Client/src/Pages/PageSpeed/index.jsx @@ -29,17 +29,20 @@ const PageSpeed = ({ isAdmin }) => { const fetchMonitors = async () => { try { setIsLoading(true); - const res = await networkService.getMonitorsByTeamId( - authToken, - user.teamId, - 10, - ["pagespeed"], - null, - "desc", - true, - null, - null - ); + const res = await networkService.getMonitorsByTeamId({ + authToken: authToken, + teamId: user.teamId, + limit: 10, + types: ["pagespeed"], + status: null, + checkOrder: "desc", + normalize: true, + page: null, + rowsPerPage: null, + filter: null, + field: null, + order: null, + }); if (res?.data?.data?.monitors) { setMonitors(res.data.data.monitors); } diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index 02f009a36..63323d5a8 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -83,29 +83,37 @@ class NetworkService { * ************************************ * * @async - * @param {string} authToken - The authorization token to be used in the request header. - * @param {string} userId - The ID of the user whose monitors are to be retrieved. - * @param {number} [limit] - The maximum number of monitors to retrieve. - * @param {Array} [types] - The types of monitors to retrieve. - * @param {string} [status] - The status of the monitors to retrieve. - * @param {string} [sortOrder] - The order in which to sort the retrieved monitors. - * @param {boolean} [normalize] - Whether to normalize the retrieved monitors. + * @param {Object} config - The configuration object. + * @param {string} config.authToken - The authorization token to be used in the request header. + * @param {string} config.teamId - The ID of the team whose monitors are to be retrieved. + * @param {number} [config.limit] - The maximum number of monitors to retrieve. + * @param {Array} [config.types] - The types of monitors to retrieve. + * @param {string} [config.status] - The status of the monitors to retrieve. + * @param {string} [config.checkOrder] - The order in which to sort the retrieved monitors. + * @param {boolean} [config.normalize] - Whether to normalize the retrieved monitors. + * @param {number} [config.page] - The page number for pagination. + * @param {number} [config.rowsPerPage] - The number of rows per page for pagination. + * @param {string} [config.filter] - The filter to apply to the monitors. + * @param {string} [config.field] - The field to sort by. + * @param {string} [config.order] - The order in which to sort the field. * @returns {Promise} The response from the axios GET request. */ - async getMonitorsByTeamId( - authToken, - teamId, - limit, - types, - status, - checkOrder, - normalize, - page, - rowsPerPage, - filter, - field, - order - ) { + async getMonitorsByTeamId(config) { + const { + authToken, + teamId, + limit, + types, + status, + checkOrder, + normalize, + page, + rowsPerPage, + filter, + field, + order, + } = config; + const params = new URLSearchParams(); if (limit) params.append("limit", limit); diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 85fe8ab03..002bf9c41 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -359,8 +359,10 @@ const getMonitorsByTeamId = async (req, res) => { field, order, } = req.query || {}; - - const monitorQuery = { teamId: req.params.teamId, type }; + const monitorQuery = { teamId: req.params.teamId }; + if (type !== undefined) { + monitorQuery.type = type; + } // Add filter if provided // $options: "i" makes the search case-insensitive if (filter !== undefined) { From 87f9b2acf6b794e02d57c8984556a0a32db2d343 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 11:40:05 +0800 Subject: [PATCH 73/82] implement sorting on monitor table --- .../Monitors/Home/MonitorTable/index.jsx | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 7203edda7..6adcf5d8f 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -14,6 +14,7 @@ import { Button, } from "@mui/material"; import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded"; +import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded"; import { setRowsPerPage } from "../../../../Features/UI/uiSlice"; import { useState, useEffect } from "react"; @@ -48,6 +49,7 @@ import useUtils from "../../utils"; */ const TablePaginationActions = (props) => { const { count, page, rowsPerPage, onPageChange } = props; + const handleFirstPageButtonClick = (event) => { onPageChange(event, 0); }; @@ -118,6 +120,7 @@ const MonitorTable = ({ isAdmin }) => { const [monitorCount, setMonitorCount] = useState(0); const authState = useSelector((state) => state.auth); const [updateTrigger, setUpdateTrigger] = useState(false); + const [sort, setSort] = useState({}); const handleActionMenuDelete = () => { setUpdateTrigger((prev) => !prev); @@ -175,19 +178,74 @@ const MonitorTable = ({ isAdmin }) => { return `${start} - ${end}`; }; + const handleSort = async (field) => { + let order = ""; + if (sort.field !== field) { + order = "desc"; + } else { + order = sort.order === "asc" ? "desc" : "asc"; + } + setSort({ field, order }); + + const { authToken } = authState; + const user = jwtDecode(authToken); + + const res = await networkService.getMonitorsByTeamId({ + authToken, + teamId: user.teamId, + limit: 25, + types: ["http", "ping"], + status: null, + checkOrder: "desc", + normalize: true, + page: page, + rowsPerPage: rowsPerPage, + filter: null, + field: field, + order: order, + }); + setMonitors(res?.data?.data?.monitors ?? []); + setMonitorCount(res?.data?.data?.monitorCount ?? 0); + }; + return ( <> - Host - + handleSort("name")}> + + Host + + {sort.order === "asc" ? ( + + ) : ( + + )} + + + + handleSort("status")}> {" "} + {" "} Status - - + + {sort.order === "asc" ? ( + + ) : ( + + )} From 98f12d28a3c0923a878c927997210a63cd1dfab4 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 11:43:32 +0800 Subject: [PATCH 74/82] Add cursor type --- Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 6adcf5d8f..54e78c053 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -214,7 +214,10 @@ const MonitorTable = ({ isAdmin }) => {
- handleSort("name")}> + handleSort("name")} + > Host { - handleSort("status")}> + handleSort("status")} + > {" "} {" "} From 354b0fd92f68163c4db9d1e660cb7b786df36383 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Sep 2024 11:47:54 +0800 Subject: [PATCH 75/82] Add sort order and field to request --- Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 54e78c053..4e464946e 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -156,8 +156,8 @@ const MonitorTable = ({ isAdmin }) => { page: page, rowsPerPage: rowsPerPage, filter: null, - field: null, - order: null, + field: sort.field, + order: sort.order, }); setMonitors(res?.data?.data?.monitors ?? []); setMonitorCount(res?.data?.data?.monitorCount ?? 0); From 594509f3d9b3659d9a97bcfb0cb963eb1e0b9dc9 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 18 Sep 2024 17:14:03 -0400 Subject: [PATCH 76/82] Initial styling and structure --- .../Components/Inputs/Autocomplete/index.jsx | 116 ----------------- Client/src/Components/Inputs/Search/index.jsx | 121 ++++++++++++++++++ Client/src/Pages/Monitors/Details/styled.jsx | 3 +- Client/src/Pages/Monitors/Home/index.jsx | 10 +- Client/src/Utils/Theme/lightTheme.js | 3 +- 5 files changed, 132 insertions(+), 121 deletions(-) delete mode 100644 Client/src/Components/Inputs/Autocomplete/index.jsx create mode 100644 Client/src/Components/Inputs/Search/index.jsx diff --git a/Client/src/Components/Inputs/Autocomplete/index.jsx b/Client/src/Components/Inputs/Autocomplete/index.jsx deleted file mode 100644 index 5256efccc..000000000 --- a/Client/src/Components/Inputs/Autocomplete/index.jsx +++ /dev/null @@ -1,116 +0,0 @@ -import { Autocomplete, TextField } from "@mui/material"; -import React from "react"; -import PropTypes from "prop-types"; -import { useTheme } from "@emotion/react"; - -/** - * @example - * - * const options = [ - * { _id: "66d6119ef959cbc681e034f0", name: "Googler" }, - * { _id: "66d6119ef959cbc681e034f0", name: "CNN" }, - * { _id: "66d61a1bf959cbc681e0353f", name: "X Corp." }, - * ]; - * - * - * - */ - -/** - * AutoCompleteField component. - * - * @component - * @param {Object} props - The component props. - * @param {string} props.id - The ID of the autocomplete field. - * @param {string} props.type - The type of the input field (text or number). - * @param {Array} props.options - The options for the autocomplete field. - * @param {string} props.placeholder - The placeholder text for the input field. - * @param {boolean} props.disabled - Indicates if the field is disabled. - * @returns {JSX.Element} The AutoCompleteField component. - */ - -const AutoCompleteField = ({ - id, - type, - options, - placeholder = "Type to search", - disabled, -}) => { - const [value, setValue] = React.useState(); - const [inputValue, setInputValue] = React.useState(""); - const theme = useTheme(); - - return ( - { - setValue(newValue); - }} - inputValue={inputValue} - onInputChange={(event, newInputValue) => { - setInputValue(newInputValue); - }} - options={options} - getOptionLabel={(option) => option.name} - renderInput={(params) => ( - - )} - renderOption={(props, option) => { - const { key, ...optionProps } = props; - return ( -
  • -
    {{option.name}}
    -
  • - ); - }} - slotProps={{ - popper: { - sx: { - "& ul": { p: 0 }, - "& li": { borderRadius: theme.shape.borderRadius }, - }, - }, - paper: { - sx: { - p: 2, - fontSize: 13, - }, - }, - }} - /> - ); -}; - -AutoCompleteField.displayName = "AutoCompleteField"; - -AutoCompleteField.propTypes = { - id: PropTypes.string, - type: PropTypes.oneOf(["text", "number"]), - options: PropTypes.array, - placeholder: PropTypes.string, - disabled: PropTypes.bool, - setWidth: PropTypes.string, -}; - -export default AutoCompleteField; diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx new file mode 100644 index 000000000..ab6586119 --- /dev/null +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -0,0 +1,121 @@ +import PropTypes from "prop-types"; +import { Box, ListItem, Autocomplete, TextField } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import SearchIcon from "../../../assets/icons/search.svg?react"; + +const options = [ + "Google", + "Material UI", + "Alias", + "Twitter", + "Discord", + "YouTube", +]; + +const Search = ({ id, sx }) => { + const theme = useTheme(); + + return ( + ( + + +
    + ), + }} + sx={{ + "& fieldset": { + borderColor: theme.palette.border.light, + borderRadius: theme.shape.borderRadius, + }, + "& .MuiOutlinedInput-root:hover:not(:has(input:focus)):not(:has(textarea:focus)) fieldset": + { + borderColor: theme.palette.border.light, + }, + }} + /> + )} + filterOptions={(options, { inputValue }) => { + const filtered = options.filter((option) => + option.toLowerCase().includes(inputValue.toLowerCase()) + ); + + if (filtered.length === 0) { + return [{ label: "No monitors found", noOptions: true }]; + } + return filtered; + }} + renderOption={(props, option) => { + const { key, ...optionProps } = props; + return ( + + {option.noOptions ? option.label : option} + + ); + }} + slotProps={{ + popper: { + keepMounted: true, + sx: { + "& ul": { p: 2 }, + "& li.MuiAutocomplete-option": { + color: theme.palette.text.secondary, + px: 4, + borderRadius: theme.shape.borderRadius, + }, + "& .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true'], & .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true'].Mui-focused, & .MuiAutocomplete-listbox .MuiAutocomplete-option[aria-selected='true']:hover": + { + backgroundColor: theme.palette.background.fill, + }, + "& .MuiAutocomplete-noOptions": { + px: theme.spacing(6), + py: theme.spacing(5), + }, + }, + }, + }} + sx={{ + height: 34, + "&.MuiAutocomplete-root .MuiAutocomplete-input": { p: 0 }, + ...sx, + }} + /> + ); +}; + +export default Search; diff --git a/Client/src/Pages/Monitors/Details/styled.jsx b/Client/src/Pages/Monitors/Details/styled.jsx index 42cc3560d..1e34fbbc9 100644 --- a/Client/src/Pages/Monitors/Details/styled.jsx +++ b/Client/src/Pages/Monitors/Details/styled.jsx @@ -40,8 +40,7 @@ export const ChartBox = styled(Stack)(({ theme }) => ({ fill: theme.palette.text.tertiary, }, "& path": { - transition: "fill 300ms ease", - transition: "stroke-width 400ms ease", + transition: "fill 300ms ease, stroke-width 400ms ease", }, })); diff --git a/Client/src/Pages/Monitors/Home/index.jsx b/Client/src/Pages/Monitors/Home/index.jsx index b66076387..a6518f56b 100644 --- a/Client/src/Pages/Monitors/Home/index.jsx +++ b/Client/src/Pages/Monitors/Home/index.jsx @@ -12,6 +12,7 @@ import StatusBox from "./StatusBox"; import Breadcrumbs from "../../../Components/Breadcrumbs"; import Greeting from "../../../Utils/greeting"; import MonitorTable from "./MonitorTable"; +import Search from "../../../Components/Inputs/Search"; const Monitors = ({ isAdmin }) => { const theme = useTheme(); @@ -26,6 +27,8 @@ const Monitors = ({ isAdmin }) => { let loading = monitorState?.isLoading && monitorState?.monitorsSummary?.monitors?.length === 0; + + console.log(monitorState.monitorsSummary.monitors); return ( {loading ? ( @@ -85,7 +88,8 @@ const Monitors = ({ isAdmin }) => { { > {monitorState?.monitorsSummary?.monitorCounts?.total || 0} - {/* TODO - add search bar */} + + + diff --git a/Client/src/Utils/Theme/lightTheme.js b/Client/src/Utils/Theme/lightTheme.js index c80633a20..5d8d76cde 100644 --- a/Client/src/Utils/Theme/lightTheme.js +++ b/Client/src/Utils/Theme/lightTheme.js @@ -151,12 +151,14 @@ const lightTheme = createTheme({ styleOverrides: { root: { marginTop: 4, + padding: 0, border: 1, borderStyle: "solid", borderColor: border.light, borderRadius: 4, boxShadow: shadow, backgroundColor: background.main, + backgroundImage: "none", }, }, }, @@ -183,7 +185,6 @@ const lightTheme = createTheme({ color: text.secondary, fontSize: 13, margin: 2, - marginBottom: 0, minWidth: 100, "&:hover, &.Mui-selected, &.Mui-selected:hover, &.Mui-selected.Mui-focusVisible": { From 200c5fa52329f74cd3651b582ccc11141b2c8b96 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 18 Sep 2024 17:22:58 -0400 Subject: [PATCH 77/82] Hooked up search to state --- Client/src/Components/Inputs/Search/index.jsx | 22 ++++++++----------- Client/src/Pages/Monitors/Home/index.jsx | 10 ++++++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx index ab6586119..b8eaf89b6 100644 --- a/Client/src/Components/Inputs/Search/index.jsx +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -3,25 +3,21 @@ import { Box, ListItem, Autocomplete, TextField } from "@mui/material"; import { useTheme } from "@emotion/react"; import SearchIcon from "../../../assets/icons/search.svg?react"; -const options = [ - "Google", - "Material UI", - "Alias", - "Twitter", - "Discord", - "YouTube", -]; - -const Search = ({ id, sx }) => { +const Search = ({ id, options, value, handleChange, sx }) => { const theme = useTheme(); return ( { + handleChange(newValue); + }} fullWidth freeSolo disableClearable options={options} + getOptionLabel={(option) => option.name} renderInput={(params) => ( { )} filterOptions={(options, { inputValue }) => { const filtered = options.filter((option) => - option.toLowerCase().includes(inputValue.toLowerCase()) + option.name.toLowerCase().includes(inputValue.toLowerCase()) ); if (filtered.length === 0) { - return [{ label: "No monitors found", noOptions: true }]; + return [{ name: "No monitors found", noOptions: true }]; } return filtered; }} @@ -84,7 +80,7 @@ const Search = ({ id, sx }) => { : {} } > - {option.noOptions ? option.label : option} + {option.name} ); }} diff --git a/Client/src/Pages/Monitors/Home/index.jsx b/Client/src/Pages/Monitors/Home/index.jsx index a6518f56b..36921d1f5 100644 --- a/Client/src/Pages/Monitors/Home/index.jsx +++ b/Client/src/Pages/Monitors/Home/index.jsx @@ -1,5 +1,5 @@ import "./index.css"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { getUptimeMonitorsByTeamId } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice"; import { useNavigate } from "react-router-dom"; @@ -19,6 +19,7 @@ const Monitors = ({ isAdmin }) => { const navigate = useNavigate(); const monitorState = useSelector((state) => state.uptimeMonitors); const authState = useSelector((state) => state.auth); + const [search, setSearch] = useState(""); const dispatch = useDispatch({}); useEffect(() => { @@ -28,7 +29,6 @@ const Monitors = ({ isAdmin }) => { monitorState?.isLoading && monitorState?.monitorsSummary?.monitors?.length === 0; - console.log(monitorState.monitorsSummary.monitors); return ( {loading ? ( @@ -118,7 +118,11 @@ const Monitors = ({ isAdmin }) => { {monitorState?.monitorsSummary?.monitorCounts?.total || 0} - + From db4f509f8798ecab3d4b8c8becf23212f0af6308 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 18 Sep 2024 17:24:36 -0400 Subject: [PATCH 78/82] Added docs --- Client/src/Components/Inputs/Search/index.jsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx index b8eaf89b6..a148c4082 100644 --- a/Client/src/Components/Inputs/Search/index.jsx +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -3,6 +3,17 @@ import { Box, ListItem, Autocomplete, TextField } from "@mui/material"; import { useTheme } from "@emotion/react"; import SearchIcon from "../../../assets/icons/search.svg?react"; +/** + * Search component using Material UI's Autocomplete. + * + * @param {Object} props + * @param {string} props.id - Unique identifier for the Autocomplete component + * @param {Array} props.options - Options to display in the Autocomplete dropdown + * @param {string} props.value - Current input value for the Autocomplete + * @param {Function} props.handleChange - Function to call when the input changes + * @param {Object} props.sx - Additional styles to apply to the component + * @returns {JSX.Element} The rendered Search component + */ const Search = ({ id, options, value, handleChange, sx }) => { const theme = useTheme(); @@ -114,4 +125,16 @@ const Search = ({ id, options, value, handleChange, sx }) => { ); }; +Search.propTypes = { + id: PropTypes.string, + options: PropTypes.arrayOf( + PropTypes.shape({ + name: PropTypes.string.isRequired, + }) + ).isRequired, + value: PropTypes.string.isRequired, + handleChange: PropTypes.func.isRequired, + sx: PropTypes.object, +}; + export default Search; From 0aebad25120188ebc00cdec1d8e1259fc8393c40 Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 18 Sep 2024 20:13:36 -0400 Subject: [PATCH 79/82] Memoized monitor table --- Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 5c43ad880..5b5883440 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -16,7 +16,7 @@ import { import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded"; import { setRowsPerPage } from "../../../../Features/UI/uiSlice"; -import { useState, useEffect } from "react"; +import { useState, useEffect, memo } from "react"; import { useNavigate } from "react-router"; import { logger } from "../../../../Utils/Logger"; import Host from "../host"; @@ -106,7 +106,7 @@ TablePaginationActions.propTypes = { onPageChange: PropTypes.func.isRequired, }; -const MonitorTable = ({ isAdmin }) => { +const MonitorTable = memo(({ isAdmin }) => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); @@ -335,7 +335,7 @@ const MonitorTable = ({ isAdmin }) => { ); -}; +}); MonitorTable.propTypes = { isAdmin: PropTypes.bool, From 5b913d9820076cf5f5204d47f0a5eaa393ce29c7 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 19 Sep 2024 08:18:16 +0800 Subject: [PATCH 80/82] Name anonymous export --- Client/src/Pages/Monitors/Home/MonitorTable/index.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 5b5883440..2fbdf3ca6 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -106,7 +106,7 @@ TablePaginationActions.propTypes = { onPageChange: PropTypes.func.isRequired, }; -const MonitorTable = memo(({ isAdmin }) => { +const MonitorTable = ({ isAdmin }) => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); @@ -335,10 +335,11 @@ const MonitorTable = memo(({ isAdmin }) => { ); -}); +}; MonitorTable.propTypes = { isAdmin: PropTypes.bool, }; -export default MonitorTable; +const MemoizedMonitorTable = memo(MonitorTable); +export default MemoizedMonitorTable; From 732645929b32b311ecd8d92c1e0ef1a0242c0b8a Mon Sep 17 00:00:00 2001 From: Daniel Cojocea Date: Wed, 18 Sep 2024 20:27:55 -0400 Subject: [PATCH 81/82] Generalized filter --- Client/src/Components/Inputs/Search/index.jsx | 18 +++---- Client/src/Components/Search/index.css | 0 Client/src/Components/Search/index.jsx | 49 ------------------- Client/src/Pages/Monitors/Home/index.jsx | 1 + 4 files changed, 9 insertions(+), 59 deletions(-) delete mode 100644 Client/src/Components/Search/index.css delete mode 100644 Client/src/Components/Search/index.jsx diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx index a148c4082..b69b25731 100644 --- a/Client/src/Components/Inputs/Search/index.jsx +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -9,12 +9,13 @@ import SearchIcon from "../../../assets/icons/search.svg?react"; * @param {Object} props * @param {string} props.id - Unique identifier for the Autocomplete component * @param {Array} props.options - Options to display in the Autocomplete dropdown + * @param {string} props.filteredBy - Key to access the option label from the options * @param {string} props.value - Current input value for the Autocomplete * @param {Function} props.handleChange - Function to call when the input changes * @param {Object} props.sx - Additional styles to apply to the component * @returns {JSX.Element} The rendered Search component */ -const Search = ({ id, options, value, handleChange, sx }) => { +const Search = ({ id, options, filteredBy, value, handleChange, sx }) => { const theme = useTheme(); return ( @@ -28,7 +29,7 @@ const Search = ({ id, options, value, handleChange, sx }) => { freeSolo disableClearable options={options} - getOptionLabel={(option) => option.name} + getOptionLabel={(option) => option[filteredBy]} renderInput={(params) => ( { )} filterOptions={(options, { inputValue }) => { const filtered = options.filter((option) => - option.name.toLowerCase().includes(inputValue.toLowerCase()) + option[filteredBy].toLowerCase().includes(inputValue.toLowerCase()) ); if (filtered.length === 0) { - return [{ name: "No monitors found", noOptions: true }]; + return [{ [filteredBy]: "No monitors found", noOptions: true }]; } return filtered; }} @@ -91,7 +92,7 @@ const Search = ({ id, options, value, handleChange, sx }) => { : {} } > - {option.name} + {option[filteredBy]} ); }} @@ -127,11 +128,8 @@ const Search = ({ id, options, value, handleChange, sx }) => { Search.propTypes = { id: PropTypes.string, - options: PropTypes.arrayOf( - PropTypes.shape({ - name: PropTypes.string.isRequired, - }) - ).isRequired, + options: PropTypes.array.isRequired, + filteredBy: PropTypes.string.isRequired, value: PropTypes.string.isRequired, handleChange: PropTypes.func.isRequired, sx: PropTypes.object, diff --git a/Client/src/Components/Search/index.css b/Client/src/Components/Search/index.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/Client/src/Components/Search/index.jsx b/Client/src/Components/Search/index.jsx deleted file mode 100644 index 391b95c02..000000000 --- a/Client/src/Components/Search/index.jsx +++ /dev/null @@ -1,49 +0,0 @@ -import Autocomplete from '@mui/material/Autocomplete'; -import TextField from '@mui/material/TextField'; -import Chip from '@mui/material/Chip'; -import Box from '@mui/material/Box'; -import { useTheme } from "@mui/material"; - -const teamMembers = [ - { title: 'John Doe'}, - { title: 'Jane Smith'}, - { title: 'Alex Johnson'}, -]; - -/** - * @component - * @returns {JSX.Element} - */ - -export default function Search() - { - const theme = useTheme(); - return ( - {/* Add padding to the container */} - option.title} - filterSelectedOptions - renderInput={(params) => ( - - )} - renderTags={(value, getTagProps) => - value.map((option) => ( - - )) - } - /> - - ); -} diff --git a/Client/src/Pages/Monitors/Home/index.jsx b/Client/src/Pages/Monitors/Home/index.jsx index 36921d1f5..d51c3de2a 100644 --- a/Client/src/Pages/Monitors/Home/index.jsx +++ b/Client/src/Pages/Monitors/Home/index.jsx @@ -120,6 +120,7 @@ const Monitors = ({ isAdmin }) => { From 07190f82d5ccacf66a4db49ee6004ebdf36f1e22 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 19 Sep 2024 11:07:38 +0800 Subject: [PATCH 82/82] Connect search component to monitor table --- Client/src/Components/Inputs/Search/index.jsx | 20 +++++++++++++++---- .../Monitors/Home/MonitorTable/index.jsx | 7 ++++--- Client/src/Pages/Monitors/Home/index.jsx | 6 ++++-- Client/src/Utils/debounce.jsx | 18 +++++++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 Client/src/Utils/debounce.jsx diff --git a/Client/src/Components/Inputs/Search/index.jsx b/Client/src/Components/Inputs/Search/index.jsx index b69b25731..f4d931fd1 100644 --- a/Client/src/Components/Inputs/Search/index.jsx +++ b/Client/src/Components/Inputs/Search/index.jsx @@ -15,15 +15,26 @@ import SearchIcon from "../../../assets/icons/search.svg?react"; * @param {Object} props.sx - Additional styles to apply to the component * @returns {JSX.Element} The rendered Search component */ -const Search = ({ id, options, filteredBy, value, handleChange, sx }) => { +const Search = ({ + id, + options, + filteredBy, + value, + handleInputChange, + handleChange, + sx, +}) => { const theme = useTheme(); return ( { - handleChange(newValue); + onInputChange={(_, newValue) => { + handleInputChange(newValue); + }} + onChange={(_, newValue) => { + handleChange && handleChange(newValue); }} fullWidth freeSolo @@ -131,7 +142,8 @@ Search.propTypes = { options: PropTypes.array.isRequired, filteredBy: PropTypes.string.isRequired, value: PropTypes.string.isRequired, - handleChange: PropTypes.func.isRequired, + handleInputChange: PropTypes.func.isRequired, + handleChange: PropTypes.func, sx: PropTypes.object, }; diff --git a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx index 732351be0..b7e50a499 100644 --- a/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx +++ b/Client/src/Pages/Monitors/Home/MonitorTable/index.jsx @@ -108,7 +108,7 @@ TablePaginationActions.propTypes = { onPageChange: PropTypes.func.isRequired, }; -const MonitorTable = ({ isAdmin }) => { +const MonitorTable = ({ isAdmin, filter }) => { const theme = useTheme(); const navigate = useNavigate(); const dispatch = useDispatch(); @@ -155,7 +155,7 @@ const MonitorTable = ({ isAdmin }) => { normalize: true, page: page, rowsPerPage: rowsPerPage, - filter: null, + filter: filter, field: sort.field, order: sort.order, }); @@ -166,7 +166,7 @@ const MonitorTable = ({ isAdmin }) => { } }; fetchPage(); - }, [updateTrigger, authState, page, rowsPerPage]); + }, [updateTrigger, authState, page, rowsPerPage, filter, sort]); /** * Helper function to calculate the range of displayed rows. @@ -406,6 +406,7 @@ const MonitorTable = ({ isAdmin }) => { MonitorTable.propTypes = { isAdmin: PropTypes.bool, + filter: PropTypes.string, }; const MemoizedMonitorTable = memo(MonitorTable); diff --git a/Client/src/Pages/Monitors/Home/index.jsx b/Client/src/Pages/Monitors/Home/index.jsx index d51c3de2a..9db0cbf9a 100644 --- a/Client/src/Pages/Monitors/Home/index.jsx +++ b/Client/src/Pages/Monitors/Home/index.jsx @@ -13,6 +13,7 @@ import Breadcrumbs from "../../../Components/Breadcrumbs"; import Greeting from "../../../Utils/greeting"; import MonitorTable from "./MonitorTable"; import Search from "../../../Components/Inputs/Search"; +import useDebounce from "../../../Utils/debounce"; const Monitors = ({ isAdmin }) => { const theme = useTheme(); @@ -21,6 +22,7 @@ const Monitors = ({ isAdmin }) => { const authState = useSelector((state) => state.auth); const [search, setSearch] = useState(""); const dispatch = useDispatch({}); + const debouncedFilter = useDebounce(search, 500); useEffect(() => { dispatch(getUptimeMonitorsByTeamId(authState.authToken)); @@ -122,11 +124,11 @@ const Monitors = ({ isAdmin }) => { options={monitorState?.monitorsSummary.monitors} filteredBy="name" value={search} - handleChange={setSearch} + handleInputChange={setSearch} /> - + )} diff --git a/Client/src/Utils/debounce.jsx b/Client/src/Utils/debounce.jsx new file mode 100644 index 000000000..a89f8c687 --- /dev/null +++ b/Client/src/Utils/debounce.jsx @@ -0,0 +1,18 @@ +import { useState, useEffect } from "react"; + +const useDebounce = (value, delay) => { + const [debouncedValue, setDebouncedValue] = useState(value); + + useEffect(() => { + const handler = setTimeout(() => { + setDebouncedValue(value); + }, delay); + + return () => { + clearTimeout(handler); + }; + }, [value, delay]); + return debouncedValue; +}; + +export default useDebounce;