forked from bderenzo/tinystatus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic operational status component and story.
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/components/OperationalStatus/OperationalStatus.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
OperationalStatus, | ||
type OperationalStatusData, | ||
} from "./OperationalStatus"; |