Compare commits

...
Author SHA1 Message Date
gorkem-bwl 35ee4d3bcb revert: Remove PageSpeed stats fix (already fixed on develop)
The PageSpeed stats fix has been implemented differently on develop branch
by Alex Holliday in commit 6447c315c. Reverting this change to avoid
conflicts and keep the incidents fixes.
2026-01-16 21:53:48 -05:00
gorkem-bwl 162b081858 Fix formatting 2026-01-16 15:26:34 -05:00
gorkem-bwl 6c0aea46a7 Fix PageSpeed stats and incidents page issues
## Changes
- Fix PageSpeed "checks since" and "last check" always showing "0s ago"
  by calculating durations from the checks array timestamps
- Fix incidents "Avg. Resolution Time" displaying decimal hours (e.g., "0.86 hours")
  by adding formatResolutionTime() to show proper format (e.g., "52m" or "2h 15m")
- Fix incidents monitor filter dropdown not working when selecting a specific monitor
  by resolving race condition between page reset and data fetch
2026-01-16 15:25:05 -05:00
3 changed files with 51 additions and 10 deletions

No files matched your search

@@ -26,6 +26,18 @@ import SummaryCard from "../SummaryCard/index.jsx";
* @param {boolean} props.isLoading - Loading state * @param {boolean} props.isLoading - Loading state
* @param {Object} props.error - Error object if any * @param {Object} props.error - Error object if any
*/ */
const formatResolutionTime = (hours) => {
if (!hours || hours === 0) return "0m";
const totalMinutes = Math.round(hours * 60);
const h = Math.floor(totalMinutes / 60);
const m = totalMinutes % 60;
if (h === 0) return `${m}m`;
if (m === 0) return `${h}h`;
return `${h}h ${m}m`;
};
const StatisticsPanel = ({ isLoading = false, error = null, summary = {} }) => { const StatisticsPanel = ({ isLoading = false, error = null, summary = {} }) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -150,7 +162,7 @@ const StatisticsPanel = ({ isLoading = false, error = null, summary = {} }) => {
> >
{t("incidentsPage.avgResolutionTime")}:{" "} {t("incidentsPage.avgResolutionTime")}:{" "}
{summary.total > 0 {summary.total > 0
? `${summary.avgResolutionTimeHours || 0} ${t("incidentsPage.hours")}` ? formatResolutionTime(summary.avgResolutionTimeHours)
: "N/A"} : "N/A"}
</Typography> </Typography>
</Stack> </Stack>
+22 -5
View File
@@ -8,7 +8,7 @@ import IncidentsSummaryPanel from "./Components/IncidentsSummaryPanel/index.jsx"
//Utils //Utils
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useState, useEffect } from "react"; import { useState, useEffect, useRef } from "react";
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx"; import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -53,16 +53,33 @@ const Incidents2 = () => {
const theme = useTheme(); const theme = useTheme();
useEffect(() => { // Track previous filter values to detect changes and reset page
setPage(0); const prevFiltersRef = useRef({ selectedMonitor, filter, dateRange });
}, [selectedMonitor, filter, dateRange]);
useEffect(() => { useEffect(() => {
const prevFilters = prevFiltersRef.current;
const filtersChanged =
prevFilters.selectedMonitor !== selectedMonitor ||
prevFilters.filter !== filter ||
prevFilters.dateRange !== dateRange;
// Determine the effective page - reset to 0 if filters changed
const effectivePage = filtersChanged ? 0 : page;
// Update the ref for next comparison
if (filtersChanged) {
prevFiltersRef.current = { selectedMonitor, filter, dateRange };
// Also update the page state (for pagination component)
if (page !== 0) {
setPage(0);
}
}
const config = { const config = {
monitorId: selectedMonitor !== "0" ? selectedMonitor : undefined, monitorId: selectedMonitor !== "0" ? selectedMonitor : undefined,
sortOrder: "desc", sortOrder: "desc",
dateRange, dateRange,
page, page: effectivePage,
rowsPerPage, rowsPerPage,
}; };
@@ -4,9 +4,21 @@ import { Typography } from "@mui/material";
import { getHumanReadableDuration } from "../../../../../Utils/timeUtils.js"; import { getHumanReadableDuration } from "../../../../../Utils/timeUtils.js";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => { const PageSpeedStatusBoxes = ({ shouldRender, monitorStats }) => {
const uptimeDuration = getHumanReadableDuration(monitor?.uptimeDuration); const lastChecked = monitorStats?.lastCheckTimestamp
const time = getHumanReadableDuration(monitor?.lastChecked); ? Date.now() - monitorStats.lastCheckTimestamp
: 0;
// Determine time since last failure
const timeOfLastFailure = monitorStats?.timeOfLastFailure;
const timeSinceLastFailure =
timeOfLastFailure > 0
? Date.now() - timeOfLastFailure
: Date.now() - new Date(monitorStats?.createdAt);
const streakTime = getHumanReadableDuration(timeSinceLastFailure);
const time = getHumanReadableDuration(lastChecked);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -16,7 +28,7 @@ const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => {
heading="checks since" heading="checks since"
subHeading={ subHeading={
<> <>
{uptimeDuration} {streakTime}
<Typography component="span">{t("ago")}</Typography> <Typography component="span">{t("ago")}</Typography>
</> </>
} }