Skip to content

fix(cli): register data-table-models, auto-add NuGet deps, suggest typos#16

Merged
Shewart merged 6 commits into
mainfrom
fix/data-table-half-install
Jun 18, 2026
Merged

fix(cli): register data-table-models, auto-add NuGet deps, suggest typos#16
Shewart merged 6 commits into
mainfrom
fix/data-table-half-install

Conversation

@Shewart

@Shewart Shewart commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

shellui add data-table left projects uncompilable in two ways: it tried to install a sub-component called data-table-models that was never registered, and the rendered DataTable.razor referenced System.Linq.Dynamic.Core (used for string-based sort) that the CLI didn't add as a NuGet package. The chart family had the same NuGet gap with Blazor-ApexCharts — that's why branch 1's CI smoke test had a manual dotnet add package workaround.

This PR makes both work out of the box and adds a "did you mean" hint for typos like shellui add datatable.

Changes

NuGet dependencies as a first-class manifest field

src/ShellUI.Core/Models/NuGetDependency.cs (new) — { PackageId, Version } record.

src/ShellUI.Core/Models/ComponentMetadata.cs — new NuGetDependencies list. Templates declare runtime NuGet deps the same way they declare source-file deps:

// DataTableTemplate
Dependencies = new List<string> { "data-table-models" },
NuGetDependencies = new List<NuGetDependency>
{
    new() { PackageId = "System.Linq.Dynamic.Core", Version = "1.7.1" }
}
// ChartTemplate
NuGetDependencies = new List<NuGetDependency>
{
    new() { PackageId = "Blazor-ApexCharts", Version = "6.0.2" }
}

The chart family (pie-chart, bar-chart, area-chart, line-chart, multi-series-chart) all transitively depend on chart, so they inherit the package through the recursive installer walk without needing to declare it themselves.

Installer runs dotnet add package

src/ShellUI.CLI/Services/ComponentInstaller.cs — the recursive dep walk now collects NuGetDependencies into a deduped batch and InstallNuGetDependenciesAsync invokes dotnet add <csproj> package <id> --version <v> for each at the end (after all source files land, so we restore once instead of between every component). Failures degrade to a warning, not a hard error — the source files are already on disk, so the user can still inspect or retry.

"Did you mean …?"

src/ShellUI.Templates/ComponentRegistry.cs — new FindClosestMatch(query) using two-row Levenshtein (O(n·m) time, O(min(n,m)) space). Returns the closest installable component name within edit distance 3, or null if nothing's close. Hidden sub-components (IsAvailable = false) are excluded — we never suggest installing internal deps directly.

ComponentInstaller calls it when ComponentRegistry.Exists(name) == false. So:

$ shellui add datatable
Component 'datatable' not found
Did you mean 'data-table'?

data-table-models gets registered

src/ShellUI.Templates/ComponentRegistry.csdata-table-models added to both the Components dictionary and the GetComponentContent switch.

src/ShellUI.Templates/Templates/DataTableModelsTemplate.csIsAvailable = false so it doesn't pollute shellui list and isn't suggested by the typo helper (it's only ever pulled in as a dep of data-table).

Tests (16 new)

ShellUI.Tests/NuGetDepsAndSuggestionsTests.cs:

  • FindClosestMatch returns expected suggestions for 5 realistic typos (datatable, data_table, buttong, chrt, themetoggle)
  • Returns null for exact matches (the caller already knows the component exists)
  • Returns null when nothing is close enough
  • Does not suggest hidden sub-components like data-table-models
  • data-table-models is registered and IsAvailable = false
  • data-table declares System.Linq.Dynamic.Core
  • chart declares Blazor-ApexCharts
  • 5 chart-family templates correctly depend on chart (transitive inheritance proof)
  • data-table @using and data-table-models namespace agree on Components.Models (the library-wide convention used by Tab, Stepper, ContextMenu, Command, ChartModels — verified with a repo-wide grep, not the Components.UI.Models form I initially tried and reverted)

CI smoke step asserts the auto-install

.github/workflows/ci.yml — dropped the manual dotnet add package Blazor-ApexCharts workaround from branch 1. The smoke step now greps the produced .csproj to confirm both Blazor-ApexCharts and System.Linq.Dynamic.Core appear (auto-installed by shellui add chart / data-table), and asserts Components/UI/Models/DataTableModels.cs exists.

Verification

  • dotnet test ShellUI.Tests43/43 passing (16 new + 27 from previous branches)
  • dotnet build src/ShellUI.CLI — clean

Test plan

  • CI green (tests + smoke step assertions)
  • Manual: scaffold a fresh dotnet new blazorshellui initshellui add data-tabledotnet build succeeds with no missing references. Confirm Components/UI/Models/DataTableModels.cs exists and <PackageReference Include="System.Linq.Dynamic.Core" /> was added to the .csproj.
  • Manual: shellui add chartdotnet build succeeds, no manual NuGet step needed.
  • Manual: shellui add datatable (no hyphen) → error message says Did you mean 'data-table'?

Shewart added 6 commits June 18, 2026 10:51
…ddition and data-table model installation

Enhanced the CI workflow to assert that the `shellui add` command correctly adds the necessary NuGet dependencies (Blazor-ApexCharts, System.Linq.Dynamic.Core) and verifies the installation of DataTable models. This ensures that the initialization process is robust and that all required components are present in the project file.
…estions

Introduced new test classes for validating the functionality of the ComponentRegistry in suggesting component names and managing NuGet dependencies. The tests cover scenarios for finding closest matches for typos, ensuring hidden sub-components are not suggested, and verifying the registration and availability of NuGet dependencies for components like data-table and chart. This addition enhances test coverage and ensures the integrity of component suggestions and dependency management.
…t dependencies and mark models as unavailable

Modified the DataTableModelsTemplate to set IsAvailable to false, indicating that the models are currently not available. Additionally, enhanced the DataTableTemplate to include a new NuGet dependency for System.Linq.Dynamic.Core, ensuring that the template has the necessary dependencies for advanced data table functionality.
…emplate

Enhanced the ChartTemplate to include a new NuGet dependency for Blazor-ApexCharts version 6.0.2, ensuring that the template has the necessary library for chart rendering functionality.
…uggestion functionality

Enhanced the ComponentRegistry by adding the "data-table-models" component and implementing a new method, FindClosestMatch, to suggest component names based on user input. This method utilizes Levenshtein distance to provide helpful hints for typos, improving user experience when searching for components.
…cies and improve installation process

Updated the ComponentInstaller to track and install NuGet dependencies more efficiently. Introduced a new method, InstallNuGetDependenciesAsync, to handle the addition of packages after all components are processed, preventing multiple invocations of `dotnet add package`. Enhanced the InstallComponentWithDependencies method to include suggestions for typos in component names, improving user experience. Additionally, added a NuGetDependencies property to ComponentMetadata for better dependency management.
@Shewart Shewart merged commit bc0b334 into main Jun 18, 2026
1 check passed
@Shewart Shewart deleted the fix/data-table-half-install branch June 18, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant