Skip to content

Consistent resource colors, resource colors match dashboard#14832

Merged
JamesNK merged 5 commits intorelease/13.2from
jamesnk/resource-color-2
Mar 3, 2026
Merged

Consistent resource colors, resource colors match dashboard#14832
JamesNK merged 5 commits intorelease/13.2from
jamesnk/resource-color-2

Conversation

@JamesNK
Copy link
Member

@JamesNK JamesNK commented Mar 2, 2026

Description

Resource color assignment is based on the order resource color is resolved. That can change based on filtered data.

PR changes:

  • The dashboard and CLI resolve all known resource names at start up so it doesn't matter how resources are displayed
  • The CLI uses the same colors as the dashboard for resources

Fixes #14292

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@JamesNK JamesNK marked this pull request as ready for review March 2, 2026 01:49
Copilot AI review requested due to automatic review settings March 2, 2026 01:49
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14832

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14832"

Copy link
Contributor

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 fixes a bug where resource colors could change depending on encounter order (e.g., when filtering resources). The fix pre-resolves all known resource names sorted alphabetically at startup so that color index assignments are deterministic, regardless of which resources are displayed or the order they are returned.

Changes:

  • Moves ColorGenerator to a shared file (namespace Aspire) compiled into both the dashboard and CLI, and adds a ResolveAll(IEnumerable<string> keys) method that pre-sorts and resolves colors for all known resource names
  • Updates ResourceColorMap in the CLI to use ColorGenerator and maps CSS accent variable names to dark-theme hex colors matching the dashboard palette for visual consistency
  • Updates DashboardClient (dashboard) and LogsCommand/DescribeCommand (CLI) to call ResolveAll at startup with all resource display names; also refactors DescribeCommand to fetch snapshots and dashboard URL in parallel and pass them to both paths

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Shared/ColorGenerator.cs Namespace changed from Aspire.Dashboard.Otlp.Model to Aspire; exposed s_variableNames and GetColorIndex as internal; added public ResolveAll method
src/Aspire.Dashboard/ServiceClient/DashboardClient.cs Calls ColorGenerator.Instance.ResolveAll() inside the resource-watch lock after each batch of changes
src/Aspire.Dashboard/Aspire.Dashboard.csproj Adds shared ColorGenerator.cs to compile items
src/Aspire.Dashboard/Components/_Imports.razor Adds @using Aspire to make ColorGenerator accessible in Razor components
src/Aspire.Dashboard/Model/ResourceGraph/ResourceGraphMapper.cs Removes now-unneeded using Aspire.Dashboard.Otlp.Model
src/Aspire.Dashboard/Model/Assistant/Markdown/ResourceInlineRenderer.cs Removes now-unneeded using Aspire.Dashboard.Otlp.Model
src/Aspire.Cli/Utils/ResourceColorMap.cs Replaces static Spectre Color[] with a ColorGenerator-backed palette; maps CSS variables to dashboard dark-theme hex values
src/Aspire.Cli/Aspire.Cli.csproj Adds shared ColorGenerator.cs to compile items
src/Aspire.Cli/Commands/LogsCommand.cs Calls _resourceColorMap.ResolveAll() after fetching the initial snapshot list
src/Aspire.Cli/Commands/DescribeCommand.cs Fetches snapshots and dashboard URLs in parallel; calls ResolveAll; refactors ExecuteSnapshotAsync to sync ExecuteSnapshot and ExecuteWatchAsync to accept pre-fetched data
tests/Aspire.Cli.Tests/Utils/ResourceColorMapTests.cs New test file covering key matching, determinism, and uniqueness of color assignment

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit a6d6084:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22601324541

@JamesNK JamesNK force-pushed the jamesnk/resource-color-2 branch from d0f4094 to 6858846 Compare March 2, 2026 23:27
Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

Clean fix — ResolveAll() ensures deterministic color assignment regardless of encounter order. Good that CLI and dashboard now share the same palette via ColorGenerator. Tests verify determinism nicely.

@JamesNK JamesNK merged commit ce61ece into release/13.2 Mar 3, 2026
682 of 685 checks passed
@JamesNK JamesNK deleted the jamesnk/resource-color-2 branch March 3, 2026 04:37
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants