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

+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 };