Compare commits

...
Author SHA1 Message Date
netcatty-bot af05b1b249 fix(#3440): automated AI fix 2026-09-18 09:02:05 +00:00
3 changed files with 24 additions and 28 deletions

No files matched your search

+8 -28
View File
@@ -77,6 +77,7 @@ import {
remapSnippetTargetGroupPaths,
} from "../domain/hostGroupPathMutations";
import {
canReorderVaultHosts,
reorderVaultItems,
reorderVaultStrings,
type VaultOrderPosition,
@@ -1191,34 +1192,13 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
const source = hostsRef.current.find((host) => host.id === sourceHostId);
const target = hostsRef.current.find((host) => host.id === targetHostId);
if (!source || !target) return;
const targetGroup = target.group || "";
const targetManagedSource = managedSources
.filter(
(sourceInfo) =>
targetGroup === sourceInfo.groupName ||
targetGroup.startsWith(`${sourceInfo.groupName}/`),
)
.sort((a, b) => b.groupName.length - a.groupName.length)[0];
const updatedHosts = hostsRef.current.map((host) =>
host.id === sourceHostId
? {
...host,
label:
targetManagedSource &&
(!host.protocol || host.protocol === "ssh")
? host.label.replace(/\s/g, "")
: host.label,
group: targetGroup,
managedSourceId:
targetManagedSource &&
(!host.protocol || host.protocol === "ssh")
? targetManagedSource.id
: undefined,
}
: host,
);
// Card-to-card drags only reorder hosts within the same group; moving a
// host into a different group must go through the group folder drop
// (moveHostToGroup), otherwise dragging two grouped cards past each
// other silently swaps their group membership.
if (!canReorderVaultHosts(source.group, target.group)) return;
const reorderedHosts = reorderVaultItems<Host>(
updatedHosts,
hostsRef.current,
sourceHostId,
targetHostId,
position,
@@ -1227,7 +1207,7 @@ const VaultViewInner: React.FC<VaultViewProps> = ({
onUpdateHosts(reorderedHosts);
setSortMode("manual");
},
[managedSources, onUpdateHosts, setSortMode],
[onUpdateHosts, setSortMode],
);
const reorderGroup = useCallback(
+9
View File
@@ -5,6 +5,7 @@ import {
normalizeVaultOrder,
reorderVaultStrings,
reorderVaultItems,
canReorderVaultHosts,
sortByVaultOrder,
} from "./vaultOrder.ts";
@@ -94,3 +95,11 @@ test("reorderVaultStrings moves one value around another", () => {
["dev", "ops", "prod"],
);
});
test("canReorderVaultHosts only allows drags within the same group", () => {
assert.equal(canReorderVaultHosts("ops", "ops"), true);
assert.equal(canReorderVaultHosts("ops", "ops/web"), false);
assert.equal(canReorderVaultHosts("ops", ""), false);
assert.equal(canReorderVaultHosts("", ""), true);
assert.equal(canReorderVaultHosts(undefined, undefined), true);
});
+7
View File
@@ -92,6 +92,13 @@ export const reorderVaultItems = <T extends VaultOrderedItem>(
return renumberVaultOrder(next);
};
export const canReorderVaultHosts = (
sourceGroup: string | undefined,
targetGroup: string | undefined,
): boolean => {
return (sourceGroup ?? "") === (targetGroup ?? "");
};
export const getNextVaultOrder = <T extends { order?: number }>(
items: readonly T[],
): number => {