-
Notifications
You must be signed in to change notification settings - Fork 1
fix: address 2 bugs from Devin Review on workspaceStore #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,7 +192,7 @@ function updateChildrenPaths(children: FileNode[], oldPath: string, newPath: str | |
| return children.map((child) => { | ||
| const updatedChild: FileNode = { | ||
| ...child, | ||
| path: child.path.replace(oldPath, newPath), | ||
| path: child.path.startsWith(oldPath) ? newPath + child.path.slice(oldPath.length) : child.path, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: The updateChildrenPaths fix correctly addresses a real String.replace bug The old code Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| }; | ||
| if (updatedChild.children) { | ||
| updatedChild.children = updateChildrenPaths(updatedChild.children, oldPath, newPath); | ||
|
|
@@ -201,6 +201,20 @@ function updateChildrenPaths(children: FileNode[], oldPath: string, newPath: str | |
| }); | ||
| } | ||
|
|
||
| function deepCloneFileNode(node: FileNode, newParentPath: string): FileNode { | ||
| const cloned: FileNode = { | ||
| ...node, | ||
| id: genId('file'), | ||
| path: `${newParentPath}/${node.name}`, | ||
| }; | ||
| if (node.children) { | ||
| cloned.children = node.children.map((child) => | ||
| deepCloneFileNode(child, cloned.path) | ||
| ); | ||
| } | ||
| return cloned; | ||
| } | ||
|
|
||
| function addChildToFolder( | ||
| nodes: FileNode[], | ||
| parentPath: string, | ||
|
|
@@ -492,6 +506,11 @@ export const useWorkspaceStore = create<WorkspaceState>((set, get) => ({ | |
| name: dupName, | ||
| path: `${parentPath}/${dupName}`, | ||
| }; | ||
| if (node.children) { | ||
| newNode.children = node.children.map((child) => | ||
| deepCloneFileNode(child, newNode.path) | ||
| ); | ||
| } | ||
| if (!parentPath) { | ||
| return { files: [...s.files, newNode] }; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Pre-existing: dupName regex doesn't handle multi-dot filenames ideally
The
dupNameconstruction at line 502 uses/(\.\w+)$/to split name from extension. For files likeApp.d.ts, this only captures the last extension segment (.ts), producingApp.d (copy).tsinstead ofApp (copy).d.ts. Similarly, for dotfiles like.gitignore, it strips the entire name to produce(copy).gitignore(note the leading space). This is a pre-existing issue not introduced by this PR, but worth noting since theduplicateFilefunction was modified.(Refers to line 502)
Was this helpful? React with 👍 or 👎 to provide feedback.