- added status grid items
- add react modal pkg
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { SystemHealthStatus } from "../../../types/types";
|
||||
import Badge from "../../../ui/Badge";
|
||||
import StatusGridItem from "./statusGridItem/StatusGridItem";
|
||||
|
||||
type SystemHealthProps = {
|
||||
startTime: string;
|
||||
@@ -13,7 +13,28 @@ type SystemHealthProps = {
|
||||
const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpdatedAt }: SystemHealthProps) => {
|
||||
const updatedDate = dateUpdatedAt ? new Date(dateUpdatedAt).toLocaleString() : null;
|
||||
|
||||
// console.log(statuses);
|
||||
const statusCategories = statuses?.reduce<Record<string, SystemHealthStatus[]>>(
|
||||
(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 convertObjtoArray = (obj: Record<string, SystemHealthStatus[]>) => {
|
||||
if (!obj) return;
|
||||
const statusCategoryArray = Object.entries(obj);
|
||||
return statusCategoryArray;
|
||||
};
|
||||
const statusCategoryArray = convertObjtoArray(statusCategories);
|
||||
|
||||
if (isError) {
|
||||
return <span className="text-red-500">Error loading system health.</span>;
|
||||
@@ -31,11 +52,9 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd
|
||||
<h3 className="text-lg">Up Time</h3> <span className="text-slate-300">{uptime}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="h-50 overflow-auto">
|
||||
{statuses?.map((status: SystemHealthStatus) => (
|
||||
<div className="border border-gray-700 p-4 rounded-md m-2 flex justify-between" key={status.id}>
|
||||
<span>{status.id}</span> <Badge text={status.tags[0]} />
|
||||
</div>
|
||||
<div className="h-50 overflow-auto grid grid-cols-2 gap-4">
|
||||
{statusCategoryArray?.map((status) => (
|
||||
<StatusGridItem title={status[0]} statusCategory={status[1]} />
|
||||
))}
|
||||
</div>
|
||||
<div className="border-t border-gray-500">
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { useState } from "react";
|
||||
import type { SystemHealthStatus } from "../../../../types/types";
|
||||
import StatusIndicators from "../../../../ui/StatusIndicators";
|
||||
import { capitalize } from "../../../../utils/utils";
|
||||
import SystemHealthModal from "../systemHealthModal/SystemHealthModal";
|
||||
|
||||
type StatusGridItemProps = {
|
||||
title: string;
|
||||
statusCategory: SystemHealthStatus[];
|
||||
};
|
||||
|
||||
const StatusGridItem = ({ title, statusCategory }: StatusGridItemProps) => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const isAllGood = statusCategory.every((status) => status.tags.includes("RUNNING"));
|
||||
|
||||
const handleClick = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241] hover:cursor-pointer"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<h3 className="text-lg flex flex-row items-center">
|
||||
{isAllGood ? <StatusIndicators status={"bg-green-500"} /> : <StatusIndicators status={"bg-amber-500"} />}
|
||||
{capitalize(title)}
|
||||
</h3>
|
||||
<p className="text-sm text-slate-300">{isAllGood ? "All systems running" : "Some systems down"}</p>
|
||||
</div>
|
||||
<SystemHealthModal
|
||||
isSystemHealthModalOpen={isOpen}
|
||||
handleClose={handleClick}
|
||||
statusCategory={statusCategory}
|
||||
title={title}
|
||||
isAllGood={isAllGood}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatusGridItem;
|
||||
@@ -0,0 +1,48 @@
|
||||
import type { SystemHealthStatus } from "../../../../types/types";
|
||||
import Badge from "../../../../ui/Badge";
|
||||
import ModalComponent from "../../../../ui/ModalComponent";
|
||||
import StatusIndicators from "../../../../ui/StatusIndicators";
|
||||
import { capitalize } from "../../../../utils/utils";
|
||||
|
||||
type SystemHealthModalProps = {
|
||||
isSystemHealthModalOpen: boolean;
|
||||
handleClose: () => void;
|
||||
statusCategory: SystemHealthStatus[];
|
||||
title: string;
|
||||
isAllGood: boolean;
|
||||
};
|
||||
|
||||
const SystemHealthModal = ({
|
||||
isSystemHealthModalOpen,
|
||||
handleClose,
|
||||
statusCategory,
|
||||
title,
|
||||
isAllGood,
|
||||
}: SystemHealthModalProps) => {
|
||||
return (
|
||||
<ModalComponent isModalOpen={isSystemHealthModalOpen} close={handleClose}>
|
||||
<div>
|
||||
<div className="border-b border-gray-500">
|
||||
<h2 className="text-xl font-bold mb-4 flex flex-row items-center">
|
||||
{isAllGood ? <StatusIndicators status={"bg-green-500"} /> : <StatusIndicators status={"bg-amber-500"} />}
|
||||
{capitalize(title)}
|
||||
</h2>
|
||||
<p className="text-sm text-slate-300">{isAllGood ? "All systems running" : "Some systems down"}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{statusCategory?.map((status: SystemHealthStatus) => (
|
||||
<div
|
||||
className="border border-gray-700 p-4 rounded-md m-2 flex justify-between hover:bg-[#233241]"
|
||||
key={status.id}
|
||||
>
|
||||
<span>{status.id}</span> <Badge text={status.tags[0]} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</ModalComponent>
|
||||
);
|
||||
};
|
||||
|
||||
export default SystemHealthModal;
|
||||
Reference in New Issue
Block a user