Skip to content

feat(DockView): remove EditorRequired attribute#985

Merged
ArgoZhang merged 3 commits intomasterfrom
refactor-dv
Apr 24, 2026
Merged

feat(DockView): remove EditorRequired attribute#985
ArgoZhang merged 3 commits intomasterfrom
refactor-dv

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 24, 2026

Link issues

fixes #984

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

Relax DockViewV2 parameter requirements while enforcing correct configuration when local storage is enabled.

Bug Fixes:

  • Prevent invalid DockViewV2 configuration by throwing an exception if local storage is enabled without providing a Name.

Enhancements:

  • Remove the compile-time EditorRequired constraint from the DockViewV2 Name parameter and validate it at runtime when needed.
  • Refine DockViewV2 local storage configuration by centralizing option construction in GetDockViewConfig and using helpers for enablement and key generation.

Copilot AI review requested due to automatic review settings April 24, 2026 01:49
@bb-auto bb-auto Bot added the enhancement New feature or request label Apr 24, 2026
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Apr 24, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 24, 2026

Reviewer's Guide

Refactors DockViewV2 local storage configuration handling by removing the EditorRequired requirement from Name, adding runtime validation when local storage is enabled, and consolidating option construction into a clearer DockView configuration method.

Class diagram for updated DockViewV2 local storage configuration

classDiagram
    class DockViewV2 {
        +string~Nullable~ Name
        +bool~Nullable~ EnableLocalStorage
        +string~Nullable~ Version
        +string~Nullable~ LocalStoragePrefix

        -bool IsEnableLocalStorage
        -string~Nullable~ LocalStorageKey

        +void OnInitialized()
        +void OnParametersSet()
        +Task OnAfterRenderAsync(bool firstRender)
        +Task InvokeInitAsync()
        -DockViewConfig GetDockViewConfig()
        -string GetVersion()
        -string GetPrefixKey()
        +Task Reset(string~Nullable~ layoutConfig)
    }

    class DockViewConfig {
        +bool EnableLocalStorage
        +string~Nullable~ LocalStorageKey
        +bool IsLock
        +bool ShowLock
        +bool IsFloating
        +string~Nullable~ LayoutConfig
        +string LoadTabs
    }

    DockViewV2 --> DockViewConfig : builds
Loading

Flow diagram for DockViewV2 local storage validation and configuration

flowchart TD
    A[OnParametersSet called] --> B{IsEnableLocalStorage?}
    B -- No --> C[Skip Name validation]
    B -- Yes --> D{Name is null or empty?}
    D -- Yes --> E[Throw InvalidOperationException]
    D -- No --> F[Continue initialization]

    subgraph ConfigConstruction[GetDockViewConfig]
        G[Compute IsEnableLocalStorage from EnableLocalStorage or options] --> H{IsEnableLocalStorage?}
        H -- No --> I[Set LocalStorageKey to null]
        H -- Yes --> J[Build LocalStorageKey using GetPrefixKey, Name, GetVersion]
        I --> K[Populate DockViewConfig with flags and LocalStorageKey]
        J --> K
    end

    C --> G
    F --> G

    K --> L[InvokeInitAsync uses GetDockViewConfig]
    K --> M[OnAfterRenderAsync update uses GetDockViewConfig]
    K --> N[Reset uses GetDockViewConfig]
Loading

File-Level Changes

Change Details Files
Make DockView Name parameter optional at compile-time but validated at runtime when local storage is enabled.
  • Removed EditorRequired attribute from the Name component parameter to avoid compile-time requirement.
  • Reintroduced Name parameter later in the file with [Parameter] and [NotNull] only, keeping the same XML documentation.
  • Added OnParametersSet override that throws InvalidOperationException if local storage is enabled but Name is null or empty.
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs
Refactor DockView configuration builder and related local storage options.
  • Renamed GetOptions helper to GetDockViewConfig to better reflect its purpose.
  • Changed EnableLocalStorage evaluation to use a new IsEnableLocalStorage helper that merges component and options defaults.
  • Changed LocalStorageKey generation to use a new LocalStorageKey helper, which returns null when local storage is disabled.
  • Updated InvokeInitAsync, OnAfterRenderAsync, and Reset methods to use GetDockViewConfig instead of GetOptions for consistency.
