From 6063532c794d07be096d83c1446bea29a1237676 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 2 Feb 2026 17:49:36 +0000 Subject: [PATCH] fitlers --- .../Components/ControlsIncidentFilter.tsx | 81 +++++++++++++++++++ .../Incidents/Components/IncidentTable.tsx | 2 +- client/src/Pages/Incidents/index.tsx | 54 ++++++------- client/src/locales/en.json | 10 +++ 4 files changed, 117 insertions(+), 30 deletions(-) diff --git a/client/src/Pages/Incidents/Components/ControlsIncidentFilter.tsx b/client/src/Pages/Incidents/Components/ControlsIncidentFilter.tsx index e69de29bb..09cc1237f 100644 --- a/client/src/Pages/Incidents/Components/ControlsIncidentFilter.tsx +++ b/client/src/Pages/Incidents/Components/ControlsIncidentFilter.tsx @@ -0,0 +1,81 @@ +import Stack from "@mui/material/Stack"; +import { Select, Button } from "@/Components/v2/inputs"; +import MenuItem from "@mui/material/MenuItem"; +import useMediaQuery from "@mui/material/useMediaQuery"; +import { Typography, useTheme } from "@mui/material"; +import { useTranslation } from "react-i18next"; +import type { Monitor } from "@/Types/Monitor"; + +const resolutionTypes = ["manual", "automatic"]; + +interface ControlsIncidentFilterProps { + monitors?: Monitor[]; + selectedMonitor: string; + setSelectedMonitor: React.Dispatch>; + selectedResolutionType: string; + setSelectedResolutionType: React.Dispatch>; + onClearFilters: () => void; +} + +export const ControlsIncidentFilter = ({ + monitors, + selectedMonitor, + setSelectedMonitor, + selectedResolutionType, + setSelectedResolutionType, + onClearFilters, +}: ControlsIncidentFilterProps) => { + const { t } = useTranslation(); + const theme = useTheme(); + const isSmall = useMediaQuery(theme.breakpoints.down("md")); + const isFilterActive = selectedMonitor !== "0" || selectedResolutionType !== ""; + + return ( + + + + {isFilterActive && ( + + )} + + ); +}; diff --git a/client/src/Pages/Incidents/Components/IncidentTable.tsx b/client/src/Pages/Incidents/Components/IncidentTable.tsx index 46352c6f7..b500ed5ba 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable.tsx +++ b/client/src/Pages/Incidents/Components/IncidentTable.tsx @@ -18,6 +18,7 @@ import { useTheme } from "@mui/material/styles"; import Box from "@mui/material/Box"; interface IncidentsTableProps { + title?: string; incidents?: Incident[]; monitors?: Monitor[]; incidentsCount: number; @@ -30,7 +31,6 @@ interface IncidentsTableProps { } export const IncidentsTable = ({ - title, incidents, monitors, incidentsCount, diff --git a/client/src/Pages/Incidents/index.tsx b/client/src/Pages/Incidents/index.tsx index 7bc0e8fa5..56595afdb 100644 --- a/client/src/Pages/Incidents/index.tsx +++ b/client/src/Pages/Incidents/index.tsx @@ -12,6 +12,7 @@ import { IncidentsTable } from "@/Pages/Incidents/Components/IncidentTable"; import { DialogResolution } from "@/Pages/Incidents/Components/DialogResolution"; import { DialogIncidentDetails } from "@/Pages/Incidents/Components/DialogIncidentDetails"; import { HeaderTimeRange } from "@/Components/v2/common"; +import { ControlsIncidentFilter } from "@/Pages/Incidents/Components/ControlsIncidentFilter"; import { useGet } from "@/Hooks/UseApi"; import { useState, useEffect, useMemo } from "react"; @@ -64,7 +65,6 @@ const IncidentsPage = () => { const { data: incidentsData, isLoading: isLoadingIncidents, - error: incidentsError, refetch: refetchIncidents, } = useGet( incidentsUrl, @@ -73,11 +73,7 @@ const IncidentsPage = () => { ); // Fetch monitors for lookup - const { - data: monitorsData, - isLoading: isLoadingMonitors, - error: monitorsError, - } = useGet("/monitors/team"); + const { data: monitorsData } = useGet("/monitors/team"); // Build active incidents URL (always fetch all active, no date filter) const activeIncidentsUrl = useMemo(() => { @@ -99,12 +95,9 @@ const IncidentsPage = () => { ); // Fetch incident summary - const { - data: summaryData, - isLoading: isLoadingSummary, - error: summaryError, - refetch: refetchSummary, - } = useGet("/incidents/team/summary"); + const { data: summaryData, refetch: refetchSummary } = useGet( + "/incidents/team/summary" + ); // Reset page when filters change useEffect(() => { @@ -116,17 +109,11 @@ const IncidentsPage = () => { const incidentsCount = incidentsData?.count ?? 0; const activeIncidents = activeIncidentsData?.incidents ?? []; const activeIncidentsCount = activeIncidentsData?.count ?? 0; - const networkError = !!incidentsError || !!monitorsError || !!summaryError; - // Expose state and handlers for future UI use - void selectedMonitor; - void setSelectedMonitor; - void filter; - void setFilter; - void isLoadingIncidents; - void isLoadingMonitors; - void isLoadingSummary; - void networkError; + const handleClearFilters = () => { + setSelectedMonitor("0"); + setFilter("all"); + }; const handleOpenDetails = (incidentId: string) => { const incident = @@ -176,15 +163,23 @@ const IncidentsPage = () => { - - {t("pages.incidents.table.activeIncidents")} - - + {activeIncidentsCount > 0 && ( <> + + {t("pages.incidents.table.activeIncidents")} + + { > {t("pages.incidents.table.resolvedIncidents")} +