Code Quality: Continued working on Shelf Pane#17308
Code Quality: Continued working on Shelf Pane#17308d2dyno1 wants to merge 10 commits intofiles-community:mainfrom
Conversation
|
@d2dyno1 thank you for the PR! We're not ready to enable this just yet as I still need to add the resize logic.
This is a nice touch 🙂 |
If time allows, I can add the resizing logic in this PR (borrowing it from the preview pane).
The buttons were an inspiration from the original spec and I think they can stay for when we roll out the Shelf feature. We can gather feedback on them and the behavior can always be changed in the future. It's not set in stone 🙂
Yes, the implementation is based on FileSystemWatcher which does observe the changes across the file system.
😉 @yaira2 |
That would be great, thanks! Aside from the actual resizing of the pane, there are other behaviors that I need to finalize such as smaller window sizes etc. |
|
Is renaming an item supposed to remove it from the list? |
|
Where do you plan to put the open shelf toggle button? |
It's next to the Status Center button. |
Thats fine, I was going to say we should avoid putting it into the toolbar, as those are kind of scoped to the view panes, and the shelf is separate from those. |
97999e5 to
806f922
Compare
| if (statusCenterItem is not null) | ||
| { | ||
| statusCenterItem.Progress.EnumerationCompleted = true; | ||
| statusCenterItem.Progress.ItemsCount = items.Count; | ||
| statusCenterItem.Progress.ReportStatus(FileSystemStatusCode.InProgress); | ||
| } |
There was a problem hiding this comment.
Bug: The progress bar's total item count is set to 0, causing a division-by-zero exception when calculating progress for copy/cut operations with over 50 items.
Severity: CRITICAL
Suggested Fix
In TransferHelpers.cs on lines 23 and 96, change statusCenterItem.Progress.ItemsCount = items.Count; to statusCenterItem.Progress.ItemsCount = itemsCount; to use the variable that holds the correct total count.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/Files.App/Helpers/TransferHelpers.cs#L20-L25
Potential issue: In `ExecuteTransferAsync`, when handling more than 50 items, a status
center item is created. Its `Progress.ItemsCount` is incorrectly initialized to
`items.Count`, which is 0, instead of using the correct `itemsCount` variable. When the
progress is updated via `AddProcessedItemsCount(1)` and `Report()` is called, the
progress percentage calculation `(value.ProcessedItemsCount * 100.0 / value.ItemsCount)`
attempts to divide by zero. This will throw an exception and crash the application
during any copy or cut operation involving more than 50 items.
Did we get this right? 👍 / 👎 to inform future reviews.
| var result = storable switch | ||
| { | ||
| IFile => await shellViewModel.GetFileFromPathAsync(storable.Id).OnSuccess(x => items.Add(x)), | ||
| IFolder => await shellViewModel.GetFolderFromPathAsync(storable.Id).OnSuccess(x => items.Add(x)), | ||
| }; |
There was a problem hiding this comment.
Bug: The switch expression in ExecuteTransferAsync lacks a default case, which will cause a SwitchExpressionException if an item is neither an IFile nor an IFolder.
Severity: MEDIUM
Suggested Fix
Add a default case to the switch expression to handle unexpected types. For consistency with BulkDeleteAsync, consider throwing an ArgumentOutOfRangeException, for example: _ => throw new ArgumentOutOfRangeException(nameof(storable)).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: src/Files.App/Helpers/TransferHelpers.cs#L36-L40
Potential issue: The `switch` expression in `ExecuteTransferAsync` (lines 36-40) handles
`IFile` and `IFolder` types but lacks a default case. If an item from the shelf is of a
type that is neither `IFile` nor `IFolder`, the switch expression will not find a
matching arm and will throw a `SwitchExpressionException` at runtime. This will crash
the copy or cut operation. A similar operation, `BulkDeleteAsync`, correctly includes a
default case that throws an `ArgumentOutOfRangeException`, suggesting this was an
oversight.
Did we get this right? 👍 / 👎 to inform future reviews.
Resolved / Related Issues
This PR introduces minor changes, unless additional changes are requested. The file watcher was implemented quite some time ago and already works properly, thanks to #16900 and #16728. This PR focuses solely on re-enabling this feature, but can be iterated upon to accommodate any undocumented missing features (if any? - not that I'm aware of)
Re-enabled the command for showing the Shelf pane in productionSteps used to test these changes
Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.