Skip to content

Commit 8087e9d

Browse files
MrFlashAccountfarmaazon
authored andcommitted
Fix renaming for Local assets (#12815)
* Fix renaming for Local assets * Fix :(
1 parent f06f970 commit 8087e9d

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

app/gui/src/dashboard/services/LocalBackend.ts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,15 +640,39 @@ export default class LocalBackend extends Backend {
640640
assetId: backend.AssetId,
641641
body: backend.UpdateAssetRequestBody,
642642
): Promise<void> {
643-
if (body.parentDirectoryId != null) {
644-
const typeAndId = extractTypeAndId(assetId)
645-
const from =
646-
typeAndId.type !== backend.AssetType.project ?
643+
// Changing description is not supported on the Local Backend.
644+
const { parentDirectoryId, title } = body
645+
646+
const typeAndId = extractTypeAndId(assetId)
647+
648+
const currentParentDirectoryPath = (() => {
649+
return typeAndId.type !== backend.AssetType.project ?
647650
typeAndId.id
648651
: this.projectManager.getProjectPath(typeAndId.id)
649-
const fileName = getFileName(from)
650-
const to = joinPath(extractTypeAndId(body.parentDirectoryId).id, fileName)
651-
await this.projectManager.moveFile(from, to)
652+
})()
653+
654+
const newParentDirectoryPath = (() => {
655+
const fileName = title == null ? getFileName(currentParentDirectoryPath) : title
656+
657+
if (parentDirectoryId == null) {
658+
return joinPath(
659+
projectManager.Path(currentParentDirectoryPath.split('/').slice(0, -1).join('/')),
660+
fileName,
661+
)
662+
}
663+
664+
return joinPath(extractTypeAndId(parentDirectoryId).id, fileName)
665+
})()
666+
667+
await this.projectManager.moveFile(currentParentDirectoryPath, newParentDirectoryPath)
668+
669+
// Changing the folder name for a project is _not_ enough,
670+
// we also need to change the name in the package.yaml file.
671+
if (typeAndId.type === backend.AssetType.project && title != null) {
672+
await this.projectManager.renameProject({
673+
projectId: typeAndId.id,
674+
name: projectManager.ProjectName(title),
675+
})
652676
}
653677
}
654678

app/gui/src/dashboard/services/ProjectManager.ts

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -620,47 +620,6 @@ export default class ProjectManager {
620620
'--filesystem-move-to',
621621
to,
622622
)
623-
const children = this.internalDirectories.get(from)
624-
// Assume a directory needs to be loaded for its children to be loaded.
625-
if (children) {
626-
const moveChildren = (directoryChildren: readonly FileSystemEntry[]) => {
627-
for (const child of directoryChildren) {
628-
switch (child.type) {
629-
case FileSystemEntryType.DirectoryEntry: {
630-
const childChildren = this.internalDirectories.get(child.path)
631-
if (childChildren) {
632-
moveChildren(childChildren)
633-
}
634-
break
635-
}
636-
case FileSystemEntryType.ProjectEntry: {
637-
const path = this.internalProjectPaths.get(child.metadata.id)
638-
if (path != null) {
639-
this.internalProjectPaths.set(child.metadata.id, Path(path.replace(from, to)))
640-
}
641-
break
642-
}
643-
case FileSystemEntryType.FileEntry: {
644-
// No special extra metadata is stored for files.
645-
break
646-
}
647-
}
648-
}
649-
this.internalDirectories.set(
650-
from,
651-
children.map((child) => ({ ...child, path: Path(child.path.replace(from, to)) })),
652-
)
653-
}
654-
moveChildren(children)
655-
}
656-
const directoryPath = getDirectoryAndName(from).directoryPath
657-
const siblings = this.internalDirectories.get(directoryPath)
658-
if (siblings) {
659-
this.internalDirectories.set(
660-
directoryPath,
661-
siblings.filter((entry) => entry.path !== from),
662-
)
663-
}
664623
}
665624

666625
/** Delete a file or directory. */

0 commit comments

Comments
 (0)