2026-01-23 12:33:40 -08:00
|
|
|
import { useGet } from "@/Hooks/UseApi";
|
2026-01-23 19:58:37 +00:00
|
|
|
import { MonitorBasePageWithStates } from "@/Components/v2/design-elements";
|
2026-01-23 21:30:34 +00:00
|
|
|
import type { Monitor, MonitorType, MonitorsWithChecksResponse } from "@/Types/Monitor";
|
2026-01-23 12:33:40 -08:00
|
|
|
import { FilterControls } from "@/Components/v2/monitors";
|
2026-01-23 21:30:34 +00:00
|
|
|
import { useState, useMemo } from "react";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import type { RootState } from "@/Types/state";
|
2026-01-23 19:58:37 +00:00
|
|
|
|
|
|
|
|
const UptimeMonitorsPage = () => {
|
2026-01-23 21:30:34 +00:00
|
|
|
// Redux state
|
|
|
|
|
const rowsPerPage = useSelector((state: RootState) => state.ui.monitors.rowsPerPage);
|
|
|
|
|
|
|
|
|
|
// Local state
|
|
|
|
|
const [selectedTypes, setSelectedTypes] = useState<MonitorType[]>([]);
|
|
|
|
|
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
|
|
|
|
const [selectedState, setSelectedState] = useState<string>("");
|
|
|
|
|
const [page, setPage] = useState(0);
|
|
|
|
|
const [search, setSearch] = useState("");
|
|
|
|
|
const [sort, setSort] = useState<
|
|
|
|
|
{ field: string; order: "asc" | "desc" } | undefined
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
// Build URL for monitors with checks
|
|
|
|
|
const monitorsWithChecksUrl = useMemo(() => {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
const types =
|
|
|
|
|
selectedTypes.length > 0 ? selectedTypes : ["http", "ping", "docker", "port"];
|
|
|
|
|
types.forEach((type) => params.append("type", type));
|
|
|
|
|
params.append("limit", "25");
|
|
|
|
|
if (page) params.append("page", String(page));
|
|
|
|
|
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
|
|
|
|
if (search) params.append("filter", search);
|
|
|
|
|
if (sort?.field) params.append("field", sort.field);
|
|
|
|
|
if (sort?.order) params.append("order", sort.order);
|
|
|
|
|
return `/monitors/team/with-checks?${params.toString()}`;
|
|
|
|
|
}, [selectedTypes, page, rowsPerPage, search, sort]);
|
|
|
|
|
|
|
|
|
|
// Data fetching
|
2026-01-23 12:33:40 -08:00
|
|
|
const {
|
|
|
|
|
data: monitors,
|
|
|
|
|
isLoading,
|
|
|
|
|
error,
|
|
|
|
|
} = useGet<Monitor[]>("/monitors/team?type=http&type=ping&type=port&type=docker");
|
|
|
|
|
|
2026-01-23 21:30:34 +00:00
|
|
|
const {
|
|
|
|
|
data: monitorsWithChecksData,
|
|
|
|
|
isLoading: monitorsWithChecksLoading,
|
|
|
|
|
error: monitorsWithChecksError,
|
|
|
|
|
} = useGet<MonitorsWithChecksResponse>(monitorsWithChecksUrl);
|
|
|
|
|
|
|
|
|
|
const { monitors: monitorsWithChecks, summary, count } = monitorsWithChecksData ?? {};
|
|
|
|
|
|
2026-01-23 19:58:37 +00:00
|
|
|
return (
|
|
|
|
|
<MonitorBasePageWithStates
|
2026-01-23 21:30:34 +00:00
|
|
|
loading={isLoading || monitorsWithChecksLoading}
|
|
|
|
|
error={error || monitorsWithChecksError}
|
2026-01-23 12:33:40 -08:00
|
|
|
items={monitors || []}
|
2026-01-23 19:58:37 +00:00
|
|
|
page="uptime"
|
|
|
|
|
actionLink="/uptime/create"
|
|
|
|
|
>
|
2026-01-23 21:30:34 +00:00
|
|
|
<FilterControls
|
|
|
|
|
selectedTypes={selectedTypes}
|
|
|
|
|
setSelectedTypes={setSelectedTypes}
|
|
|
|
|
selectedStatus={selectedStatus}
|
|
|
|
|
setSelectedStatus={setSelectedStatus}
|
|
|
|
|
selectedState={selectedState}
|
|
|
|
|
setSelectedState={setSelectedState}
|
|
|
|
|
/>
|
2026-01-23 12:33:40 -08:00
|
|
|
<pre>{JSON.stringify(monitors, null, 2)}</pre>
|
2026-01-23 19:58:37 +00:00
|
|
|
</MonitorBasePageWithStates>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default UptimeMonitorsPage;
|