Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 28, 2026

Link issues

fixes #912

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add configurability to PdfViewer URL generation to optionally hide the embedded PDF toolbar and thumbnail sidebar, and improve documentation comments for its parameters.

New Features:

  • Introduce a ShowToolbar parameter on PdfViewer to control visibility of the PDF toolbar and thumbnail sidebar.

Enhancements:

  • Refine PdfViewer URL fragment construction to support optional toolbar/sidebar hiding and page index handling.
  • Update PdfViewer component and parameter XML documentation with bilingual (Chinese/English) summaries.

Copilot AI review requested due to automatic review settings January 28, 2026 03:55
@bb-auto bb-auto bot added the enhancement New feature or request label Jan 28, 2026
@bb-auto bb-auto bot added this to the v9.2.0 milestone Jan 28, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 28, 2026

Reviewer's Guide

Adds a configurable ShowToolbar parameter to PdfViewer that controls PDF URL fragments for toolbar and thumbnail sidebar visibility, while refactoring URL fragment construction and enhancing XML documentation with bilingual comments.

Sequence diagram for PdfViewer URL generation with ShowToolbar

sequenceDiagram
participant PdfViewer
participant NavigationManager
participant UriBuilder

PdfViewer->>NavigationManager: ToAbsoluteUri(Url)
NavigationManager-->>PdfViewer: uri
PdfViewer->>UriBuilder: create UriBuilder(uri.AbsoluteUri)
PdfViewer->>PdfViewer: BuildFragment(builder)
PdfViewer->>UriBuilder: set Fragment(BuildFragment)
UriBuilder-->>PdfViewer: Uri.ToString() with_page_and_toolbar_fragments
Loading

Class diagram for updated PdfViewer with ShowToolbar

classDiagram
class PdfViewer {
  string Url
  int PageIndex
  string Height
  Func~Task~ OnLoaded
  Func~Task~ NotSupportCallback
  bool UseGoogleDocs
  bool ShowToolbar
  Task OnAfterRenderAsync(bool firstRender)
  Task InvokeInitAsync()
  string GetAbsoluteUri(string url)
  string BuildFragment(UriBuilder builder)
  Task TriggerOnLoaded()
  Task TriggerNotSupportCallback()
}

class NavigationManager {
  Uri ToAbsoluteUri(string url)
}

PdfViewer --> NavigationManager : uses
Loading

File-Level Changes

Change Details Files
Add ShowToolbar parameter and use it to control PDF viewer toolbar/sidebar via URL fragment construction.
  • Introduce a new ShowToolbar component parameter defaulting to true to indicate whether the toolbar and thumbnail sidebar should be displayed.
  • Refactor GetAbsoluteUri to use UriBuilder and delegate fragment construction to a new BuildFragment helper method.
  • In BuildFragment, append page index to the fragment only when PageIndex is greater than 0 and append toolbar/navpanes suppression when ShowToolbar is false.
  • Update XML documentation comments to provide both Chinese and English descriptions for existing parameters and callbacks and adjust inherited documentation methods by removing redundant returns tags.
src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 56064f5 into master Jan 28, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the feat-viewer branch January 28, 2026 03:55
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In BuildFragment, the UriBuilder builder parameter is never used, so it can be removed (and callers updated) to simplify the method signature and avoid confusion.
  • Consider extracting the fragment construction constants (e.g., "toolbar=0&navpanes=0") into named constants or separate helpers to make the intent clearer and reduce the chance of typos if reused or extended later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `BuildFragment`, the `UriBuilder builder` parameter is never used, so it can be removed (and callers updated) to simplify the method signature and avoid confusion.
- Consider extracting the fragment construction constants (e.g., `"toolbar=0&navpanes=0"`) into named constants or separate helpers to make the intent clearer and reduce the chance of typos if reused or extended later.

## Individual Comments

### Comment 1
<location> `src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs:97` </location>
<code_context>
         }

         var uri = NavigationManager.ToAbsoluteUri(url);
-        return $"{uri.AbsoluteUri}#page={PageIndex}";
+        var builder = new UriBuilder(uri.AbsoluteUri);
+        builder.Fragment = BuildFragment(builder);
</code_context>

<issue_to_address>
**issue (complexity):** Consider simplifying the new URI construction logic in `GetAbsoluteUri` to avoid the extra `UriBuilder` and `BuildFragment` indirection while still supporting `ShowToolbar` and page index behavior.

The new `GetAbsoluteUri` / `BuildFragment` flow adds indirection without clear benefit. You can keep the new `ShowToolbar` behavior while simplifying the URI construction and removing `UriBuilder` and the extra method.

A more direct implementation that preserves current behavior (including overwriting any existing fragment and using `"toolbar=0&navpanes=0"` as a single unit) could be:

