@@ -10,7 +10,6 @@ import { Button, Input } from '@nextui-org/react'
10
10
import { IoCloseCircle } from 'react-icons/io5'
11
11
import { calcTraffic } from '@renderer/utils/calc'
12
12
import { Table , TableHeader , TableColumn , TableBody , TableRow , TableCell } from '@nextui-org/react'
13
- import dayjs from 'dayjs'
14
13
import ConnectionDetailModal from '@renderer/components/connections/connection-detail-modal'
15
14
16
15
let preData : IMihomoConnectionDetail [ ] = [ ]
@@ -21,8 +20,6 @@ const Connections: React.FC = () => {
21
20
const [ connections , setConnections ] = useState < IMihomoConnectionDetail [ ] > ( [ ] )
22
21
const [ selectedConnection , setSelectedConnection ] = useState < IMihomoConnectionDetail > ( )
23
22
const [ isDetailModalOpen , setIsDetailModalOpen ] = useState ( false )
24
- const [ sortKey , setSortKey ] = useState ( '' )
25
- const [ descend , setDescend ] = useState ( false )
26
23
27
24
const filteredConnections = useMemo ( ( ) => {
28
25
if ( filter === '' ) return connections
@@ -32,25 +29,6 @@ const Connections: React.FC = () => {
32
29
} )
33
30
} , [ connections , filter ] )
34
31
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
-
54
32
useEffect ( ( ) => {
55
33
startMihomoConnections ( )
56
34
window . electron . ipcRenderer . on ( 'mihomoConnections' , ( _e , info : IMihomoConnectionsInfo ) => {
@@ -119,85 +97,38 @@ const Connections: React.FC = () => {
119
97
setSelectedConnection ( connections . find ( ( c ) => c . id === ( id as string ) ) )
120
98
setIsDetailModalOpen ( true )
121
99
} }
122
- sortDescriptor = { { column : sortKey , direction : descend ? 'descending' : 'ascending' } }
123
- onSortChange = { ( desc ) => {
124
- setSortKey ( desc . column as string )
125
- setDescend ( desc . direction !== 'ascending' )
126
- } }
127
100
isHeaderSticky
128
101
isStriped
129
102
className = "h-[calc(100vh-100px)] p-2 select-none"
130
103
>
131
104
< TableHeader >
132
- < TableColumn key = "type" allowsSorting >
105
+ < TableColumn key = "type" allowsResizing >
133
106
类型
134
107
</ 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 >
169
113
</ TableHeader >
170
- < TableBody items = { sortedConnections ?? [ ] } >
114
+ < TableBody items = { filteredConnections ?? [ ] } >
171
115
{ ( item ) => (
172
116
< TableRow key = { item . id } >
173
- < TableCell className = "max-w-[10px]" >
117
+ < TableCell >
174
118
{ item . metadata . type } ({ item . metadata . network } )
175
119
</ 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 }
179
125
</ 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 }
185
128
</ TableCell >
186
129
< TableCell className = "max-w-[200px] text-ellipsis whitespace-nowrap overflow-hidden" >
187
130
{ item . chains . reverse ( ) . join ( '::' ) }
188
131
</ 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 >
201
132
< TableCell >
202
133
< Button
203
134
isIconOnly
0 commit comments