mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 16:42:19 +00:00
Deleting saved hosts now removes their jump references from surviving hosts and group defaults in all ordinary deletion flows. Host-only bulk deletion uses the existing vault mutation boundary, and explicit empty chains retain their original group-override meaning. Validation: 282 focused checks, lint/build, two independent full-diff reviews, latest-head Codex review, current GitHub checks, and actual isolated Electron deletion/restart/native SSH reconnection. Fixes #3691
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { useCallback } from 'react';
|
|
|
|
import type { VaultGroupMutationResult, VaultGroupMutationState } from '../../domain/vaultGroupMutation';
|
|
import { pruneVaultJumpHostReferences } from '../../domain/vaultJumpGraph';
|
|
|
|
export function useVaultHostDeletion(
|
|
commit: (
|
|
mutate: (current: VaultGroupMutationState) => VaultGroupMutationResult,
|
|
) => Promise<VaultGroupMutationResult | { ok: false; superseded: true }>,
|
|
) {
|
|
return useCallback(async (hostIds: Iterable<string>) => {
|
|
const removedHostIds = new Set(hostIds);
|
|
if (removedHostIds.size === 0) return;
|
|
const result = await commit((current) => {
|
|
const pruned = pruneVaultJumpHostReferences({
|
|
hosts: current.hosts.filter((host) => !removedHostIds.has(host.id)),
|
|
groupConfigs: current.configs,
|
|
removedHostIds,
|
|
});
|
|
return {
|
|
ok: true,
|
|
state: { ...current, hosts: pruned.hosts, configs: pruned.groupConfigs },
|
|
};
|
|
});
|
|
if (!result.ok) {
|
|
throw new Error('error' in result ? result.error : 'Host deletion was superseded. Try again.');
|
|
}
|
|
}, [commit]);
|
|
}
|