feat(console): confirm removing filled editor rows

Filter conditions and groups, delivery targets, saved fragments and forge
hosts vanished on a single click, taking whatever had been typed with
them. Rows holding content now ask first, while empty, never-filled
rows (`isBlankNode`: default operator, no path, no values, not negated)
are still removed directly.
This commit is contained in:
翅膀 committed 2026-10-17 00:58:24 +08:00
1 parent 85f8cb74bc
commit 84fc63663e
8 files changed
+104 -12

No files matched your search

+16 -4
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import type { NodeForm } from "~/composables/useFilterNode";
import { blankNode } from "~/composables/useFilterNode";
import { blankNode, isBlankNode } from "~/composables/useFilterNode";
import { FILTER_TYPES, FILTER_OPS } from "~/types";
defineOptions({ name: "FilterNodeEditor" });
@@ -13,6 +13,7 @@ const props = withDefaults(defineProps<{ node: NodeForm; depth?: number; deletab
const emit = defineEmits<{ (e: "remove"): void }>();
const { t } = useI18n();
const { confirm } = useConfirm();
const NODE_KINDS = ["all", "any"] as const;
const filterTypeOptions = computed(() =>
@@ -37,6 +38,17 @@ function unwrapNot(): void {
props.node.children = child.children;
props.node.child = child.child;
}
async function remove(): Promise<void> {
if (!isBlankNode(props.node)) {
const confirmed = await confirm({
title:
props.node.kind === "leaf" ? t("confirm.removeCondition") : t("confirm.removeFilterGroup"),
});
if (!confirmed) return;
}
emit("remove");
}
</script>
<template>
@@ -80,7 +92,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
@click="emit('remove')"
@click="remove"
>
✕
</RcButton>
@@ -124,7 +136,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
@click="emit('remove')"
@click="remove"
>
✕
</RcButton>
@@ -157,7 +169,7 @@ function unwrapNot(): void {
size="icon"
class="icon-btn danger"
:title="t('routeEditor.remove')"
@click="emit('remove')"
@click="remove"
>
✕
</RcButton>
+11 -1
View File
@@ -85,7 +85,7 @@
variant="destructive"
size="icon"
class="[grid-area:del] justify-self-end"
@click="form.forgeSources.splice(i, 1)"
@click="removeForgeSource(s)"
>
✕
</RcButton>
@@ -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<void> {
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])]
+23 -5
View File
@@ -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<void> {
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<void> {
}
}
function deleteFragment(frag: NamedFragment): void {
if (!props.groupId) return;
async function deleteFragment(frag: NamedFragment): Promise<void> {
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)"
>
✕
</RcButton>
+15
View File
@@ -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 => {
+10
View File
@@ -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<Locale, Dict> = { en, zh };
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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 处理即会生效。
+27
View File
@@ -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);
});
});