Files
clash-verge-rev/src/components/rule/rule-item.tsx
T
Tunglies 0c2de711bc perf(connections): reduce snapshot and table allocation churn (#8613)
* perf(connections): reduce snapshot and table allocation churn

Reuse unchanged connection lists, sort traffic columns without display snapshots, and suspend the relative-time clock while hidden. Keep rule rows indexed and release resize listeners on unmount.

* test(connections): limit coverage to changed behavior

Keep snapshot sharing, speed decay, bounded history, numeric sorting, and visibility regression guards. Remove unrelated clear-history and pending-delivery assertions.

* test(connections): focus clock regression on timer cost

Replace behavioral clock assertions with one resource-count check for shared, hidden, and released intervals.

* test(connections): retain only allocation and formatting guards

Reduce snapshot and table tests to reference reuse, notification suppression, and visible-row formatting cost.

* remove useless test

* no need changelog
2026-11-17 02:24:27 +00:00

74 lines
1.7 KiB
TypeScript

import { styled, Box, Typography } from '@mui/material'
import { Rule } from 'tauri-plugin-mihomo-api'
const Item = styled(Box)(({ theme }) => ({
display: 'flex',
padding: '4px 16px',
color: theme.palette.text.primary,
}))
const COLOR = [
'primary',
'secondary',
'info.main',
'warning.main',
'success.main',
]
interface Props {
value: Rule
lineNo: number
}
const parseColor = (text: string) => {
if (text === 'REJECT' || text === 'REJECT-DROP') return 'error.main'
if (text === 'DIRECT') return 'text.primary'
let sum = 0
for (let i = 0; i < text.length; i++) {
sum += text.charCodeAt(i)
}
return COLOR[sum % COLOR.length]
}
const RuleItem = (props: Props) => {
const { value, lineNo } = props
return (
<Item sx={{ borderBottom: '1px solid var(--divider-color)' }}>
<Typography
color="text.secondary"
variant="body2"
sx={{ lineHeight: 2, minWidth: 30, mr: 2.25, textAlign: 'center' }}
>
{lineNo}
</Typography>
<Box sx={{ userSelect: 'text' }}>
<Typography component="h6" variant="subtitle1" color="text.primary">
{value.payload || '-'}
</Typography>
<Typography
component="span"
variant="body2"
color="text.secondary"
sx={{ mr: 3, minWidth: 120, display: 'inline-block' }}
>
{typeof value.type === 'string' ? value.type : value.type.Unknown}
</Typography>
<Typography
component="span"
variant="body2"
color={parseColor(value.proxy)}
>
{value.proxy}
</Typography>
</Box>
</Item>
)
}
export default RuleItem