Skip to content

Commit

Permalink
Update display name and description for built-in lifecycle commands (#…
Browse files Browse the repository at this point in the history
…7334)

* Update display name and description for built-in lifecycle commands

* add compile items

* Add additional localizations

* pass localizer to opendialogasync, add KnownResourceCommands

---------

Co-authored-by: Adam Ratzman <[email protected]>
  • Loading branch information
adamint and Adam Ratzman authored Feb 7, 2025
1 parent 05f988f commit 9e52dff
Show file tree
Hide file tree
Showing 43 changed files with 901 additions and 51 deletions.
25 changes: 19 additions & 6 deletions src/Aspire.Dashboard/Aspire.Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<Protobuf Include="Otlp\**\*.proto">
<ProtoRoot>Otlp</ProtoRoot>
</Protobuf>

<Protobuf Include="..\Aspire.Hosting\Dashboard\proto\resource_service.proto">
<Access>Internal</Access>
<Link>ResourceService\resource_service.proto</Link>
Expand Down Expand Up @@ -65,6 +65,16 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Columns.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Columns.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Commands.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Commands.resx</DependentUpon>
</Compile>
<Compile Update="Resources\ControlsStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand All @@ -85,11 +95,6 @@
<AutoGen>True</AutoGen>
<DependentUpon>Layout.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Columns.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Columns.resx</DependentUpon>
</Compile>
<Compile Update="Resources\Metrics.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -224,6 +229,13 @@
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>StructuredFiltering.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Commands.resx">
<XlfSourceFormat>Resx</XlfSourceFormat>
<XlfOutputItem>EmbeddedResource</XlfOutputItem>
<SubType>Designer</SubType>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Commands.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Expand All @@ -235,6 +247,7 @@
<Compile Include="$(SharedDir)StringComparers.cs" Link="Utils\StringComparers.cs" />
<Compile Include="$(SharedDir)TaskHelpers.cs" Link="Utils\TaskHelpers.cs" />
<Compile Include="$(SharedDir)Model\KnownProperties.cs" Link="Utils\KnownProperties.cs" />
<Compile Include="$(SharedDir)Model\KnownResourceCommands.cs" Link="Utils\KnownResourceCommands.cs" />
<Compile Include="$(SharedDir)Model\KnownResourceTypes.cs" Link="Utils\KnownResourceTypes.cs" />
<Compile Include="$(SharedDir)CircularBuffer.cs" Link="Otlp\Storage\CircularBuffer.cs" />
<Compile Include="$(SharedDir)DashboardConfigNames.cs" Link="Utils\DashboardConfigNames.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private async Task OpenExemplarsDialogAsync(MetricViewBase metric)
{
Title = DialogsLoc[nameof(Resources.Dialogs.ExemplarsDialogTitle)],
PrimaryAction = DialogsLoc[nameof(Resources.Dialogs.DialogCloseButtonText)],
DismissTitle = DialogsLoc[nameof(Resources.Dialogs.DialogCloseButtonText)],
SecondaryAction = string.Empty,
Width = "800px",
Height = "auto"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@namespace Aspire.Dashboard.Components

@using Aspire.Dashboard.Extensions
@using Aspire.Dashboard.Components.Dialogs
@using Aspire.Dashboard.Otlp.Model
@using Aspire.Dashboard.Resources

@inject IStringLocalizer<ControlsStrings> Loc
@inject IStringLocalizer<Dashboard.Resources.Dialogs> DialogsLoc

@if (!string.IsNullOrWhiteSpace(ExceptionText))
{
Expand All @@ -30,6 +29,6 @@

private void OnExceptionDetailsClicked(MouseEventArgs e)
{
_ = TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, Loc[nameof(ControlsStrings.ExceptionDetailsTitle)], ExceptionText);
_ = TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, DialogsLoc, Loc[nameof(ControlsStrings.ExceptionDetailsTitle)], ExceptionText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ private async Task ToggleMaskStateAsync()

private async Task OpenTextVisualizerAsync()
{
await TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, ValueDescription, ValueToVisualize ?? Value ?? string.Empty);
await TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, DialogsLoc, ValueDescription, ValueToVisualize ?? Value ?? string.Empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class StructuredLogActions : ComponentBase
[Inject]
public required IStringLocalizer<Resources.ControlsStrings> ControlsLoc { get; set; }

[Inject]
public required IStringLocalizer<Resources.Dialogs> DialogsLoc { get; set; }

[Inject]
public required IDialogService DialogService { get; set; }

Expand Down Expand Up @@ -55,7 +58,7 @@ protected override void OnParametersSet()
OnClick = async () =>
{
var header = Loc[nameof(Resources.StructuredLogs.StructuredLogsMessageColumnHeader)];
await TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, header, LogEntry.Message);
await TextVisualizerDialog.OpenDialogAsync(ViewportInformation, DialogService, DialogsLoc, header, LogEntry.Message);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>

<div>
<span class="setting-title">Dashboard telemetry</span>
<span class="setting-title">@Loc[nameof(Dialogs.SettingsDashboardTelemetry)]</span>
<div>
<FluentButton IconStart="@(new Icons.Regular.Size16.Delete())"
OnClick="ClearAllSignals"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Aspire.Dashboard.Model;
using Aspire.Dashboard.Model.Otlp;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.FluentUI.AspNetCore.Components;
using Microsoft.JSInterop;

Expand Down Expand Up @@ -263,12 +264,13 @@ public async ValueTask DisposeAsync()

public record StringLogLine(int LineNumber, string Content, bool IsFormatted);

public static async Task OpenDialogAsync(ViewportInformation viewportInformation, IDialogService dialogService, string valueDescription, string value)
public static async Task OpenDialogAsync(ViewportInformation viewportInformation, IDialogService dialogService, IStringLocalizer<Resources.Dialogs> dialogsLoc, string valueDescription, string value)
{
var width = viewportInformation.IsDesktop ? "75vw" : "100vw";
var parameters = new DialogParameters
{
Title = valueDescription,
DismissTitle = dialogsLoc[nameof(Resources.Dialogs.DialogCloseButtonText)],
Width = $"min(1000px, {width})",
TrapFocus = true,
Modal = true,
Expand Down
22 changes: 21 additions & 1 deletion src/Aspire.Dashboard/ResourceService/Partials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using Aspire.Dashboard.Model;
using Aspire.Hosting.Dashboard;
using FluentUIIconVariant = Microsoft.FluentUI.AspNetCore.Components.IconVariant;
using CommandsResources = Aspire.Dashboard.Resources.Commands;

namespace Aspire.ResourceService.Proto.V1;

Expand Down Expand Up @@ -107,8 +109,25 @@ ImmutableArray<VolumeViewModel> GetVolumes()
ImmutableArray<CommandViewModel> GetCommands()
{
return Commands
.Select(c => new CommandViewModel(c.Name, MapState(c.State), c.DisplayName, c.DisplayDescription, c.ConfirmationMessage, c.Parameter, c.IsHighlighted, c.IconName, MapIconVariant(c.IconVariant)))
.Select(c =>
{
var (displayName, displayDescription) = GetDisplayNameAndDescription(c.Name, c.DisplayName, c.DisplayDescription);
return new CommandViewModel(c.Name, MapState(c.State), displayName, displayDescription, c.ConfirmationMessage, c.Parameter, c.IsHighlighted, c.IconName, MapIconVariant(c.IconVariant));
})
.ToImmutableArray();

// Use custom localizations for built-in lifecycle commands
static (string DisplayName, string DisplayDescription) GetDisplayNameAndDescription(string commandName, string displayName, string description)
{
return commandName switch
{
KnownResourceCommands.StartCommand => (CommandsResources.StartCommandDisplayName, CommandsResources.StartCommandDisplayDescription),
KnownResourceCommands.StopCommand => (CommandsResources.StopCommandDisplayName, CommandsResources.StopCommandDisplayDescription),
KnownResourceCommands.RestartCommand => (CommandsResources.RestartCommandDisplayName, CommandsResources.RestartCommandDisplayDescription),
_ => (displayName, description)
};
}

static CommandViewModelState MapState(ResourceCommandState state)
{
return state switch
Expand All @@ -119,6 +138,7 @@ static CommandViewModelState MapState(ResourceCommandState state)
_ => throw new InvalidOperationException("Unknown state: " + state),
};
}

static FluentUIIconVariant MapIconVariant(IconVariant iconVariant)
{
return iconVariant switch
Expand Down
116 changes: 116 additions & 0 deletions src/Aspire.Dashboard/Resources/Commands.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9e52dff

Please sign in to comment.