diff --git a/src/features/dashboard/components/CameraStatus.tsx b/src/features/dashboard/components/CameraStatus.tsx index 9c28274..18ecac7 100644 --- a/src/features/dashboard/components/CameraStatus.tsx +++ b/src/features/dashboard/components/CameraStatus.tsx @@ -1,17 +1,35 @@ +import type { SystemHealthStatus } from "../../../types/types"; import Card from "../../../ui/Card"; -import CardHeader from "../../../ui/CardHeader"; +import StatusIndicators from "../../../ui/StatusIndicators"; +import { capitalize } from "../../../utils/utils"; +import CameraStatusGridItem from "./CameraStatusGridItem"; type CameraStatusProps = { title: string; - status?: string; - description: string; + category: SystemHealthStatus[]; }; -const CameraStatus = ({ title, status, description }: CameraStatusProps) => { +const CameraStatus = ({ title, category }: CameraStatusProps) => { + const isAllGood = category?.every((status) => status.tags.includes("RUNNING")); + // check if some are down + // check if all are down + //check if offline return ( - -

{description}

+
+

+ {isAllGood ? : } + {capitalize(title)} +

+

{isAllGood ? "All systems running" : "Some systems down"}

+
+ {category && category?.length <= 0 ? ( +

Loading Camera health...

+ ) : ( +
+ +
+ )}
); }; diff --git a/src/features/dashboard/components/CameraStatusGridItem.tsx b/src/features/dashboard/components/CameraStatusGridItem.tsx new file mode 100644 index 0000000..8217dc8 --- /dev/null +++ b/src/features/dashboard/components/CameraStatusGridItem.tsx @@ -0,0 +1,38 @@ +import { useState } from "react"; +import type { SystemHealthStatus } from "../../../types/types"; +import { capitalize } from "../../../utils/utils"; +import SystemHealthModal from "./systemHealthModal/SystemHealthModal"; + +type CameraStatusGridItemProps = { + title: string; + statusCategory: SystemHealthStatus[]; +}; + +const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemProps) => { + const [isOpen, setIsOpen] = useState(false); + const isAllGood = statusCategory?.every((status) => status.tags.includes("RUNNING")); + + const handleClick = () => { + setIsOpen(false); + }; + return ( + <> +
setIsOpen(true)} + > +

{capitalize(title)}

+

{isAllGood ? "Click to view module status" : "Some systems down"}

+
+ + + ); +}; + +export default CameraStatusGridItem; diff --git a/src/features/dashboard/components/DashboardGrid.tsx b/src/features/dashboard/components/DashboardGrid.tsx index b430106..1d75e5b 100644 --- a/src/features/dashboard/components/DashboardGrid.tsx +++ b/src/features/dashboard/components/DashboardGrid.tsx @@ -1,16 +1,55 @@ +import type { SystemHealthStatus } from "../../../types/types"; +import { useGetSystemHealth } from "../hooks/useGetSystemHealth"; import CameraStatus from "./CameraStatus"; import SystemOverview from "./SystemOverview"; import SystemStatusCard from "./SystemStatusCard"; const DashboardGrid = () => { + const { query } = useGetSystemHealth(); + const startTime = query?.data?.StartTimeHumane; + const uptime = query?.data?.UptimeHumane; + const statuses: SystemHealthStatus[] = query?.data?.Status; + const isLoading = query?.isLoading; + const isError = query?.isError; + const dateUpdatedAt = query?.dataUpdatedAt; + const refetch = query?.refetch; + + const statusCategories = statuses?.reduce>( + (acc, cur) => { + if (cur?.groupID === "ChannelA") acc?.channelA?.push(cur); + if (cur?.groupID === "ChannelB") acc?.channelB?.push(cur); + if (cur?.groupID === "ChannelC") acc?.channelC?.push(cur); + if (cur?.groupID === "Default") acc?.default?.push(cur); + return acc; + }, + { + channelA: [], + channelB: [], + channelC: [], + default: [], + }, + ); + + const categoryA = statusCategories?.channelA ?? []; + const categoryB = statusCategories?.channelB ?? []; + const categoryC = statusCategories?.channelC ?? []; + return (
- +
- - - + + +
); diff --git a/src/features/dashboard/components/SystemHealth.tsx b/src/features/dashboard/components/SystemHealth.tsx index 4055e7a..1471947 100644 --- a/src/features/dashboard/components/SystemHealth.tsx +++ b/src/features/dashboard/components/SystemHealth.tsx @@ -29,12 +29,7 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd }, ); - const convertObjtoArray = (obj: Record) => { - if (!obj) return; - const statusCategoryArray = Object.entries(obj); - return statusCategoryArray; - }; - const statusCategoryArray = convertObjtoArray(statusCategories); + const categoryDefault = statusCategories?.default ?? []; if (isError) { return Error loading system health.; @@ -52,10 +47,8 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd

Up Time

{uptime} -
- {statusCategoryArray?.map((status) => ( - - ))} +
+
{`Last refeshed ${updatedDate}`} diff --git a/src/features/dashboard/components/SystemOverview.tsx b/src/features/dashboard/components/SystemOverview.tsx index b440e22..418070e 100644 --- a/src/features/dashboard/components/SystemOverview.tsx +++ b/src/features/dashboard/components/SystemOverview.tsx @@ -1,22 +1,32 @@ import { faArrowsRotate } from "@fortawesome/free-solid-svg-icons"; import Card from "../../../ui/Card"; import CardHeader from "../../../ui/CardHeader"; -import { useGetSystemHealth } from "../hooks/useGetSystemHealth"; + import SystemHealth from "./SystemHealth"; +import type { SystemHealthStatus } from "../../../types/types"; -const SystemOverview = () => { - const { query } = useGetSystemHealth(); - - const startTime = query?.data?.StartTimeHumane; - const uptime = query?.data?.UptimeHumane; - const statuses = query?.data?.Status; - const isLoading = query?.isLoading; - const isError = query?.isError; - const dateUpdatedAt = query?.dataUpdatedAt; +type SystemOverviewProps = { + startTime: string; + uptime: string; + statuses: SystemHealthStatus[]; + isLoading: boolean; + isError: boolean; + dateUpdatedAt: number; + refetch: () => void; +}; +const SystemOverview = ({ + startTime, + uptime, + statuses, + isLoading, + isError, + dateUpdatedAt, + refetch, +}: SystemOverviewProps) => { return ( - + ) => { + if (!obj) return; + const statusCategoryArray = Object.entries(obj); + return statusCategoryArray; +};