fix(connection): 复制连接时保持在同一组内
- 修改 `addConnection` 方法以支持指定目标组 ID - 更新 `duplicateConnection` 函数以传递目标组 ID - 添加测试用例以验证复制连接的功能
This commit is contained in:
3 files changed
+61
-3
No files matched your search
@@ -1459,7 +1459,7 @@ async function duplicateConnection() {
|
||||
const config = connectionStore.getConfig(connId);
|
||||
if (!config) return;
|
||||
const newConfig = { ...config, id: uuid(), name: `${config.name} (Copy)` };
|
||||
await connectionStore.addConnection(newConfig);
|
||||
await connectionStore.addConnection(newConfig, connectionStore.groupIdForConnection(connId));
|
||||
toast(t("connection.duplicated"), 2000);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
emptyLayout,
|
||||
appendConnectionToLayout,
|
||||
removeConnectionFromSidebarLayout,
|
||||
findConnectionLocation,
|
||||
createGroup as createGroupOp,
|
||||
renameGroup as renameGroupOp,
|
||||
deleteGroup as deleteGroupOp,
|
||||
@@ -994,7 +995,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
if (scope === "root") rebuildTreeNodes();
|
||||
}
|
||||
|
||||
async function addConnection(config: ConnectionConfig) {
|
||||
async function addConnection(config: ConnectionConfig, targetGroupId?: string | null) {
|
||||
const normalized = normalizeConnection(config);
|
||||
const existing = connections.value.findIndex((c) => c.id === normalized.id);
|
||||
const nextConnections = [...connections.value];
|
||||
@@ -1002,7 +1003,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
nextConnections[existing] = normalized;
|
||||
} else {
|
||||
nextConnections.push(normalized);
|
||||
sidebarLayout.value = appendConnectionToLayout(sidebarLayout.value, normalized.id, newConnectionGroupId.value);
|
||||
const groupId = targetGroupId !== undefined ? targetGroupId : newConnectionGroupId.value;
|
||||
sidebarLayout.value = appendConnectionToLayout(sidebarLayout.value, normalized.id, groupId);
|
||||
}
|
||||
await persistConnections(nextConnections);
|
||||
connections.value = nextConnections;
|
||||
@@ -4057,6 +4059,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
moveConnectionToGroup(connectionId: string, groupId: string | null) {
|
||||
updateLayoutAndRebuild(moveConnectionToGroupOp(sidebarLayout.value, connectionId, groupId));
|
||||
},
|
||||
groupIdForConnection(connectionId: string): string | null {
|
||||
return findConnectionLocation(sidebarLayout.value, connectionId)?.groupId ?? null;
|
||||
},
|
||||
reorderSidebarEntry(draggedId: string, targetId: string, position: DropPosition) {
|
||||
updateLayoutAndRebuild(reorderEntryOp(sidebarLayout.value, draggedId, targetId, position));
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user