feat(firewall): Move-up/down buttons for rule priority reordering
Adds ↑↓ icon buttons in the firewall rules table. Clicking swaps the rule's priority value with its sorted neighbor via two sequential PUTs. First rule's ↑ and last rule's ↓ are disabled. Viewer role cannot reorder. v1.1.102 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { useState } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { Button, Form, Input, InputNumber, Modal, Popconfirm, Select, Space, Switch, Tag, Tooltip, Typography, message } from 'antd'
|
||||
import type { ColumnsType } from 'antd/es/table'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FireOutlined } from '@ant-design/icons'
|
||||
import { ArrowDownOutlined, ArrowUpOutlined, FireOutlined } from '@ant-design/icons'
|
||||
|
||||
const { Text } = Typography
|
||||
|
||||
@@ -183,6 +183,20 @@ export default function RulesTab() {
|
||||
onError: (e: Error) => message.error(e.message),
|
||||
})
|
||||
|
||||
const sortedRules = useMemo(
|
||||
() => [...(rules ?? [])].sort((a, b) => a.priority - b.priority),
|
||||
[rules],
|
||||
)
|
||||
|
||||
const swap = useMutation({
|
||||
mutationFn: async ({ a, b }: { a: FwRule; b: FwRule }) => {
|
||||
await apiClient.put(`/firewall/rules/${a.id}`, { ...a, priority: b.priority })
|
||||
await apiClient.put(`/firewall/rules/${b.id}`, { ...b, priority: a.priority })
|
||||
},
|
||||
onSuccess: () => { void qc.invalidateQueries({ queryKey: ['fw', 'rules'] }) },
|
||||
onError: (e: Error) => message.error(e.message),
|
||||
})
|
||||
|
||||
const editFromRow = (r: FwRule) => {
|
||||
setEditing(r)
|
||||
form.setFieldsValue({
|
||||
@@ -246,6 +260,33 @@ export default function RulesTab() {
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '', key: 'move', width: 64,
|
||||
render: (_, row) => {
|
||||
const idx = sortedRules.findIndex(r => r.id === row.id)
|
||||
const swapping = swap.isPending
|
||||
return (
|
||||
<Space size={2}>
|
||||
<Tooltip title={t('fw.rule.moveUp')}>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowUpOutlined />}
|
||||
disabled={isViewer || idx <= 0 || swapping}
|
||||
onClick={() => swap.mutate({ a: row, b: sortedRules[idx - 1] })}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('fw.rule.moveDown')}>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowDownOutlined />}
|
||||
disabled={isViewer || idx >= sortedRules.length - 1 || swapping}
|
||||
onClick={() => swap.mutate({ a: row, b: sortedRules[idx + 1] })}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('common.edit'), key: 'actions',
|
||||
render: (_, row) => (
|
||||
|
||||
Reference in New Issue
Block a user