diff --git a/app/components/FilterNodeEditor.vue b/app/components/FilterNodeEditor.vue
index 4bd8c60..8011bc2 100644
--- a/app/components/FilterNodeEditor.vue
+++ b/app/components/FilterNodeEditor.vue
@@ -1,6 +1,6 @@
@@ -80,7 +92,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
- @click="emit('remove')"
+ @click="remove"
>
✕
@@ -124,7 +136,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
- @click="emit('remove')"
+ @click="remove"
>
✕
@@ -157,7 +169,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
- @click="emit('remove')"
+ @click="remove"
>
✕
diff --git a/app/components/GroupEditor.vue b/app/components/GroupEditor.vue
index 38ad7f2..3013176 100644
--- a/app/components/GroupEditor.vue
+++ b/app/components/GroupEditor.vue
@@ -85,7 +85,7 @@
variant="destructive"
size="icon"
class="[grid-area:del] justify-self-end"
- @click="form.forgeSources.splice(i, 1)"
+ @click="removeForgeSource(s)"
>
✕
@@ -240,6 +240,7 @@ import { reactive, watch } from "vue";
import type { ForgeSource, Group } from "~/types";
const { t } = useI18n();
+const { confirm } = useConfirm();
const props = defineProps<{
open: boolean;
@@ -285,6 +286,15 @@ const owners = computed({
function addForgeSource(): void {
form.forgeSources.push({ host: "", type: "github" });
}
+
+async function removeForgeSource(source: ForgeSource): Promise {
+ const label = source.host.trim() || source.name?.trim();
+ if (label && !(await confirm({ title: t("confirm.removeForgeSource", { name: label }) }))) {
+ return;
+ }
+ const index = form.forgeSources.indexOf(source);
+ if (index >= 0) form.forgeSources.splice(index, 1);
+}
function toggleProvider(p: "github" | "gitea", checked: boolean): void {
form.providers = checked
? [...new Set([...form.providers, p])]
diff --git a/app/components/RouteEditor.vue b/app/components/RouteEditor.vue
index d1e177c..db6d120 100644
--- a/app/components/RouteEditor.vue
+++ b/app/components/RouteEditor.vue
@@ -27,6 +27,7 @@ const props = withDefaults(
const emit = defineEmits<{ (e: "close"): void; (e: "save", route: Route): void }>();
const { t } = useI18n();
+const { confirm } = useConfirm();
const isEdit = computed(() => props.route != null);
const discordRoles = computed({
@@ -84,6 +85,18 @@ function addTarget(): void {
form.targets.push(blankTarget());
}
+async function removeTarget(target: TargetForm): Promise {
+ const filled = [target.channelId, target.threadId, target.chatId, target.topicId].some((v) =>
+ v.trim(),
+ );
+ if (filled) {
+ const n = form.targets.indexOf(target) + 1;
+ if (!(await confirm({ title: t("confirm.removeTarget", { n }) }))) return;
+ }
+ const index = form.targets.indexOf(target);
+ if (index >= 0) form.targets.splice(index, 1);
+}
+
function validateNode(nf: NodeForm): string | null {
if (nf.kind === "leaf") {
if (nf.leaf.type === "field" && !nf.leaf.path.trim()) return t("routeEditor.errPath");
@@ -277,12 +290,17 @@ async function saveAsFragment(): Promise {
}
}
-function deleteFragment(frag: NamedFragment): void {
- if (!props.groupId) return;
+async function deleteFragment(frag: NamedFragment): Promise {
+ const groupId = props.groupId;
+ if (!groupId) return;
+ if (!(await confirm({ title: t("confirm.deleteFragment", { name: frag.name }) }))) return;
+ fragmentError.value = "";
const next = fragments.value.filter((f) => f.id !== frag.id);
- saveFragments(props.groupId, next).catch((err) => {
+ try {
+ await saveFragments(groupId, next);
+ } catch (err) {
fragmentError.value = err instanceof Error ? err.message : String(err);
- });
+ }
}
watch(
@@ -537,7 +555,7 @@ watch(
size="icon"
class="[grid-area:del] justify-self-end"
:title="t('routeEditor.remove')"
- @click="form.targets.splice(i, 1)"
+ @click="removeTarget(tg)"
>
✕
diff --git a/app/composables/useFilterNode.ts b/app/composables/useFilterNode.ts
index 62f124e..5ba5774 100644
--- a/app/composables/useFilterNode.ts
+++ b/app/composables/useFilterNode.ts
@@ -116,6 +116,21 @@ export function nodeFormToRouteFilters(nf: NodeForm): { filters: Filter[]; ast?:
return { filters: [], ast: ast ?? undefined };
}
+/**
+ * Whether a node holds nothing worth confirming before it is removed: an
+ * untouched condition (default operator, no path, no values, not negated) or
+ * groups made only of those. A changed operator counts as content, since
+ * e.g. `exists` is a complete condition without values.
+ */
+export function isBlankNode(nf: NodeForm): boolean {
+ if (nf.kind === "leaf") {
+ const { exclude, op, path, values } = nf.leaf;
+ return !exclude && op === "eq" && !path.trim() && values.every((v) => !v.trim());
+ }
+ if (nf.kind === "all" || nf.kind === "any") return nf.children.every(isBlankNode);
+ return !nf.child || isBlankNode(nf.child);
+}
+
export function collectEvents(node: FilterNode): string[] {
const out: string[] = [];
const walk = (n: FilterNode): void => {
diff --git a/app/composables/useI18n.ts b/app/composables/useI18n.ts
index dcb13eb..e58524b 100644
--- a/app/composables/useI18n.ts
+++ b/app/composables/useI18n.ts
@@ -396,10 +396,15 @@ const en: Dict = {
"confirm.deleteGroupWarn": " {n} route(s) reference it and will lose their group.",
"confirm.cancel": "Cancel",
"confirm.delete": "Delete",
+ "confirm.removeCondition": "Delete this condition?",
+ "confirm.removeFilterGroup": "Delete this condition group and everything in it?",
+ "confirm.removeTarget": "Remove target {n}?",
+ "confirm.deleteFragment": 'Delete fragment "{name}"?',
"confirm.removeMember": 'Remove member "{name}"?',
"confirm.revokeInvite": "Revoke this invite link?",
"confirm.disableWebhook": "Disable this group's webhook endpoint?",
"confirm.disableWebhookDetail": "The secret is deleted; senders still using it will be rejected.",
+ "confirm.removeForgeSource": 'Remove host "{name}"?',
};
const zh: Dict = {
@@ -790,10 +795,15 @@ const zh: Dict = {
"confirm.deleteGroupWarn": " 有 {n} 条路由引用它,将失去所属分组。",
"confirm.cancel": "取消",
"confirm.delete": "删除",
+ "confirm.removeCondition": "确定删除该条件吗?",
+ "confirm.removeFilterGroup": "确定删除该条件组及其中的全部条件吗?",
+ "confirm.removeTarget": "确定删除第 {n} 个目标吗?",
+ "confirm.deleteFragment": "确定删除片段“{name}”吗?",
"confirm.removeMember": "确定移除成员“{name}”吗?",
"confirm.revokeInvite": "确定撤销该邀请链接吗?",
"confirm.disableWebhook": "确定停用该分组的 webhook 入口吗?",
"confirm.disableWebhookDetail": "secret 将被删除,仍在使用它的发送方会被拒绝。",
+ "confirm.removeForgeSource": "确定删除来源主机“{name}”吗?",
};
const messages: Record = { en, zh };
diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md
index 9cf3eae..599125e 100644
--- a/docs/guide/configuration.md
+++ b/docs/guide/configuration.md
@@ -65,7 +65,7 @@ For local debugging only, set `DEBUG_MODE=true` to bypass GitHub OAuth and grant
The console is served as an SPA at `/admin`; its tabs are deep-linkable via the URL path (`/admin/groups`, `/admin/logs`, `/admin/audit`). URLs outside `/admin` that do not match an endpoint return a plain `404` instead of the console.
-Destructive actions — deleting routes or groups, removing members, revoking invites, disabling a group's webhook — ask for confirmation in an in-app dialog.
+Destructive actions — deleting routes, groups, filter conditions, fragments, targets or forge hosts, removing members, revoking invites, disabling a group's webhook — ask for confirmation in an in-app dialog (empty, never-filled rows are removed directly).
All management endpoints (`/admin/api/*`) are documented in the [Admin API](../api/admin). Saved routes and groups are persisted to D1 (`d1_routes` / `d1_groups`) immediately, the KV cache is invalidated and the config cache is refreshed so the webhook pipeline picks them up on the next run.
diff --git a/docs/zh/guide/configuration.md b/docs/zh/guide/configuration.md
index f995d70..caf47d9 100644
--- a/docs/zh/guide/configuration.md
+++ b/docs/zh/guide/configuration.md
@@ -64,7 +64,7 @@ WebHooker 在 `/admin` 提供内置配置控制台,可在浏览器中管理路
控制台以 SPA 形式在 `/admin` 提供;其标签页可通过 URL 路径直达(`/admin/groups`、`/admin/logs`、`/admin/audit`)。`/admin` 之外未匹配到端点的 URL 直接返回 `404`,而不会展示控制台。
-删除类操作——删除路由或分组,移除成员,撤销邀请,停用分组 webhook——都会先弹出应用内确认框。
+删除类操作——删除路由、分组、过滤条件、片段、目标或来源主机,移除成员,撤销邀请,停用分组 webhook——都会先弹出应用内确认框(从未填写过的空行直接删除)。
所有管理端点(`/admin/api/*`)见 [Admin API](../api/admin)。保存的路由和分组会立即持久化到 D1(`d1_routes` / `d1_groups`),并使 KV 缓存失效、刷新配置缓存,下一次 webhook 处理即会生效。
diff --git a/tests/filter-node.test.ts b/tests/filter-node.test.ts
new file mode 100644
index 0000000..2020853
--- /dev/null
+++ b/tests/filter-node.test.ts
@@ -0,0 +1,27 @@
+import { describe, it, expect } from "bun:test";
+import { blankNode, isBlankNode } from "../app/composables/useFilterNode";
+
+describe("isBlankNode", () => {
+ it("treats untouched conditions and groups as blank", () => {
+ expect(isBlankNode(blankNode("leaf"))).toBe(true);
+ expect(isBlankNode(blankNode("all"))).toBe(true);
+ expect(isBlankNode(blankNode("not"))).toBe(true);
+ });
+
+ it("treats any value, path or negation as content", () => {
+ const withValue = blankNode("all");
+ withValue.children[0]!.leaf.values = ["push"];
+ expect(isBlankNode(withValue)).toBe(false);
+ const negated = blankNode("leaf");
+ negated.leaf.exclude = true;
+ expect(isBlankNode(negated)).toBe(false);
+ const withPath = blankNode("leaf");
+ withPath.leaf.path = "sender.login";
+ expect(isBlankNode(withPath)).toBe(false);
+ // `exists` is a complete condition without any value.
+ const exists = blankNode("all");
+ exists.children[0]!.leaf.type = "branch";
+ exists.children[0]!.leaf.op = "exists";
+ expect(isBlankNode(exists)).toBe(false);
+ });
+});