From 74106474caf128baf2f84c240b463a0d54992760 Mon Sep 17 00:00:00 2001
From: ryan
Date: Sun, 19 Jul 2026 11:52:29 +0800
Subject: [PATCH] =?UTF-8?q?fix(waf):=20UA=20=E6=A3=80=E6=9F=A5=E8=AF=B4?=
=?UTF-8?q?=E6=98=8E=E6=94=B9=E4=B8=BA=E9=97=AE=E5=8F=B7=E6=82=AC=E6=B5=AE?=
=?UTF-8?q?=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
将屏蔽/匹配相关 FieldDescription 收敛为 CircleHelp Tooltip。
---
.../components/node-properties.test.tsx | 13 +-
.../editor/components/node-properties.tsx | 128 ++++++++++--------
2 files changed, 77 insertions(+), 64 deletions(-)
diff --git a/frontend/app/(main)/waf/rules/editor/components/node-properties.test.tsx b/frontend/app/(main)/waf/rules/editor/components/node-properties.test.tsx
index 9d57b53b..ee9528b4 100644
--- a/frontend/app/(main)/waf/rules/editor/components/node-properties.test.tsx
+++ b/frontend/app/(main)/waf/rules/editor/components/node-properties.test.tsx
@@ -25,9 +25,9 @@ it('hides match and block until UA check is enabled', () => {
const { rerender } = render(
,
);
- expect(screen.queryByLabelText('屏蔽常见爬虫 UA')).not.toBeInTheDocument();
+ expect(screen.queryByRole('switch', { name: /屏蔽常见爬虫/ })).not.toBeInTheDocument();
expect(screen.queryByLabelText('浏览器')).not.toBeInTheDocument();
- fireEvent.click(screen.getByLabelText('开启 UA 检查'));
+ fireEvent.click(screen.getByRole('switch', { name: /开启 UA 检查/ }));
expect(onChange).toHaveBeenCalledWith(
expect.objectContaining({
config: expect.objectContaining({ require_ua: true }),
@@ -40,11 +40,10 @@ it('hides match and block until UA check is enabled', () => {
onChange={onChange}
/>,
);
- expect(screen.getByLabelText('屏蔽常见爬虫 UA')).toBeInTheDocument();
- expect(screen.getByLabelText('屏蔽非正常 UA')).toBeInTheDocument();
- expect(screen.getByLabelText('屏蔽自定义 UA')).toBeInTheDocument();
- expect(screen.getByText(/浏览器或操作系统分类为 Bot/)).toBeInTheDocument();
- expect(screen.getByText(/浏览器分类为 Other 或 Unknown/)).toBeInTheDocument();
+ expect(screen.getByRole('switch', { name: /屏蔽常见爬虫/ })).toBeInTheDocument();
+ expect(screen.getByRole('switch', { name: /屏蔽非正常/ })).toBeInTheDocument();
+ expect(screen.getByRole('switch', { name: /屏蔽自定义/ })).toBeInTheDocument();
+ expect(screen.getAllByLabelText('说明').length).toBeGreaterThan(0);
});
it('edits display name for configurable nodes', () => {
diff --git a/frontend/app/(main)/waf/rules/editor/components/node-properties.tsx b/frontend/app/(main)/waf/rules/editor/components/node-properties.tsx
index e44ce2b0..ed77eafc 100644
--- a/frontend/app/(main)/waf/rules/editor/components/node-properties.tsx
+++ b/frontend/app/(main)/waf/rules/editor/components/node-properties.tsx
@@ -1,4 +1,4 @@
-import { Settings2 } from 'lucide-react';
+import { CircleHelp, Settings2 } from 'lucide-react';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
@@ -27,6 +27,11 @@ import {
import { Separator } from '@/components/ui/separator';
import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/textarea';
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@/components/ui/tooltip';
import type { WAFIPGroup, WAFRuleNode } from '@/lib/services/openflare';
import { countryOptions, regionOptions, type GeoOption } from './geo-options';
@@ -149,14 +154,13 @@ function PropertyFields({
orientation='horizontal'
className='items-center justify-between'
>
-
-
- 开启 UA 检查
-
-
- 开启后如果请求头不携带 UA 将返回 False
-
-
+
+ 开启 UA 检查
+
+
-
-
- 屏蔽
-
-
- 命中返回 false,优先级高于匹配
-
-
+
+ 屏蔽
+
+
-
-
- 屏蔽常见爬虫 UA
-
-
- 浏览器或操作系统分类为 Bot(含 bot / spider / crawler /
- slurp 等特征,如 Googlebot)
-
-
+
+ 屏蔽常见爬虫 UA
+
+
onChange({
@@ -205,20 +202,17 @@ function PropertyFields({
-
-
- 屏蔽非正常 UA
-
-
- 浏览器分类为 Other 或 Unknown(不含搜索引擎等爬虫
- Bot,爬虫请用上方开关)
-
-
+
+ 屏蔽非正常 UA
+
+
onChange({
@@ -230,19 +224,17 @@ function PropertyFields({
-
-
- 屏蔽自定义 UA
-
-
- 原始 User-Agent 命中任一条正则时返回 false(Lua 模式语法)
-
-
+
+ 屏蔽自定义 UA
+
+
onChange({
@@ -254,8 +246,12 @@ function PropertyFields({
{node.config.block_custom_ua && (
-
+
自定义 UA 正则
+
-
- 每行一条 Lua 模式正则,命中任一条即 false;最多 32 条
-
)}
@@ -287,8 +280,12 @@ function PropertyFields({
UA 匹配
-
+
匹配模式
+
-
- 浏览器与操作系统两侧都有选择时生效
-
+
+
+
+
+ {tip}
+
+
+ );
+}
+
function DisplayNameField({
node,
onChange,