From 93f111b5b2931969ecaef2247a9491ece2f4d671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Sat, 17 Oct 2026 16:17:42 +0800 Subject: [PATCH] fix(groups): serialize edits and isolate group detail panels Prevent overlapping whole-list writes, avoid duplicate ids after rename, and discard delete confirmations prepared on a page that has since been left. Key member and webhook panels by group so local state cannot cross tenants. --- app/components/ConsolePage.vue | 37 +++++++++++++++++++++++++++++----- app/composables/useI18n.ts | 2 ++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/components/ConsolePage.vue b/app/components/ConsolePage.vue index 1cbba2d..c2560c9 100644 --- a/app/components/ConsolePage.vue +++ b/app/components/ConsolePage.vue @@ -209,6 +209,7 @@ @@ -250,6 +252,7 @@ {{ t("app.newGroup") }} @@ -291,6 +294,7 @@ variant="ghost" size="icon" class="h-7 w-7 text-muted hover:text-text" + :disabled="savingGroup" :title="t('groupEditor.editTitle')" @click="openEditGroup(g)" > @@ -301,6 +305,7 @@ color="error" size="icon" class="h-7 w-7 text-muted hover:text-bad" + :disabled="savingGroup" :title="t('groups.delete')" :aria-label="t('groups.delete')" @click="onDeleteGroup(g)" @@ -358,7 +363,7 @@
{{ t("groups.createFirst") }} @@ -589,7 +594,6 @@ const groupMissing = computed( () => !!routeGroupId.value && groupsLoaded.value && !groupsError.value && !selectedGroup.value, ); - const groupEditorOpen = ref(false); const editingGroup = ref(null); const savingGroup = ref(false); @@ -618,6 +622,7 @@ function canWriteRoutes(): boolean { push(t("toast.routesNotReady"), "bad"); return false; } + // Bumped whenever an editor opens: a save may only close the editor it was // made from, never one opened since (on another page, for another route). let routeEditorSession = 0; @@ -629,6 +634,7 @@ const orderChanged = computed( orderDraft.value.length !== groupRoutes.value.length || orderDraft.value.some((r, i) => r.id !== groupRoutes.value[i]?.id), ); + const canCreateRoute = computed( () => !needLogin.value && @@ -640,7 +646,6 @@ const canReorder = computed( () => !!selectedGroup.value && canEditRoutes(selectedGroup.value.id) && groupRoutes.value.length > 1, ); - /** * Labels of the group bar's buttons, given up so the group name stays whole: * first Reorder turns into an icon, then New route; only with both on icons @@ -751,6 +756,8 @@ watch( { immediate: true }, ); +// Every page is a history entry: the browser's (or device's) back button +// returns from a group's routes to the group list. function switchView(next: View): void { const path = next === "overview" ? "/admin" : `/admin/${next}`; if (route.path !== path) router.push(path); @@ -1028,7 +1035,18 @@ function openEditGroup(group: Group): void { groupEditorOpen.value = true; } +/** + * Group writes replace the whole group list, so they run one at a time, each + * built from the list the previous one saved; true when one may start. + */ +function canWriteGroups(): boolean { + if (!savingGroup.value) return true; + push(t("toast.groupsBusy"), "bad"); + return false; +} + async function onSaveGroupFromPanel(group: Group): Promise { + if (!canWriteGroups()) return; savingGroup.value = true; try { const next = groups.value.map((g) => (g.id === group.id ? group : g)); @@ -1043,6 +1061,7 @@ async function onSaveGroupFromPanel(group: Group): Promise { } async function onSaveGroup(group: Group): Promise { + if (!canWriteGroups()) return; const session = groupEditorSession; savingGroup.value = true; try { @@ -1053,7 +1072,8 @@ async function onSaveGroup(group: Group): Promise { // Id changed: rename first so routes/webhook secret/invites follow, // then persist the remaining edits under the new id. await groupsRename(editing.id, group.id); - next = [...groups.value.filter((g) => g.id !== editing.id), group]; + // A list loaded meanwhile may already hold the new id as well. + next = [...groups.value.filter((g) => g.id !== editing.id && g.id !== group.id), group]; } else { next = groups.value.map((g) => (g.id === editing.id ? group : g)); } @@ -1076,6 +1096,8 @@ async function onSaveGroup(group: Group): Promise { } async function onDeleteGroup(group: Group): Promise { + if (!canWriteGroups()) return; + const visit = pageVisit; // Fetch the real route count for this group instead of relying on the // routes of whichever group happens to be open in the detail view. let used = 0; @@ -1087,16 +1109,21 @@ async function onDeleteGroup(group: Group): Promise { } catch { // Count is best-effort; proceed without the warning. } + // The list was left while the count loaded: never ask on another page. + if (visit !== pageVisit) return; const confirmed = await confirm({ title: t("confirm.deleteGroup", { name: group.name || group.id }), description: used ? t("confirm.deleteGroupWarn", { n: used }).trim() : undefined, }); - if (!confirmed) return; + if (!confirmed || visit !== pageVisit || !canWriteGroups()) return; + savingGroup.value = true; try { await saveGroups(groups.value.filter((g) => g.id !== group.id)); push(t("toast.groupDeleted")); } catch (err) { push(t("toast.deleteFailed", { msg: err instanceof Error ? err.message : String(err) }), "bad"); + } finally { + savingGroup.value = false; } } diff --git a/app/composables/useI18n.ts b/app/composables/useI18n.ts index 675d92e..3b45d0f 100644 --- a/app/composables/useI18n.ts +++ b/app/composables/useI18n.ts @@ -422,6 +422,7 @@ const en: Dict = { "audit.allGroups": "All groups", "audit.refresh": "⟳ Refresh", "toast.routesSaved": "Routes saved", + "toast.groupsBusy": "Another group change is still saving; try again in a moment", "toast.routesNotReady": "The routes are still loading or saving; try again in a moment", "toast.routeDeleted": "Route deleted", "toast.groupSaved": "Groups saved", @@ -862,6 +863,7 @@ const zh: Dict = { "audit.allGroups": "全部分组", "audit.refresh": "⟳ 刷新", "toast.routesSaved": "路由已保存", + "toast.groupsBusy": "另一项分组修改仍在保存,请稍后再试", "toast.routesNotReady": "路由仍在加载或保存中,请稍后再试", "toast.routeDeleted": "路由已删除", "toast.groupSaved": "分组已保存",