2021-11-11 20:27:41 +00:00
|
|
|
import React from "react";
|
|
|
|
import { usePresignedURL } from "../core/hooks";
|
|
|
|
import Report from "./Report";
|
|
|
|
import { Spinner, Flex, Heading, Text } from "@chakra-ui/react";
|
|
|
|
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-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;
|