import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Dropdown, Tag } from 'antd'; import { MoreOutlined, EditOutlined, DeleteOutlined, ExportOutlined, ClusterOutlined, ArrowUpOutlined, ArrowDownOutlined, HolderOutlined, } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import CriterionRow from './CriterionRow'; import type { RuleRow } from './types'; interface RoutingColumnsParams { isMobile: boolean; rowsLength: number; onHandlePointerDown: (idx: number, ev: React.PointerEvent) => void; openEdit: (idx: number) => void; moveUp: (idx: number) => void; moveDown: (idx: number) => void; confirmDelete: (idx: number) => void; } export function useRoutingColumns({ isMobile, rowsLength, onHandlePointerDown, openEdit, moveUp, moveDown, confirmDelete, }: RoutingColumnsParams): ColumnsType { const { t } = useTranslation(); return useMemo( () => [ { title: '#', align: 'center', width: 100, key: 'action', render: (_v, _r, index) => (
onHandlePointerDown(index, ev)} /> {index + 1}
{!isMobile && (
), }, { title: t('pages.xray.rules.source'), align: 'left', width: 180, key: 'source', render: (_v, record) => (
{record.sourceIP && } {record.sourcePort && } {record.vlessRoute && } {!record.sourceIP && !record.sourcePort && !record.vlessRoute && —}
), }, { title: t('pages.inbounds.network'), align: 'left', width: 180, key: 'network', render: (_v, record) => (
{record.network && } {record.protocol && } {record.attrs && } {!record.network && !record.protocol && !record.attrs && —}
), }, { title: t('pages.xray.rules.dest'), align: 'left', key: 'destination', render: (_v, record) => (
{record.ip && } {record.domain && } {record.port && } {!record.ip && !record.domain && !record.port && —}
), }, { title: t('pages.xray.Inbounds'), align: 'left', width: 180, key: 'inbound', render: (_v, record) => (
{record.inboundTag && } {record.user && } {!record.inboundTag && !record.user && —}
), }, { title: t('pages.xray.Outbounds'), align: 'left', width: 170, key: 'outbound', render: (_v, record) => record.outboundTag ? (
{record.outboundTag}
) : ( — ), }, { title: t('pages.xray.Balancers'), align: 'left', width: 150, key: 'balancer', render: (_v, record) => record.balancerTag ? (
{record.balancerTag}
) : ( — ), }, ], // eslint-disable-next-line react-hooks/exhaustive-deps [t, isMobile, rowsLength], ); }