mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 17:32:18 +00:00
* 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>
48 lines
1.4 KiB
TypeScript
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,
|
|
);
|
|
};
|