moonstream/frontend/src/components/SubscriptionReport.js

174 wiersze
4.5 KiB
JavaScript
Czysty Zwykły widok Historia

2021-11-11 20:27:41 +00:00
import React from "react";
import { usePresignedURL } from "../core/hooks";
import Report from "./Report";
2021-11-15 18:56:12 +00:00
import { Spinner, Flex, Heading, Text, Stack } from "@chakra-ui/react";
2021-11-11 20:27:41 +00:00
import { v4 } from "uuid";
const HOUR_KEY = "Hourly";
const DAY_KEY = "Daily";
const WEEK_KEY = "Weekly";
let timeMap = {};
timeMap[HOUR_KEY] = "hour";
timeMap[DAY_KEY] = "day";
timeMap[WEEK_KEY] = "week";
2021-11-12 10:21:53 +00:00
const SubscriptionReport = ({ url, id, type }) => {
2021-11-11 20:27:41 +00:00
const { data, isLoading } = usePresignedURL({
url: url,
isEnabled: true,
id: id,
type: type,
});
const plotMinW = "500px";
if (!data || isLoading) return <Spinner />;
return (
<Flex w="100%" h="auto" flexGrow={1} flexBasis="420px" direction="column">
2021-11-15 18:56:12 +00:00
<Stack
bgColor="blue.50"
direction={["column", "row", null]}
spacing={4}
flexGrow={1}
>
{data?.web3_metric.map((metric) => {
return (
<Flex
flexGrow={1}
flexBasis="75px"
placeSelf="center"
p={2}
bgColor="blue.100"
m={4}
key={v4()}
size="sm"
fontWeight="600"
boxShadow="sm"
w="75px"
maxH="150px"
direction="column"
>
<Text placeSelf="center">{metric.display_name}</Text>
<Text p={2} fontSize="42px" placeSelf="center">
{metric.value}
</Text>
</Flex>
);
})}
</Stack>
2021-11-14 14:29:51 +00:00
{data?.events && Object.keys(data?.events) && (
2021-11-11 20:27:41 +00:00
<Flex
w="100%"
h="auto"
flexGrow={1}
flexBasis="420px"
direction="column"
>
<Heading size="sm">Events</Heading>
2021-11-14 14:29:51 +00:00
{Object.keys(data.events).map((key) => {
2021-11-11 20:27:41 +00:00
return (
<Flex
key={v4()}
flexBasis={plotMinW}
flexGrow={1}
minW={plotMinW}
minH="320px"
maxH="420px"
direction="column"
boxShadow="md"
m={2}
>
<Text
w="100%"
py={2}
bgColor="gray.50"
fontWeight="600"
textAlign="center"
>
{key}
</Text>
2021-11-14 17:12:13 +00:00
<Report data={data.events[key]} metric={key} />
2021-11-11 20:27:41 +00:00
</Flex>
);
})}
</Flex>
)}
2021-11-14 14:29:51 +00:00
{data?.functions && Object.keys(data?.functions) && (
2021-11-11 20:27:41 +00:00
<Flex
w="100%"
h="auto"
flexGrow={1}
flexBasis="420px"
direction="column"
>
2021-11-14 14:29:51 +00:00
<Heading size="sm">functions</Heading>
{Object.keys(data.functions).map((key) => {
2021-11-11 20:27:41 +00:00
return (
<Flex
key={v4()}
flexBasis={plotMinW}
flexGrow={1}
minW={plotMinW}
minH="320px"
maxH="420px"
direction="column"
boxShadow="md"
m={2}
>
<Text
w="100%"
py={2}
bgColor="gray.50"
fontWeight="600"
textAlign="center"
>
{key}
</Text>
2021-11-14 17:12:13 +00:00
<Report data={data.functions[key]} metric={key} />
2021-11-11 20:27:41 +00:00
</Flex>
);
})}
</Flex>
)}
2021-11-14 14:29:51 +00:00
{data?.generic && Object.keys(data?.generic) && (
2021-11-11 20:27:41 +00:00
<Flex
w="100%"
h="auto"
flexGrow={1}
flexBasis="420px"
direction="column"
>
<Heading size="sm">Account generic</Heading>
2021-11-14 14:29:51 +00:00
{Object.keys(data.generic).map((key) => {
2021-11-11 20:27:41 +00:00
return (
<Flex
key={v4()}
flexBasis={plotMinW}
flexGrow={1}
minW={plotMinW}
minH="320px"
maxH="420px"
direction="column"
boxShadow="md"
m={2}
>
<Text
w="100%"
py={2}
bgColor="gray.50"
fontWeight="600"
textAlign="center"
>
{key}
</Text>
2021-11-14 17:12:13 +00:00
<Report data={data.generic[key]} metric={key} />
2021-11-11 20:27:41 +00:00
</Flex>
);
})}
</Flex>
)}
</Flex>
);
};
export default SubscriptionReport;