mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
refactor(profiles): drop manual snapshot update now that switching autosaves
Since switching projects automatically saves the current configuration back to the project being left, the per-project "update from current" button is redundant and even harmful: it allowed overwriting another project's snapshot with the current state, breaking the invariant that a project holds the state you last left it in. - Remove the resnapshot button and confirm dialog from the manage dialog; drop the now-unused scope prop and PROFILE_SCOPE_LABELS - Add a footer Close button to the manage dialog (overlay click is disabled app-wide, so it previously could only be closed via Esc) - Update manageDescription in all four locales to describe the autosave behavior; remove the two dead i18n keys - Fix a shadowed `warnings` vec in ProfileService::apply that silently dropped autosave-failure warnings before they reached the frontend - Mention auto-capture on next switch in the "no snapshot for this scope yet" warning and doc comments The backend update command keeps its resnapshot parameter; it is now only exercised by the pre-switch autosave path.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Check, Pencil, RefreshCw, Trash2, X } from "lucide-react";
|
||||
import { Check, Pencil, Trash2, X } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
@@ -16,17 +17,13 @@ import {
|
||||
useProfilesQuery,
|
||||
useUpdateProfileMutation,
|
||||
} from "@/lib/query/profiles";
|
||||
import type { ProfileScope } from "@/lib/api/profiles";
|
||||
import { PROFILE_SCOPE_LABELS } from "./scope";
|
||||
|
||||
interface ProfileManageDialogProps {
|
||||
isOpen: boolean;
|
||||
scope: ProfileScope;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
type PendingConfirm = {
|
||||
type: "resnapshot" | "delete";
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
@@ -34,12 +31,11 @@ type PendingConfirm = {
|
||||
/**
|
||||
* 项目管理对话框(纯快照式)
|
||||
*
|
||||
* 项目列表全应用共享,重命名/删除作用于共享实体;
|
||||
* "以当前状态更新快照"只覆盖发起页所属分组(scope)的槽位。
|
||||
* 项目列表全应用共享,重命名/删除作用于共享实体。
|
||||
* 快照内容由切换时的自动保存维护,不提供手动重拍入口。
|
||||
*/
|
||||
export function ProfileManageDialog({
|
||||
isOpen,
|
||||
scope,
|
||||
onClose,
|
||||
}: ProfileManageDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
@@ -71,11 +67,7 @@ export function ProfileManageDialog({
|
||||
|
||||
const handleConfirm = () => {
|
||||
if (!confirm) return;
|
||||
if (confirm.type === "delete") {
|
||||
deleteMutation.mutate(confirm.id);
|
||||
} else {
|
||||
updateMutation.mutate({ id: confirm.id, resnapshot: true, scope });
|
||||
}
|
||||
deleteMutation.mutate(confirm.id);
|
||||
setConfirm(null);
|
||||
};
|
||||
|
||||
@@ -154,21 +146,6 @@ export function ProfileManageDialog({
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
title={t("profiles.updateSnapshot")}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
type: "resnapshot",
|
||||
id: profile.id,
|
||||
name: profile.name,
|
||||
})
|
||||
}
|
||||
>
|
||||
<RefreshCw className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
@@ -176,7 +153,6 @@ export function ProfileManageDialog({
|
||||
title={t("profiles.delete")}
|
||||
onClick={() =>
|
||||
setConfirm({
|
||||
type: "delete",
|
||||
id: profile.id,
|
||||
name: profile.name,
|
||||
})
|
||||
@@ -189,26 +165,27 @@ export function ProfileManageDialog({
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
cancelRename();
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
{t("common.close")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{confirm && (
|
||||
<ConfirmDialog
|
||||
isOpen
|
||||
title={
|
||||
confirm.type === "delete"
|
||||
? t("profiles.deleteConfirmTitle")
|
||||
: t("profiles.updateSnapshot")
|
||||
}
|
||||
message={
|
||||
confirm.type === "delete"
|
||||
? t("profiles.deleteConfirmMessage", { name: confirm.name })
|
||||
: t("profiles.updateSnapshotConfirm", {
|
||||
name: confirm.name,
|
||||
group: PROFILE_SCOPE_LABELS[scope],
|
||||
})
|
||||
}
|
||||
variant={confirm.type === "delete" ? "destructive" : "info"}
|
||||
title={t("profiles.deleteConfirmTitle")}
|
||||
message={t("profiles.deleteConfirmMessage", { name: confirm.name })}
|
||||
variant="destructive"
|
||||
onConfirm={handleConfirm}
|
||||
onCancel={() => setConfirm(null)}
|
||||
/>
|
||||
|
||||
@@ -246,7 +246,6 @@ export function ProfileSwitcher({ activeApp }: ProfileSwitcherProps) {
|
||||
|
||||
<ProfileManageDialog
|
||||
isOpen={isManageOpen}
|
||||
scope={scope}
|
||||
onClose={() => setIsManageOpen(false)}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -12,13 +12,6 @@ export const APP_PROFILE_SCOPE: Partial<Record<AppId, ProfileScope>> = {
|
||||
codex: "codex",
|
||||
};
|
||||
|
||||
/** 分组显示名(产品名,不进 i18n;与后端托盘子菜单标签一致) */
|
||||
export const PROFILE_SCOPE_LABELS: Record<ProfileScope, string> = {
|
||||
claude: "Claude Code",
|
||||
"claude-desktop": "Claude Desktop",
|
||||
codex: "Codex",
|
||||
};
|
||||
|
||||
/** 分组内的 payload 槽位 key(后端 ProfileScope::apps 的前端镜像) */
|
||||
const SCOPE_SLOT_KEYS: Record<ProfileScope, (keyof PerApp<unknown>)[]> = {
|
||||
claude: ["claude"],
|
||||
|
||||
Reference in New Issue
Block a user