|
| 1 | +import { useGuideContext, useStore } from "@knocklabs/react-core"; |
| 2 | +import { Box, Stack } from "@telegraph/layout"; |
| 3 | +import { Text } from "@telegraph/typography"; |
| 4 | +import { ChevronDown, ChevronRight } from "lucide-react"; |
| 5 | +import * as React from "react"; |
| 6 | + |
| 7 | +export const GuideContextDetails = () => { |
| 8 | + const { client } = useGuideContext(); |
| 9 | + const [isExpanded, setIsExpanded] = React.useState(false); |
| 10 | + |
| 11 | + const defaultGroup = useStore(client.store, (state) => state.guideGroups[0]); |
| 12 | + const displayInterval = defaultGroup?.display_interval ?? null; |
| 13 | + |
| 14 | + return ( |
| 15 | + <Stack direction="column" borderTop="px"> |
| 16 | + <Stack |
| 17 | + h="5" |
| 18 | + px="2" |
| 19 | + bg="gray-3" |
| 20 | + align="center" |
| 21 | + gap="1" |
| 22 | + style={{ cursor: "pointer" }} |
| 23 | + onClick={() => setIsExpanded((prev) => !prev)} |
| 24 | + > |
| 25 | + <Text as="span" size="0" weight="medium"> |
| 26 | + Details |
| 27 | + </Text> |
| 28 | + {isExpanded ? <ChevronDown size={12} /> : <ChevronRight size={12} />} |
| 29 | + </Stack> |
| 30 | + |
| 31 | + {isExpanded && ( |
| 32 | + <Stack direction="column"> |
| 33 | + <Stack direction="column" gap="0_5" py="1" px="2" borderTop="px"> |
| 34 | + <Text as="span" size="0" weight="medium"> |
| 35 | + Throttle |
| 36 | + </Text> |
| 37 | + <Text as="code" size="0"> |
| 38 | + {displayInterval === null ? "-" : `Every ${displayInterval}s`} |
| 39 | + </Text> |
| 40 | + </Stack> |
| 41 | + |
| 42 | + <Stack direction="column" py="1" px="2" borderTop="px"> |
| 43 | + <Text as="span" size="0" weight="medium"> |
| 44 | + Target params |
| 45 | + </Text> |
| 46 | + <Stack direction="column" gap="0_5" mt="1"> |
| 47 | + <Text as="span" size="0" color="gray"> |
| 48 | + Tenant |
| 49 | + </Text> |
| 50 | + <Text as="code" size="0"> |
| 51 | + {client.targetParams.tenant ? ( |
| 52 | + <Box |
| 53 | + rounded="2" |
| 54 | + overflow="auto" |
| 55 | + backgroundColor="gray-2" |
| 56 | + border="px" |
| 57 | + style={{ maxHeight: "200px" }} |
| 58 | + > |
| 59 | + <pre style={{ fontSize: "11px", margin: 0 }}> |
| 60 | + <code>{client.targetParams.tenant}</code> |
| 61 | + </pre> |
| 62 | + </Box> |
| 63 | + ) : ( |
| 64 | + <Text as="code" size="0"> |
| 65 | + - |
| 66 | + </Text> |
| 67 | + )} |
| 68 | + </Text> |
| 69 | + </Stack> |
| 70 | + |
| 71 | + <Stack direction="column" gap="0_5"> |
| 72 | + <Text as="span" size="0" color="gray"> |
| 73 | + Data |
| 74 | + </Text> |
| 75 | + {client.targetParams.data ? ( |
| 76 | + <Box |
| 77 | + rounded="2" |
| 78 | + overflow="auto" |
| 79 | + backgroundColor="gray-2" |
| 80 | + border="px" |
| 81 | + style={{ maxHeight: "200px" }} |
| 82 | + > |
| 83 | + <pre style={{ fontSize: "11px", margin: 0 }}> |
| 84 | + <code> |
| 85 | + {JSON.stringify(client.targetParams.data, null, 2)} |
| 86 | + </code> |
| 87 | + </pre> |
| 88 | + </Box> |
| 89 | + ) : ( |
| 90 | + <Text as="code" size="0"> |
| 91 | + - |
| 92 | + </Text> |
| 93 | + )} |
| 94 | + </Stack> |
| 95 | + </Stack> |
| 96 | + </Stack> |
| 97 | + )} |
| 98 | + </Stack> |
| 99 | + ); |
| 100 | +}; |
0 commit comments