Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import { useEffect } from 'react';
|
|
|
|
import { activeTabStore } from '../../application/state/activeTabStore';
|
|
import {
|
|
vaultHostTreeActionsStore,
|
|
type VaultHostTreeActions,
|
|
} from '../../application/state/vaultHostTreeActionsStore';
|
|
import type { Host } from '../../types';
|
|
import type { VaultOrderPosition } from '../../domain/vaultOrder';
|
|
|
|
type RegisterVaultHostTreeActionsParams = {
|
|
handleCopyCredentials: (host: Host) => void;
|
|
handleCopyHostname?: (host: Host) => void;
|
|
handleDuplicateHost: (host: Host) => void;
|
|
startInlineRenameHost: (host: Host) => void;
|
|
onDeleteHost: (hostId: string) => void;
|
|
handleUnmanageGroup?: (groupPath: string) => void;
|
|
moveHostToGroup: (hostId: string, groupPath: string | null) => void;
|
|
moveGroup: (sourcePath: string, targetParent: string | null) => void;
|
|
reorderHost: (sourceHostId: string, targetHostId: string, position: VaultOrderPosition) => void;
|
|
reorderGroup: (sourcePath: string, targetPath: string, position: VaultOrderPosition) => boolean;
|
|
managedGroupPaths?: Set<string>;
|
|
startInlineNewGroup: (parentPath?: string) => void;
|
|
startInlineRenameGroup: (groupPath: string) => void;
|
|
startInlineDeleteGroup: (groupPath: string) => void;
|
|
commitInlineGroupRename: (name: string) => boolean | void | Promise<boolean | void>;
|
|
cancelInlineGroupEdit: () => void;
|
|
commitInlineHostRename: (name: string) => void;
|
|
cancelInlineHostEdit: () => void;
|
|
};
|
|
|
|
function focusVaultTab() {
|
|
activeTabStore.setActiveTabId('vault');
|
|
}
|
|
|
|
function withVaultFocus<T extends (...args: never[]) => void>(fn: T): T {
|
|
return ((...args: Parameters<T>) => {
|
|
focusVaultTab();
|
|
fn(...args);
|
|
}) as T;
|
|
}
|
|
|
|
export function useRegisterVaultHostTreeActions({
|
|
handleCopyCredentials,
|
|
handleCopyHostname,
|
|
handleDuplicateHost,
|
|
startInlineRenameHost,
|
|
onDeleteHost,
|
|
handleUnmanageGroup,
|
|
moveHostToGroup,
|
|
moveGroup,
|
|
reorderHost,
|
|
reorderGroup,
|
|
managedGroupPaths,
|
|
startInlineNewGroup,
|
|
startInlineRenameGroup,
|
|
startInlineDeleteGroup,
|
|
commitInlineGroupRename,
|
|
cancelInlineGroupEdit,
|
|
commitInlineHostRename,
|
|
cancelInlineHostEdit,
|
|
}: RegisterVaultHostTreeActionsParams) {
|
|
useEffect(() => {
|
|
const actions: VaultHostTreeActions = {
|
|
onCopyCredentials: handleCopyCredentials,
|
|
onCopyHostname: handleCopyHostname,
|
|
onDuplicateHost: withVaultFocus(handleDuplicateHost),
|
|
onRenameHost: startInlineRenameHost,
|
|
onDeleteHost: (host) => onDeleteHost(host.id),
|
|
onNewGroup: startInlineNewGroup,
|
|
onRenameGroup: startInlineRenameGroup,
|
|
onDeleteGroup: startInlineDeleteGroup,
|
|
commitInlineGroupRename,
|
|
cancelInlineGroupEdit,
|
|
commitInlineHostRename,
|
|
cancelInlineHostEdit,
|
|
moveHostToGroup,
|
|
moveGroup,
|
|
reorderHost,
|
|
reorderGroup,
|
|
managedGroupPaths,
|
|
onUnmanageGroup: handleUnmanageGroup
|
|
? withVaultFocus(handleUnmanageGroup)
|
|
: undefined,
|
|
};
|
|
|
|
vaultHostTreeActionsStore.setActions(actions);
|
|
return () => vaultHostTreeActionsStore.setActions(null);
|
|
}, [
|
|
cancelInlineGroupEdit,
|
|
cancelInlineHostEdit,
|
|
commitInlineGroupRename,
|
|
commitInlineHostRename,
|
|
handleCopyCredentials,
|
|
handleCopyHostname,
|
|
handleDuplicateHost,
|
|
handleUnmanageGroup,
|
|
managedGroupPaths,
|
|
moveGroup,
|
|
moveHostToGroup,
|
|
reorderGroup,
|
|
reorderHost,
|
|
onDeleteHost,
|
|
startInlineRenameHost,
|
|
startInlineDeleteGroup,
|
|
startInlineNewGroup,
|
|
startInlineRenameGroup,
|
|
]);
|
|
}
|