src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#984 Remove the [EditorRequired] attribute from the DockViewV2 Name parameter (while keeping the parameter functional in the component).

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

Copy link
Copy Markdown

@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 left some high level feedback:

  • The new InvalidOperationException message is only in English, whereas the surrounding XML comments are bilingual; consider aligning the error message with your localization approach (e.g., bilingual or resource-based).
  • The Chinese comment above the OnParametersSet validation contains a likely typo ('本体存储'); it should probably be '本地存储' to match the feature description.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new InvalidOperationException message is only in English, whereas the surrounding XML comments are bilingual; consider aligning the error message with your localization approach (e.g., bilingual or resource-based).
- The Chinese comment above the OnParametersSet validation contains a likely typo ('本体存储'); it should probably be '本地存储' to match the feature description.

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.

@ArgoZhang ArgoZhang merged commit a4c0e8a into master Apr 24, 2026
2 checks passed
@ArgoZhang ArgoZhang deleted the refactor-dv branch April 24, 2026 01:53
Copy link
Copy Markdown

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

Removes the EditorRequired requirement from DockViewV2.Name and replaces the design-time requirement with runtime validation when local-storage persistence is enabled.

Changes:

  • Removes [EditorRequired] from the Name parameter and repositions the parameter definition.
  • Adds OnParametersSet validation to throw when local storage is enabled but Name is missing.
  • Refactors option-building logic (GetOptionsGetDockViewConfig) and centralizes local-storage derived values (IsEnableLocalStorage, LocalStorageKey).

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

/// <para lang="en">Gets or sets the DockView name. Default is null and it is used for local storage identification</para>
/// </summary>
[Parameter]
[NotNull]
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Name is declared as nullable (string?) and is intentionally optional now (only required when local storage is enabled), but it is still annotated with [NotNull]. That attribute communicates to the nullability analyzer that the property getter never returns null, which is no longer true and can lead to incorrect flow analysis. Consider removing [NotNull] (or making Name non-nullable again if it must always be supplied).

Suggested change
[NotNull]

Copilot uses AI. Check for mistakes.
{
base.OnParametersSet();

// 开启本体存储未提供 Name 时抛出异常提示
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

Typo in the comment: it says “本体存储” but the code and docs refer to “本地存储”. This should be corrected to avoid confusion.

Suggested change
// 开启本体存储未提供 Name 时抛出异常提示
// 开启本地存储未提供 Name 时抛出异常提示

Copilot uses AI. Check for mistakes.
// 开启本体存储未提供 Name 时抛出异常提示
if (IsEnableLocalStorage && string.IsNullOrEmpty(Name))
{
throw new InvalidOperationException("Name must be provided when local storage is enabled.");
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The thrown InvalidOperationException message could be more actionable for consumers. Consider including the component/parameter names via nameof(Name)/nameof(EnableLocalStorage) and clarifying that local storage may be enabled either via the parameter or global DockViewOptions, so users know what to change.

Suggested change
throw new InvalidOperationException("Name must be provided when local storage is enabled.");
throw new InvalidOperationException($"{nameof(Name)} must be provided when local storage is enabled. Local storage can be enabled either by the {nameof(EnableLocalStorage)} parameter or by global {nameof(DockViewOptions)} configuration.");

Copilot uses AI. Check for mistakes.

private bool IsEnableLocalStorage => EnableLocalStorage ?? _options.EnableLocalStorage ?? false;

private string? LocalStorageKey => IsEnableLocalStorage ? $"{GetPrefixKey()}-{Name}-{GetVersion()}" : null;
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

LocalStorageKey is now null when local storage is disabled, but some JS code (e.g. dockview-utils.js) reads options.localStorageKey outside the enableLocalStorage guard. This can cause unexpected access to localStorage keys like null-panels/undefined-panels, and potentially JSON parse errors if those keys exist. Consider always providing a stable non-null key, or updating the JS side to only access localStorageKey when enableLocalStorage is true.

Suggested change
private string? LocalStorageKey => IsEnableLocalStorage ? $"{GetPrefixKey()}-{Name}-{GetVersion()}" : null;
private string LocalStorageKey => $"{GetPrefixKey()}-{Name}-{GetVersion()}";

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(DockView): remove EditorRequired attribute

2 participants