|
@@ -1,6 +1,6 @@
|
|
|
import { useMemo } from 'react';
|
|
import { useMemo } from 'react';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
-import { Button, Dropdown, Tag } from 'antd';
|
|
|
|
|
|
|
+import { Button, Dropdown, Switch, Tag } from 'antd';
|
|
|
import {
|
|
import {
|
|
|
MoreOutlined,
|
|
MoreOutlined,
|
|
|
EditOutlined,
|
|
EditOutlined,
|
|
@@ -15,7 +15,7 @@ import type { ColumnsType } from 'antd/es/table';
|
|
|
|
|
|
|
|
import { useInboundOptions } from '@/api/queries/useInboundOptions';
|
|
import { useInboundOptions } from '@/api/queries/useInboundOptions';
|
|
|
import CriterionRow from './CriterionRow';
|
|
import CriterionRow from './CriterionRow';
|
|
|
-import { buildRemarkByTag, formatInboundTagList, inboundTagsDisplayTitle } from './helpers';
|
|
|
|
|
|
|
+import { buildRemarkByTag, formatInboundTagList, inboundTagsDisplayTitle, isApiRule } from './helpers';
|
|
|
import type { RuleRow } from './types';
|
|
import type { RuleRow } from './types';
|
|
|
|
|
|
|
|
interface RoutingColumnsParams {
|
|
interface RoutingColumnsParams {
|
|
@@ -28,6 +28,7 @@ interface RoutingColumnsParams {
|
|
|
moveUp: (idx: number) => void;
|
|
moveUp: (idx: number) => void;
|
|
|
moveDown: (idx: number) => void;
|
|
moveDown: (idx: number) => void;
|
|
|
confirmDelete: (idx: number) => void;
|
|
confirmDelete: (idx: number) => void;
|
|
|
|
|
+ toggleRule: (idx: number, enabled: boolean) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function useRoutingColumns({
|
|
export function useRoutingColumns({
|
|
@@ -40,6 +41,7 @@ export function useRoutingColumns({
|
|
|
moveUp,
|
|
moveUp,
|
|
|
moveDown,
|
|
moveDown,
|
|
|
confirmDelete,
|
|
confirmDelete,
|
|
|
|
|
+ toggleRule,
|
|
|
}: RoutingColumnsParams): ColumnsType<RuleRow> {
|
|
}: RoutingColumnsParams): ColumnsType<RuleRow> {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const { data: inboundOptions } = useInboundOptions();
|
|
const { data: inboundOptions } = useInboundOptions();
|
|
@@ -49,44 +51,66 @@ export function useRoutingColumns({
|
|
|
{
|
|
{
|
|
|
title: '#',
|
|
title: '#',
|
|
|
align: 'center',
|
|
align: 'center',
|
|
|
- width: 100,
|
|
|
|
|
- key: 'action',
|
|
|
|
|
|
|
+ width: 60,
|
|
|
|
|
+ key: 'index',
|
|
|
render: (_v, _r, index) => (
|
|
render: (_v, _r, index) => (
|
|
|
- <div className="action-cell">
|
|
|
|
|
|
|
+ <div className="action-cell" style={{ justifyContent: 'center' }}>
|
|
|
<HolderOutlined
|
|
<HolderOutlined
|
|
|
className="drag-handle"
|
|
className="drag-handle"
|
|
|
title={t('pages.xray.routing.dragToReorder')}
|
|
title={t('pages.xray.routing.dragToReorder')}
|
|
|
onPointerDown={(ev: React.PointerEvent) => onHandlePointerDown(index, ev)}
|
|
onPointerDown={(ev: React.PointerEvent) => onHandlePointerDown(index, ev)}
|
|
|
/>
|
|
/>
|
|
|
<span className="row-index">{index + 1}</span>
|
|
<span className="row-index">{index + 1}</span>
|
|
|
- <div className={!isMobile ? 'action-buttons' : ''}>
|
|
|
|
|
- {!isMobile && (
|
|
|
|
|
- <Button shape="circle" size="small" icon={<EditOutlined />} onClick={() => openEdit(index)} />
|
|
|
|
|
- )}
|
|
|
|
|
- <Dropdown
|
|
|
|
|
- trigger={['click']}
|
|
|
|
|
- menu={{
|
|
|
|
|
- items: [
|
|
|
|
|
- ...(isMobile
|
|
|
|
|
- ? [{ key: 'edit', label: <><EditOutlined /> {t('edit')}</>, onClick: () => openEdit(index) }]
|
|
|
|
|
- : []),
|
|
|
|
|
- { key: 'up', label: <ArrowUpOutlined />, disabled: index === 0, onClick: () => moveUp(index) },
|
|
|
|
|
- {
|
|
|
|
|
- key: 'down',
|
|
|
|
|
- label: <ArrowDownOutlined />,
|
|
|
|
|
- disabled: index === rowsLength - 1,
|
|
|
|
|
- onClick: () => moveDown(index),
|
|
|
|
|
- },
|
|
|
|
|
- { key: 'del', danger: true, label: <><DeleteOutlined /> {t('delete')}</>, onClick: () => confirmDelete(index) },
|
|
|
|
|
- ],
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
- <Button shape="circle" size="small" icon={<MoreOutlined />} />
|
|
|
|
|
- </Dropdown>
|
|
|
|
|
- </div>
|
|
|
|
|
</div>
|
|
</div>
|
|
|
),
|
|
),
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ title: t('pages.clients.actions'),
|
|
|
|
|
+ align: 'center',
|
|
|
|
|
+ width: 80,
|
|
|
|
|
+ key: 'action',
|
|
|
|
|
+ render: (_v, _r, index) => (
|
|
|
|
|
+ <div className={!isMobile ? 'action-buttons' : ''} style={{ justifyContent: 'center', margin: 0 }}>
|
|
|
|
|
+ {!isMobile && (
|
|
|
|
|
+ <Button shape="circle" size="small" icon={<EditOutlined />} onClick={() => openEdit(index)} />
|
|
|
|
|
+ )}
|
|
|
|
|
+ <Dropdown
|
|
|
|
|
+ trigger={['click']}
|
|
|
|
|
+ menu={{
|
|
|
|
|
+ items: [
|
|
|
|
|
+ ...(isMobile
|
|
|
|
|
+ ? [{ key: 'edit', label: <><EditOutlined /> {t('edit')}</>, onClick: () => openEdit(index) }]
|
|
|
|
|
+ : []),
|
|
|
|
|
+ { key: 'up', label: <ArrowUpOutlined />, disabled: index === 0, onClick: () => moveUp(index) },
|
|
|
|
|
+ {
|
|
|
|
|
+ key: 'down',
|
|
|
|
|
+ label: <ArrowDownOutlined />,
|
|
|
|
|
+ disabled: index === rowsLength - 1,
|
|
|
|
|
+ onClick: () => moveDown(index),
|
|
|
|
|
+ },
|
|
|
|
|
+ { key: 'del', danger: true, label: <><DeleteOutlined /> {t('delete')}</>, onClick: () => confirmDelete(index) },
|
|
|
|
|
+ ],
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Button shape="circle" size="small" icon={<MoreOutlined />} />
|
|
|
|
|
+ </Dropdown>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ title: t('enable'),
|
|
|
|
|
+ align: 'center',
|
|
|
|
|
+ width: 80,
|
|
|
|
|
+ key: 'enabled',
|
|
|
|
|
+ render: (_v, _r, index) => (
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ size="small"
|
|
|
|
|
+ checked={_r.enabled !== false}
|
|
|
|
|
+ onChange={(checked) => toggleRule(index, checked)}
|
|
|
|
|
+ disabled={isApiRule(_r)}
|
|
|
|
|
+ />
|
|
|
|
|
+ ),
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
title: t('pages.xray.rules.source'),
|
|
title: t('pages.xray.rules.source'),
|
|
|
align: 'left',
|
|
align: 'left',
|
|
@@ -184,6 +208,6 @@ export function useRoutingColumns({
|
|
|
),
|
|
),
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
- [t, isMobile, rowsLength, showSource, showBalancer, remarkByTag, onHandlePointerDown, openEdit, moveUp, moveDown, confirmDelete],
|
|
|
|
|
|
|
+ [t, isMobile, rowsLength, showSource, showBalancer, remarkByTag, onHandlePointerDown, openEdit, moveUp, moveDown, confirmDelete, toggleRule],
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|