feat(AvatarUpload): preview when click backdrop#7368
Conversation
1. Make the hover style of the delete button more prominent, 2. Rewrite zoom onclick event and set stopPropagation.
|
Thanks for your PR, @momijijin. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors AvatarUpload preview behavior to open the correct image based on the clicked item’s validation id and enhances the avatar delete button styling and interaction to avoid accidental preview triggers. Sequence diagram for updated avatar preview and delete interactionssequenceDiagram
actor User
participant AvatarUploadComponent
participant PreviewMethod
participant JSInterop
rect rgb(230,230,250)
User->>AvatarUploadComponent: Click action area (not delete)
AvatarUploadComponent->>PreviewMethod: Preview(item.ValidateId)
PreviewMethod->>PreviewMethod: Validate ShowPreviewList
PreviewMethod->>PreviewMethod: Check id is not null/whitespace
PreviewMethod->>PreviewMethod: Find file where ValidateId == id
alt File found
PreviewMethod->>JSInterop: InvokeVoidAsync preview(PreviewerId, matchedIndex)
else File not found
PreviewMethod-->>AvatarUploadComponent: No action
end
end
rect rgb(230,255,230)
User->>AvatarUploadComponent: Click delete icon
AvatarUploadComponent->>AvatarUploadComponent: stopPropagation on delete click
AvatarUploadComponent->>AvatarUploadComponent: OnFileDelete(item)
AvatarUploadComponent-->>User: File removed without triggering preview
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- In
Preview(string id)you traverseFilesup to three times (Any,First, thenIndexOf); consider using a single pass (e.g.,var index = Files.FindIndex(f => f.ValidateId == id);and checkingindex >= 0) to avoid redundant enumeration. - The new
Preview(string id)signature changes the public API; if this method is used elsewhere, consider adding an overload or a default parameter-less wrapper to avoid breaking existing consumers. - In the Razor markup, the
@onclick="@(() => Preview(item.ValidateId ?? ""))"handler could be simplified to avoid the empty-string fallback and unnecessary lambda allocation, e.g., by passingitem.ValidateId!and letting thePreviewmethod handle null checks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Preview(string id)` you traverse `Files` up to three times (`Any`, `First`, then `IndexOf`); consider using a single pass (e.g., `var index = Files.FindIndex(f => f.ValidateId == id);` and checking `index >= 0`) to avoid redundant enumeration.
- The new `Preview(string id)` signature changes the public API; if this method is used elsewhere, consider adding an overload or a default parameter-less wrapper to avoid breaking existing consumers.
- In the Razor markup, the `@onclick="@(() => Preview(item.ValidateId ?? ""))"` handler could be simplified to avoid the empty-string fallback and unnecessary lambda allocation, e.g., by passing `item.ValidateId!` and letting the `Preview` method handle null checks.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/Upload/AvatarUpload.razor.cs:157-161` </location>
<code_context>
/// </summary>
/// <returns></returns>
- public async Task Preview()
+ public async Task Preview(string id)
{
- if(ShowPreviewList)
+ if(ShowPreviewList && !string.IsNullOrWhiteSpace(id) && Files.Any(r => r.ValidateId == id))
{
- await InvokeVoidAsync("preview", PreviewerId, 0);
+ await InvokeVoidAsync("preview", PreviewerId, Files.IndexOf(Files.First(r => r.ValidateId == id)));
}
}
</code_context>
<issue_to_address>
**suggestion:** Avoid double enumeration over `Files` when resolving the index for preview.
`Any` + `First` + `IndexOf` walks `Files` multiple times for the same id. Instead, compute the index in a single pass (e.g., `FindIndex` if `Files` is a `List<T>`, or a `for` loop) and pass that index directly to `preview`.
</issue_to_address>
### Comment 2
<location> `src/BootstrapBlazor/Components/Upload/AvatarUpload.razor:19-20` </location>
<code_context>
<Avatar Url="@item.PrevUrl" />
- <div class="upload-item-actions">
- <span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))">
+ <div class="upload-item-actions" @onclick="@(() => Preview(item.ValidateId ?? ""))">
+ <span class="upload-item-delete" @onclick="@(e => OnFileDelete(item))"
+ @onclick:stopPropagation="true">
<i class="@DeleteIcon"></i>
</code_context>
<issue_to_address>
**suggestion:** Consider passing the nullable id directly instead of normalizing to an empty string.
`Preview` currently requires a non-null `string`, so the call site converts `null` to `""`, which is then rejected by `string.IsNullOrWhiteSpace`. Instead, let `Preview` accept `string?` and pass `item.ValidateId` directly, so null handling is centralized and you avoid using a magic empty string at the call site.
Suggested implementation:
```
<Avatar Url="@item.PrevUrl" />
<div class="upload-item-actions" @onclick="@(() => Preview(item.ValidateId))">
```
To fully implement the suggestion, you will also need to:
1. Update the `Preview` method signature (likely in the `@code` block of `AvatarUpload.razor` or in `AvatarUpload.razor.cs`) from:
```csharp
private void Preview(string validateId)
```
to:
```csharp
private void Preview(string? validateId)
```
2. Adjust the implementation of `Preview` to handle `null` (and optionally whitespace) centrally, e.g.:
```csharp
private void Preview(string? validateId)
{
if (string.IsNullOrWhiteSpace(validateId))
{
return;
}
// existing preview logic using validateId
}
```
3. Ensure all other call sites of `Preview` now pass either `string?` directly or are updated to avoid normalizing to `""` in the caller.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7368 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 747 747
Lines 32765 32776 +11
Branches 4541 4543 +2
=========================================
+ Hits 32765 32776 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ange to use PrevUrl
Link issues
fixes #7340
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Refine avatar upload preview behavior and delete control styling.
New Features:
Bug Fixes:
Enhancements: