Skip to content

Commit 715f146

Browse files
committed
packages/network-explorer: show detailed connect/listen and libp2p info
1 parent 98b13fd commit 715f146

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

packages/network-explorer/src/ApplicationDataBox.tsx

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,70 @@
11
import packageJson from "../package.json"
22

3-
import { Box, Grid, Text } from "@radix-ui/themes"
3+
import { Box, Grid, Text, Popover, IconButton } from "@radix-ui/themes"
44
import { useApplicationData } from "./hooks/useApplicationData.js"
5+
import { LuUnplug } from "react-icons/lu"
6+
7+
const ConnectionPopover = ({ children }: { children: React.ReactNode }) => {
8+
return (
9+
<Popover.Root>
10+
<Popover.Trigger>
11+
<IconButton
12+
variant="ghost"
13+
color="gray"
14+
radius="full"
15+
size="1"
16+
style={{ position: "relative", top: "3px", left: "-1px" }}
17+
>
18+
<LuUnplug color="#6f6f6f" />
19+
</IconButton>
20+
</Popover.Trigger>
21+
<Popover.Content>
22+
<Text size="2">{children}</Text>
23+
</Popover.Content>
24+
</Popover.Root>
25+
)
26+
}
527

628
export const ApplicationDataBox = () => {
729
const applicationInfo = useApplicationData()
830

931
return (
1032
<Box mt="auto">
1133
<Text size="2">
12-
<Grid
13-
columns="auto auto"
14-
px="3"
15-
py="3"
16-
width="auto"
17-
gapX="4"
18-
>
19-
<Text weight="bold">Status</Text> <Text color="gray">{applicationInfo ? "Connected" : "Offline"}</Text>
20-
<Text weight="bold">Topic</Text>
21-
<Text color="gray" wrap="nowrap">{applicationInfo ? applicationInfo.topic : "-"}</Text>
34+
<Grid columns="auto auto" px="3" py="3" width="auto" gapX="4">
35+
<Text weight="bold">Upstream</Text>{" "}
36+
<Text color="gray">
37+
{!applicationInfo && <Text color="gray">Offline</Text>}
38+
{Object.keys(applicationInfo?.networkConfig || {}).length > 0 && (
39+
<Text color="gray">
40+
libp2p{" "}
41+
<ConnectionPopover>
42+
{applicationInfo?.networkConfig.bootstrapList && (
43+
<Box>Bootstrap: {JSON.stringify(applicationInfo?.networkConfig.bootstrapList)}</Box>
44+
)}
45+
{applicationInfo?.networkConfig.listen && (
46+
<Box>Listen: {JSON.stringify(applicationInfo?.networkConfig.listen)}</Box>
47+
)}
48+
{applicationInfo?.networkConfig.announce && (
49+
<Box>Announce: {JSON.stringify(applicationInfo?.networkConfig.announce)}</Box>
50+
)}
51+
</ConnectionPopover>
52+
</Text>
53+
)}
54+
{applicationInfo?.wsConfig.listen && <Text color="gray">Accepting connections</Text>}
55+
{applicationInfo?.wsConfig.connect && (
56+
<Text color="gray">
57+
WebSocket <ConnectionPopover>{applicationInfo?.wsConfig.connect}</ConnectionPopover>
58+
</Text>
59+
)}
60+
{Object.keys(applicationInfo?.networkConfig || {}).length === 0 &&
61+
!applicationInfo?.wsConfig.listen &&
62+
!applicationInfo?.wsConfig.connect && <Text color="gray">No connection</Text>}
63+
</Text>
64+
<Text weight="bold">Topic</Text>
65+
<Text color="gray" wrap="nowrap">
66+
{applicationInfo ? applicationInfo.topic : "-"}
67+
</Text>
2268
<Text weight="bold">Database</Text>{" "}
2369
<Text color="gray">{applicationInfo ? applicationInfo.database : "-"}</Text>
2470
<Text weight="bold">Version</Text> <Text color="gray">v{packageJson.version}</Text>

packages/network-explorer/src/hooks/useApplicationData.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,7 @@ import useSWR from "swr"
22

33
import { fetchAndIpldParseJson } from "../utils.js"
44
import React, { createContext, useContext, useEffect, useState } from "react"
5-
import { Model } from "@canvas-js/modeldb"
6-
7-
export type ApplicationData = {
8-
networkConfig: {
9-
bootstrapList?: string[]
10-
listen?: string[]
11-
announce?: string[]
12-
}
13-
database: string
14-
topic: string
15-
models: Record<string, Model>
16-
actions: string[]
17-
}
5+
import { ApplicationData } from "@canvas-js/core"
186

197
const ApplicationDataContext = createContext<ApplicationData | null>(null)
208

0 commit comments

Comments
 (0)