fix(cli): register data-table-models, auto-add NuGet deps, suggest typos#16
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shellui add data-tableleft projects uncompilable in two ways: it tried to install a sub-component calleddata-table-modelsthat was never registered, and the renderedDataTable.razorreferencedSystem.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 withBlazor-ApexCharts— that's why branch 1's CI smoke test had a manualdotnet add packageworkaround.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— newNuGetDependencieslist. Templates declare runtime NuGet deps the same way they declare source-file deps:The chart family (
pie-chart,bar-chart,area-chart,line-chart,multi-series-chart) all transitively depend onchart, so they inherit the package through the recursive installer walk without needing to declare it themselves.Installer runs
dotnet add packagesrc/ShellUI.CLI/Services/ComponentInstaller.cs— the recursive dep walk now collectsNuGetDependenciesinto a deduped batch andInstallNuGetDependenciesAsyncinvokesdotnet 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— newFindClosestMatch(query)using two-row Levenshtein (O(n·m) time, O(min(n,m)) space). Returns the closest installable component name within edit distance 3, ornullif nothing's close. Hidden sub-components (IsAvailable = false) are excluded — we never suggest installing internal deps directly.ComponentInstallercalls it whenComponentRegistry.Exists(name) == false. So:data-table-models gets registered
src/ShellUI.Templates/ComponentRegistry.cs—data-table-modelsadded to both theComponentsdictionary and theGetComponentContentswitch.src/ShellUI.Templates/Templates/DataTableModelsTemplate.cs—IsAvailable = falseso it doesn't polluteshellui listand isn't suggested by the typo helper (it's only ever pulled in as a dep ofdata-table).Tests (16 new)
ShellUI.Tests/NuGetDepsAndSuggestionsTests.cs:FindClosestMatchreturns expected suggestions for 5 realistic typos (datatable,data_table,buttong,chrt,themetoggle)nullfor exact matches (the caller already knows the component exists)nullwhen nothing is close enoughdata-table-modelsdata-table-modelsis registered andIsAvailable = falsedata-tabledeclaresSystem.Linq.Dynamic.CorechartdeclaresBlazor-ApexChartschart(transitive inheritance proof)data-table@usinganddata-table-modelsnamespaceagree onComponents.Models(the library-wide convention used by Tab, Stepper, ContextMenu, Command, ChartModels — verified with a repo-wide grep, not theComponents.UI.Modelsform I initially tried and reverted)CI smoke step asserts the auto-install
.github/workflows/ci.yml— dropped the manualdotnet add package Blazor-ApexChartsworkaround from branch 1. The smoke step nowgreps the produced.csprojto confirm bothBlazor-ApexChartsandSystem.Linq.Dynamic.Coreappear (auto-installed byshellui add chart/data-table), and assertsComponents/UI/Models/DataTableModels.csexists.Verification
dotnet test ShellUI.Tests— 43/43 passing (16 new + 27 from previous branches)dotnet build src/ShellUI.CLI— cleanTest plan
dotnet new blazor→shellui init→shellui add data-table→dotnet buildsucceeds with no missing references. ConfirmComponents/UI/Models/DataTableModels.csexists and<PackageReference Include="System.Linq.Dynamic.Core" />was added to the.csproj.shellui add chart→dotnet buildsucceeds, no manual NuGet step needed.shellui add datatable(no hyphen) → error message saysDid you mean 'data-table'?