Skip to content

Commit c8377f9

Browse files
author
Pompurin404
committed
simplified connection page
1 parent 5ceb6fb commit c8377f9

File tree

1 file changed

+15
-84
lines changed

1 file changed

+15
-84
lines changed

src/renderer/src/pages/connections.tsx

+15-84
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Button, Input } from '@nextui-org/react'
1010
import { IoCloseCircle } from 'react-icons/io5'
1111
import { calcTraffic } from '@renderer/utils/calc'
1212
import { Table, TableHeader, TableColumn, TableBody, TableRow, TableCell } from '@nextui-org/react'
13-
import dayjs from 'dayjs'
1413
import ConnectionDetailModal from '@renderer/components/connections/connection-detail-modal'
1514

1615
let preData: IMihomoConnectionDetail[] = []
@@ -21,8 +20,6 @@ const Connections: React.FC = () => {
2120
const [connections, setConnections] = useState<IMihomoConnectionDetail[]>([])
2221
const [selectedConnection, setSelectedConnection] = useState<IMihomoConnectionDetail>()
2322
const [isDetailModalOpen, setIsDetailModalOpen] = useState(false)
24-
const [sortKey, setSortKey] = useState('')
25-
const [descend, setDescend] = useState(false)
2623

2724
const filteredConnections = useMemo(() => {
2825
if (filter === '') return connections
@@ -32,25 +29,6 @@ const Connections: React.FC = () => {
3229
})
3330
}, [connections, filter])
3431

35-
const sortedConnections = useMemo(() => {
36-
if (sortKey === '') return filteredConnections
37-
return filteredConnections.sort((a, b) => {
38-
const localA = a[sortKey] ? a[sortKey] : a.metadata[sortKey]
39-
const localB = b[sortKey] ? b[sortKey] : b.metadata[sortKey]
40-
if (descend) {
41-
if (typeof localA === 'string') {
42-
return localB.localeCompare(localA)
43-
}
44-
return localB - localA
45-
} else {
46-
if (typeof localA === 'string') {
47-
return localA.localeCompare(localB)
48-
}
49-
return localA - localB
50-
}
51-
})
52-
}, [filteredConnections, sortKey, descend])
53-
5432
useEffect(() => {
5533
startMihomoConnections()
5634
window.electron.ipcRenderer.on('mihomoConnections', (_e, info: IMihomoConnectionsInfo) => {
@@ -119,85 +97,38 @@ const Connections: React.FC = () => {
11997
setSelectedConnection(connections.find((c) => c.id === (id as string)))
12098
setIsDetailModalOpen(true)
12199
}}
122-
sortDescriptor={{ column: sortKey, direction: descend ? 'descending' : 'ascending' }}
123-
onSortChange={(desc) => {
124-
setSortKey(desc.column as string)
125-
setDescend(desc.direction !== 'ascending')
126-
}}
127100
isHeaderSticky
128101
isStriped
129102
className="h-[calc(100vh-100px)] p-2 select-none"
130103
>
131104
<TableHeader>
132-
<TableColumn key="type" allowsSorting>
105+
<TableColumn key="type" allowsResizing>
133106
类型
134107
</TableColumn>
135-
<TableColumn key="process" allowsSorting>
136-
进程
137-
</TableColumn>
138-
<TableColumn key="host" allowsSorting>
139-
主机
140-
</TableColumn>
141-
<TableColumn key="sniffer" allowsSorting>
142-
嗅探域名
143-
</TableColumn>
144-
<TableColumn key="rule" allowsSorting>
145-
规则
146-
</TableColumn>
147-
<TableColumn key="chains" width={500}>
148-
链路
149-
</TableColumn>
150-
<TableColumn key="download" allowsSorting>
151-
下载量
152-
</TableColumn>
153-
<TableColumn key="upload" allowsSorting>
154-
上传量
155-
</TableColumn>
156-
<TableColumn key="downloadSpeed" allowsSorting>
157-
下载速度
158-
</TableColumn>
159-
<TableColumn key="uploadSpeed" allowsSorting>
160-
上传速度
161-
</TableColumn>
162-
<TableColumn key="start" allowsSorting>
163-
连接时间
164-
</TableColumn>
165-
<TableColumn key="sourceIp">源地址</TableColumn>
166-
<TableColumn key="sourcePort">源端口</TableColumn>
167-
<TableColumn key="inboundUser">入站用户</TableColumn>
168-
<TableColumn key="close">关闭连接</TableColumn>
108+
<TableColumn key="origin">来源</TableColumn>
109+
<TableColumn key="target">目标</TableColumn>
110+
<TableColumn key="rule">规则</TableColumn>
111+
<TableColumn key="chains">链路</TableColumn>
112+
<TableColumn key="close">关闭</TableColumn>
169113
</TableHeader>
170-
<TableBody items={sortedConnections ?? []}>
114+
<TableBody items={filteredConnections ?? []}>
171115
{(item) => (
172116
<TableRow key={item.id}>
173-
<TableCell className="max-w-[10px]">
117+
<TableCell>
174118
{item.metadata.type}({item.metadata.network})
175119
</TableCell>
176-
<TableCell>{item.metadata.process}</TableCell>
177-
<TableCell className="max-w-[200px] text-ellipsis whitespace-nowrap overflow-hidden">
178-
{item.metadata.host}
120+
<TableCell>{item.metadata.process || item.metadata.sourceIP}</TableCell>
121+
<TableCell className="max-w-[100px] text-ellipsis whitespace-nowrap overflow-hidden">
122+
{item.metadata.host ||
123+
item.metadata.remoteDestination ||
124+
item.metadata.destinationIP}
179125
</TableCell>
180-
<TableCell className="max-w-[200px] text-ellipsis whitespace-nowrap overflow-hidden">
181-
{item.metadata.sniffHost ?? '-'}
182-
</TableCell>
183-
<TableCell className="max-w-[200px] text-ellipsis whitespace-nowrap overflow-hidden">
184-
{`${item.rule} ${item.rulePayload}`}
126+
<TableCell className="max-w-[100px] text-ellipsis whitespace-nowrap overflow-hidden">
127+
{item.rule} {item.rulePayload}
185128
</TableCell>
186129
<TableCell className="max-w-[200px] text-ellipsis whitespace-nowrap overflow-hidden">
187130
{item.chains.reverse().join('::')}
188131
</TableCell>
189-
<TableCell className="whitespace-nowrap">{calcTraffic(item.download)}</TableCell>
190-
<TableCell className="whitespace-nowrap">{calcTraffic(item.upload)}</TableCell>
191-
<TableCell className="whitespace-nowrap">
192-
{calcTraffic(item.downloadSpeed ?? 0)}/s
193-
</TableCell>
194-
<TableCell className="whitespace-nowrap">
195-
{calcTraffic(item.uploadSpeed ?? 0)}/s
196-
</TableCell>
197-
<TableCell className="whitespace-nowrap">{dayjs(item.start).fromNow()}</TableCell>
198-
<TableCell className="whitespace-nowrap">{item.metadata.sourceIP}</TableCell>
199-
<TableCell className="whitespace-nowrap">{item.metadata.sourcePort}</TableCell>
200-
<TableCell className="whitespace-nowrap">{item.metadata.inboundUser}</TableCell>
201132
<TableCell>
202133
<Button
203134
isIconOnly

0 commit comments

Comments
 (0)