diff --git a/Changelog.md b/Changelog.md
index af0dc277d..e53b4ebf3 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -40,6 +40,7 @@
✨ 新增功能
+- 新增连接页面按网络协议(TCP/UDP)筛选连接
diff --git a/src/pages/connections.tsx b/src/pages/connections.tsx
index fbfe9d378..7a11a1497 100644
--- a/src/pages/connections.tsx
+++ b/src/pages/connections.tsx
@@ -71,6 +71,10 @@ const ORDER_OPTIONS = [
type OrderKey = (typeof ORDER_OPTIONS)[number]['id']
+type NetworkFilter = 'all' | 'tcp' | 'udp'
+
+let savedNetworkFilter: NetworkFilter = 'all'
+
const orderFunctionMap = ORDER_OPTIONS.reduce>(
(acc, option) => {
acc[option.id] = option.fn
@@ -86,6 +90,9 @@ const ConnectionsPage = () => {
const { searchState, match, onSearch } = usePageSearch('connections')
const hasSearch = searchState.text.length > 0
const [curOrderOpt, setCurOrderOpt] = useState('default')
+ const [networkFilter, setNetworkFilter] =
+ useState(savedNetworkFilter)
+ const hasFilter = networkFilter !== 'all'
const [connectionsType, setConnectionsType] = useState<'active' | 'closed'>(
'active',
)
@@ -112,18 +119,30 @@ const ConnectionsPage = () => {
const filterConn = useMemo(() => {
const orderFunc = orderFunctionMap[curOrderOpt]
- if (isTableLayout && !hasSearch) return selectedConnections
- if (!hasSearch) return orderFunc([...selectedConnections])
+ if (isTableLayout && !hasSearch && !hasFilter) return selectedConnections
+ if (!hasSearch && !hasFilter) return orderFunc([...selectedConnections])
const matchConns = selectedConnections.filter((conn) => {
- const { host, destinationIP, process } = conn.metadata
+ const { host, destinationIP, process, network } = conn.metadata
+ if (networkFilter !== 'all' && network !== networkFilter) return false
return (
- match(host || '') || match(destinationIP || '') || match(process || '')
+ !hasSearch ||
+ match(host || '') ||
+ match(destinationIP || '') ||
+ match(process || '')
)
})
return orderFunc ? orderFunc(matchConns) : matchConns
- }, [selectedConnections, isTableLayout, hasSearch, match, curOrderOpt])
+ }, [
+ selectedConnections,
+ isTableLayout,
+ hasSearch,
+ hasFilter,
+ networkFilter,
+ match,
+ curOrderOpt,
+ ])
const displayRows = useConnectionRowViews(
isTableLayout ? EMPTY_CONNECTIONS : filterConn,
@@ -255,6 +274,24 @@ const ConnectionsPage = () => {
))}
)}
+ {
+ savedNetworkFilter = e.target.value as NetworkFilter
+ setNetworkFilter(savedNetworkFilter)
+ }}
+ >
+
+
+
+