Files
Netcatty/application/state/vaultHostTreeActionsStore.ts
T
陈大猫andCursor 96c9ccaaa0 fix(vault): add duplicate host to tree view context menu (#1336)
* fix(vault): add duplicate host action to tree view context menu

Wire the existing onDuplicateHost handler into vault host tree menus so
tree view matches grid/list duplicate behavior. Fixes #1329.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(vault): switch to hosts section when duplicating from terminal tree

Ensure the host details panel is visible after duplicate is triggered
from the terminal host tree sidebar.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 17:20:12 +08:00

48 lines
1.4 KiB
TypeScript

import { useSyncExternalStore } from 'react';
import type { Host } from '../../types';
export interface VaultHostTreeActions {
onDeleteHost: (host: Host) => void;
onDuplicateHost: (host: Host) => void;
onCopyCredentials: (host: Host) => void;
onNewGroup: (parentPath?: string) => void;
onRenameGroup: (groupPath: string) => void;
onDeleteGroup: (groupPath: string) => void;
commitInlineGroupRename: (name: string) => void;
cancelInlineGroupEdit: () => void;
moveHostToGroup: (hostId: string, groupPath: string | null) => void;
moveGroup: (sourcePath: string, targetParent: string | null) => void;
managedGroupPaths?: Set<string>;
onUnmanageGroup?: (groupPath: string) => void;
}
type Listener = () => void;
class VaultHostTreeActionsStore {
private actions: VaultHostTreeActions | null = null;
private listeners = new Set<Listener>();
getActions = () => this.actions;
setActions = (actions: VaultHostTreeActions | null) => {
this.actions = actions;
this.listeners.forEach((listener) => listener());
};
subscribe = (listener: Listener) => {
this.listeners.add(listener);
return () => this.listeners.delete(listener);
};
}
export const vaultHostTreeActionsStore = new VaultHostTreeActionsStore();
export const useVaultHostTreeActions = () => {
return useSyncExternalStore(
vaultHostTreeActionsStore.subscribe,
vaultHostTreeActionsStore.getActions,
vaultHostTreeActionsStore.getActions,
);
};