import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Dropdown, Tag, Tooltip } from 'antd'; import { MoreOutlined, EditOutlined, DeleteOutlined, ExportOutlined, ClusterOutlined, ArrowUpOutlined, ArrowDownOutlined, HolderOutlined, } from '@ant-design/icons'; import { useInboundOptions } from '@/api/queries/useInboundOptions'; import { buildRemarkByTag, chipPreview, inboundTagChipPreview, inboundTagsDisplayTitle, ruleCriteriaChips } from './helpers'; import type { RuleRow } from './types'; interface RuleCardListProps { rows: RuleRow[]; draggedIndex: number | null; dropTargetIndex: number | null; onHandlePointerDown: (idx: number, ev: React.PointerEvent) => void; openEdit: (idx: number) => void; moveUp: (idx: number) => void; moveDown: (idx: number) => void; confirmDelete: (idx: number) => void; } export default function RuleCardList({ rows, draggedIndex, dropTargetIndex, onHandlePointerDown, openEdit, moveUp, moveDown, confirmDelete, }: RuleCardListProps) { const { t } = useTranslation(); const { data: inboundOptions } = useInboundOptions(); const remarkByTag = useMemo(() => buildRemarkByTag(inboundOptions || []), [inboundOptions]); return (
{rows.length === 0 ? (
—
) : ( rows.map((rule, index) => (
draggedIndex ? 'drop-after' : ''}`} data-row-key={index} >
onHandlePointerDown(index, ev)} /> #{index + 1} {t('edit')}, onClick: () => openEdit(index) }, { key: 'up', label: , disabled: index === 0, onClick: () => moveUp(index) }, { key: 'down', label: , disabled: index === rows.length - 1, onClick: () => moveDown(index) }, { key: 'del', danger: true, label: <> {t('delete')}, onClick: () => confirmDelete(index) }, ], }} >
{t('pages.xray.Inbounds')} {rule.inboundTag ? ( {inboundTagChipPreview(rule.inboundTag, remarkByTag)} ) : ( any )}
→
{rule.balancerTag ? t('pages.xray.balancer') || 'Balancer' : t('pages.xray.Outbounds')} {rule.outboundTag ? ( {rule.outboundTag} ) : rule.balancerTag ? ( {rule.balancerTag} ) : ( — )}
{ruleCriteriaChips(rule).length > 0 && (
{ruleCriteriaChips(rule).map((chip) => ( {chip.label} {chipPreview(chip.value)} ))}
)}
)) )}
); }