-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathErrorLogsMenu.tsx
77 lines (73 loc) · 2.52 KB
/
ErrorLogsMenu.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Box, Button, Divider, Flex, Heading, Link, Text, VStack } from "@chakra-ui/react";
import { errorsActions, useAppDispatch, useAppSelector } from "@umami/state";
import { useColor } from "../../../styles/useColor";
import { EmptyMessage } from "../../EmptyMessage";
import { DrawerContentWrapper } from "../DrawerContentWrapper";
export const ErrorLogsMenu = () => {
const color = useColor();
const errors = [...useAppSelector(s => s.errors)].reverse();
const dispatch = useAppDispatch();
const clearErrors = () => dispatch(errorsActions.reset());
return (
<DrawerContentWrapper
actions={
<Flex>
{Boolean(errors.length) && (
<Flex gap="15px" marginTop="18px">
<Button
as={Link}
width="auto"
padding="0 24px"
download="UmamiErrorLogs.json"
href={`data:application/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(errors)
)}`}
variant="primary"
>
Download
</Button>
<Button width="auto" padding="0 24px" onClick={clearErrors} variant="tertiary">
Clear All
</Button>
</Flex>
)}
</Flex>
}
title="Error Logs"
>
{errors.length ? (
<Box overflowY="auto">
<VStack
alignItems="flex-start"
gap="24px"
marginTop="24px"
divider={<Divider />}
spacing="0"
>
{errors.map((errorLog, index) => (
<Box key={errorLog.timestamp + index} width="full">
<Flex>
<Flex flexDirection="column">
<Heading color={color("900")} wordBreak="break-all" size="lg">
{errorLog.description}
</Heading>
<Text color={color("700")} size="sm">
{errorLog.timestamp}
</Text>
{errorLog.technicalDetails && (
<Text marginTop="12px" color={color("700")} size="sm">
{JSON.stringify(errorLog.technicalDetails)}
</Text>
)}
</Flex>
</Flex>
</Box>
))}
</VStack>
</Box>
) : (
<EmptyMessage alignItems="flex-start" marginTop="40px" title="No logs to show" />
)}
</DrawerContentWrapper>
);
};