mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(core-app): CB-1988 node move behaviour
This commit is contained in:
@@ -95,6 +95,13 @@ export class NavNodeInfoResource extends CachedMapResource<string, NavNode> {
|
||||
});
|
||||
}
|
||||
|
||||
getParent(key: string): string | undefined;
|
||||
getParent(key: ResourceKeyList<string>): (string | undefined)[];
|
||||
getParent(key: ResourceKey<string>): string | undefined | (string | undefined)[];
|
||||
getParent(key: ResourceKey<string>): string | undefined | (string | undefined)[] {
|
||||
return ResourceKeyUtils.map(key, key => this.get(key)?.parentId);
|
||||
}
|
||||
|
||||
setParent(key: string, parentId: string): void;
|
||||
setParent(key: ResourceKeyList<string>, parentId: string): void;
|
||||
setParent(key: ResourceKey<string>, parentId: string): void;
|
||||
|
||||
@@ -68,6 +68,7 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
childrenLimit: computed,
|
||||
setDetails: action,
|
||||
setNavObject: action,
|
||||
moveToNode: action,
|
||||
deleteInNode: action,
|
||||
unshiftToNode: action,
|
||||
pushToNode: action,
|
||||
@@ -205,6 +206,8 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
nodePaths: ResourceKeyUtils.toArray(key),
|
||||
folderPath: folder?.id,
|
||||
});
|
||||
|
||||
this.moveToNode(key, target);
|
||||
} finally {
|
||||
this.markDataLoaded(target);
|
||||
}
|
||||
@@ -229,8 +232,39 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
this.markOutdated(node.parentId);
|
||||
}
|
||||
|
||||
moveToNode(key: string, target: string): void;
|
||||
moveToNode(key: ResourceKeyList<string>, target: string): void;
|
||||
moveToNode(keyObject: ResourceKey<string>, target: string): void;
|
||||
moveToNode(keyObject: ResourceKey<string>, target: string): void {
|
||||
ResourceKeyUtils.forEach(keyObject, key => {
|
||||
const parentId = this.navNodeInfoResource.getParent(key);
|
||||
|
||||
if (parentId !== undefined) {
|
||||
const currentValue = this.data.get(parentId);
|
||||
|
||||
if (currentValue) {
|
||||
const nodeInfo = this.navNodeInfoResource.get(parentId);
|
||||
const children = currentValue.filter(value => value !== key);
|
||||
|
||||
if (nodeInfo) {
|
||||
nodeInfo.hasChildren = children.length > 0;
|
||||
}
|
||||
this.data.set(parentId, children);
|
||||
}
|
||||
}
|
||||
|
||||
this.navNodeInfoResource.setParent(key, target);
|
||||
});
|
||||
|
||||
this.pushToNode(target, ResourceKeyUtils.toArray(keyObject));
|
||||
this.markUpdated(target);
|
||||
this.markUpdated(keyObject);
|
||||
this.onItemAdd.execute(keyObject);
|
||||
}
|
||||
|
||||
deleteInNode(key: string, value: string[]): void;
|
||||
deleteInNode(key: ResourceKeyList<string>, value: string[][]): void;
|
||||
deleteInNode(keyObject: ResourceKey<string>, valueObject: string[] | string[][]): void;
|
||||
deleteInNode(keyObject: ResourceKey<string>, valueObject: string[] | string[][]): void {
|
||||
const deletedKeys: string[] = [];
|
||||
|
||||
@@ -239,7 +273,13 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
const currentValue = this.data.get(key);
|
||||
|
||||
if (currentValue) {
|
||||
this.data.set(key, currentValue.filter(value => !values.includes(value)));
|
||||
const children = currentValue.filter(value => !values.includes(value));
|
||||
const nodeInfo = this.navNodeInfoResource.get(key);
|
||||
|
||||
if (nodeInfo) {
|
||||
nodeInfo.hasChildren = children.length > 0;
|
||||
}
|
||||
this.data.set(key, children);
|
||||
}
|
||||
|
||||
deletedKeys.push(...values);
|
||||
@@ -256,8 +296,13 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
ResourceKeyUtils.forEach(keyObject, (key, i) => {
|
||||
const values = i === -1 ? (valueObject as string[]) : (valueObject as string[][])[i];
|
||||
const currentValue = this.data.get(key) || [];
|
||||
const nodeInfo = this.navNodeInfoResource.get(key);
|
||||
|
||||
currentValue.unshift(...values);
|
||||
|
||||
if (nodeInfo) {
|
||||
nodeInfo.hasChildren = currentValue.length > 0;
|
||||
}
|
||||
this.data.set(key, currentValue);
|
||||
});
|
||||
|
||||
@@ -271,8 +316,13 @@ export class NavTreeResource extends CachedMapResource<string, string[]> {
|
||||
ResourceKeyUtils.forEach(keyObject, (key, i) => {
|
||||
const values = i === -1 ? (valueObject as string[]) : (valueObject as string[][])[i];
|
||||
const currentValue = this.data.get(key) || [];
|
||||
const nodeInfo = this.navNodeInfoResource.get(key);
|
||||
|
||||
currentValue.push(...values);
|
||||
|
||||
if (nodeInfo) {
|
||||
nodeInfo.hasChildren = currentValue.length > 0;
|
||||
}
|
||||
this.data.set(key, currentValue);
|
||||
});
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap {
|
||||
) {
|
||||
const move = contexts.getContext(navNodeMoveContext);
|
||||
const nodes = getNodesFromContext(moveContexts);
|
||||
const nodeIdList = nodes.map(node => node.id);
|
||||
const children = this.navTreeResource.get(targetNode.id);
|
||||
|
||||
if (type === ENodeMoveType.CanDrop && targetNode.nodeType) {
|
||||
@@ -144,7 +145,12 @@ export class ConnectionFoldersBootstrap extends Bootstrap {
|
||||
move.setCanMove(true);
|
||||
}
|
||||
} else {
|
||||
await this.navTreeResource.moveTo(resourceKeyList(nodes.map(node => node.id)), targetNode.id);
|
||||
await this.navTreeResource.moveTo(resourceKeyList(nodeIdList), targetNode.id);
|
||||
const connections = nodeIdList
|
||||
.map(nodeId => this.connectionInfoResource.getConnectionForNode(nodeId)?.id)
|
||||
.filter<string>(Boolean as any);
|
||||
|
||||
this.connectionInfoResource.markOutdated(resourceKeyList(connections));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user