Skip to content

Commit

Permalink
Fix exception when unselecting application on metrics page (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Oct 18, 2023
1 parent 4ea75fb commit 915c0c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class ChartContainer : ComponentBase, IAsyncDisposable

protected override void OnInitialized()
{
// Update the graph every 200ms. This displays the latest data and moves time forward.
_tickTimer = new PeriodicTimer(TimeSpan.FromSeconds(0.2));
_tickTask = Task.Run(UpdateDataAsync);
}
Expand All @@ -50,22 +51,22 @@ public async ValueTask DisposeAsync()
// Wait for UpdateData to complete.
if (_tickTask is { } t)
{
await t.ConfigureAwait(false);
await t;
}
}

private async Task UpdateDataAsync()
{
var timer = _tickTimer;
while (await timer!.WaitForNextTickAsync().ConfigureAwait(false))
while (await timer!.WaitForNextTickAsync())
{
_instrument = GetInstrument();

if (_instrument.Dimensions.Count > _renderedDimensionsCount)
{
// Re-render the entire control if the number of dimensions has changed.
_renderedDimensionsCount = _instrument.Dimensions.Count;
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
await InvokeAsync(StateHasChanged);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Dashboard/Components/Pages/Metrics.razor
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
</Panel1>
<Panel2>
<div class="metrics-content">
@if (_selectedInstrument != null)
@if (_selectedApplication.Id != null && _selectedMeter != null && _selectedInstrument != null)
{
<ChartContainer ApplicationId="@(_selectedApplication.Id)" MeterName="@(_selectedMeter?.MeterName)" InstrumentName="@(_selectedInstrument.Name)" Duration="_selectedDuration.Duration" />
<ChartContainer ApplicationId="@(_selectedApplication.Id)" MeterName="@(_selectedMeter.MeterName)" InstrumentName="@(_selectedInstrument.Name)" Duration="_selectedDuration.Duration" />
}
else if (_selectedMeter != null)
{
Expand Down
10 changes: 6 additions & 4 deletions src/Aspire.Dashboard/Components/Pages/Metrics.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected override Task OnInitializedAsync()

protected override void OnParametersSet()
{
_selectedApplication = _applications.SingleOrDefault(e => e.Id == ApplicationInstanceId) ?? _applications.ElementAtOrDefault(1) ?? s_selectApplication;
_selectedApplication = _applications.SingleOrDefault(e => e.Id == ApplicationInstanceId) ?? s_selectApplication;
ViewModel.ApplicationServiceId = _selectedApplication.Id;
_instruments = !string.IsNullOrEmpty(_selectedApplication.Id) ? TelemetryRepository.GetInstrumentsSummary(_selectedApplication.Id) : null;

Expand Down Expand Up @@ -105,10 +105,12 @@ private void UpdateApplications()
UpdateSubscription();
}

private Task HandleSelectedApplicationChangedAsync()
private async Task HandleSelectedApplicationChangedAsync()
{
NavigationManager.NavigateTo($"/Metrics/{_selectedApplication.Id}");
return Task.CompletedTask;
var state = new MetricsSelectedState { ApplicationId = _selectedApplication.Id };

NavigateTo(state);
await ProtectedSessionStore.SetAsync(MetricsSelectedState.Key, state);
}

private sealed class MetricsSelectedState
Expand Down

0 comments on commit 915c0c0

Please sign in to comment.