Skip to content

Commit

Permalink
Added basic operational status component and story.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikuPAN committed Jul 5, 2024
1 parent 67a81f1 commit 1f8980b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/components/OperationalStatus/OperationalStatus.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Meta, StoryFn } from "@storybook/react";
import { OperationalStatus, OperationalStatusData } from "./OperationalStatus";
import jsonData from "../../../public/status.json";

const typedJsonData: OperationalStatusData["data"] =
jsonData as OperationalStatusData["data"];

export default {
title: "Component/OperationalStatus",
component: OperationalStatus,
} as Meta<typeof OperationalStatus>;

const Template: StoryFn<typeof OperationalStatus> = (args) => (
<OperationalStatus {...args} />
);

export const Default = Template.bind({});
Default.args = {
data: typedJsonData,
};

export const NoDataAvailable = Template.bind({});
NoDataAvailable.args = {
data: undefined,
};
74 changes: 74 additions & 0 deletions src/components/OperationalStatus/OperationalStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { FunctionComponent } from "react";
import {
Text,
Box,
Table,
Thead,
Tbody,
Tr,
Th,
Td,
TableContainer,
Tag,
TagLabel,
} from "@chakra-ui/react";

interface Service {
name: string;
status: string;
error?: string;
}

interface Data extends Service {
last_updated?: string;
services: Service[];
}

export interface OperationalStatusData extends Data {
data?: Data;
}

export const OperationalStatus: FunctionComponent<OperationalStatusData> = ({
data,
}) => {
return (
<Box>
<Text as="b" fontSize="3xl">
Operational status
</Text>
{data && data?.services.length > 0 ? (
<TableContainer>
<Table variant="simple">
<Thead>
<Tr>
<Th>SERVICE</Th>
<Th isNumeric>STATUS</Th>
</Tr>
</Thead>
<Tbody>
{data?.services.map((service: any) => (
<Tr key={service?.name}>
<Td>{service?.name}</Td>
<Td isNumeric>
<Tag
variant="subtle"
colorScheme={service?.status === "OK" ? "green" : "red"}
>
<TagLabel>
{service?.status === "OK" ? "Operational" : "Disrupted"}
</TagLabel>
</Tag>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
) : (
<Text>No Data available.</Text>
)}
</Box>
);
};

export default OperationalStatus;
4 changes: 4 additions & 0 deletions src/components/OperationalStatus/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
OperationalStatus,
type OperationalStatusData,
} from "./OperationalStatus";

0 comments on commit 1f8980b

Please sign in to comment.