mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
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:
1 parent
85f8cb74bc
commit
84fc63663e
8 files changed
+104
-12
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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])]
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user