```csharp
private string GetAbsoluteUri(string? url)
{
    if (string.IsNullOrEmpty(url))
    {
        return string.Empty;
    }

    var baseUri = NavigationManager.ToAbsoluteUri(url).AbsoluteUri;

    string? fragment = null;

    if (PageIndex > 0)
    {
        fragment = $"page={PageIndex}";
    }

    if (!ShowToolbar)
    {
        var toolbarFragment = "toolbar=0&navpanes=0";
        fragment = string.IsNullOrEmpty(fragment)
            ? toolbarFragment
            : $"{fragment}&{toolbarFragment}";
    }

    return string.IsNullOrEmpty(fragment)
        ? baseUri
        : $"{baseUri}#{fragment}";
}
```

This:

- Keeps all existing functionality (page index, optional toolbar/navpanes hiding).
- Matches the current behavior of replacing any existing fragment.
- Removes the extra `UriBuilder` allocation and `BuildFragment` method.
- Avoids the `List<string>` / `string.Join` overhead for at most two conditions, making the control flow easier to follow.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

var uri = NavigationManager.ToAbsoluteUri(url);
return $"{uri.AbsoluteUri}#page={PageIndex}";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider simplifying the new URI construction logic in GetAbsoluteUri to avoid the extra UriBuilder and BuildFragment indirection while still supporting ShowToolbar and page index behavior.

The new GetAbsoluteUri / BuildFragment flow adds indirection without clear benefit. You can keep the new ShowToolbar behavior while simplifying the URI construction and removing UriBuilder and the extra method.

A more direct implementation that preserves current behavior (including overwriting any existing fragment and using "toolbar=0&navpanes=0" as a single unit) could be:

private string GetAbsoluteUri(string? url)
{
    if (string.IsNullOrEmpty(url))
    {
        return string.Empty;
    }

    var baseUri = NavigationManager.ToAbsoluteUri(url).AbsoluteUri;

    string? fragment = null;

    if (PageIndex > 0)
    {
        fragment = $"page={PageIndex}";
    }

    if (!ShowToolbar)
    {
        var toolbarFragment = "toolbar=0&navpanes=0";
        fragment = string.IsNullOrEmpty(fragment)
            ? toolbarFragment
            : $"{fragment}&{toolbarFragment}";
    }

    return string.IsNullOrEmpty(fragment)
        ? baseUri
        : $"{baseUri}#{fragment}";
}

This:

  • Keeps all existing functionality (page index, optional toolbar/navpanes hiding).
  • Matches the current behavior of replacing any existing fragment.
  • Removes the extra UriBuilder allocation and BuildFragment method.
  • Avoids the List<string> / string.Join overhead for at most two conditions, making the control flow easier to follow.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a ShowToolbar parameter to the PdfViewer component to control the visibility of the PDF viewer's toolbar and thumbnail sidebar. The parameter defaults to true to maintain backward compatibility.

Changes:

  • Added a new boolean ShowToolbar parameter with a default value of true
  • Updated all XML documentation comments to use bilingual format (Chinese and English)
  • Refactored URL fragment building logic to support multiple PDF open parameters
  • Bumped package version from implicit to 10.0.1

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
PdfViewer.razor.cs Added ShowToolbar parameter, updated documentation to bilingual format, refactored fragment building with new BuildFragment method, and removed empty <returns> tags
BootstrapBlazor.PdfViewer.csproj Added explicit version property set to 10.0.1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +114 to +125
private string BuildFragment(UriBuilder builder)
{
var fragments = new List<string>();
if (PageIndex > 0)
{
fragments.Add($"page={PageIndex}");
}
if (!ShowToolbar)
{
fragments.Add("toolbar=0&navpanes=0");
}
return string.Join('&', fragments);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The builder parameter is passed to BuildFragment but never used. If the input URL already contains a fragment (e.g., "file.pdf#existingfragment"), it will be silently overwritten. If this is intentional behavior, the parameter should be removed. If existing fragments should be preserved or merged, the builder.Fragment should be checked and incorporated into the result.

Copilot uses AI. Check for mistakes.
}
if (!ShowToolbar)
{
fragments.Add("toolbar=0&navpanes=0");
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider splitting "toolbar=0&navpanes=0" into two separate fragment entries: fragments.Add("toolbar=0") and fragments.Add("navpanes=0"). While the current implementation works correctly, splitting them improves maintainability and makes the code more consistent - each fragment entry should represent a single parameter rather than pre-joined parameters.

Suggested change
fragments.Add("toolbar=0&navpanes=0");
fragments.Add("toolbar=0");
fragments.Add("navpanes=0");

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(PdfViewer): add ShowToolbar parameter

1 participant