Skip to content

Commit a838286

Browse files
authored
Fix metrics instruments not updating in mobile view (#7608)
1 parent c8dd4c3 commit a838286

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/Aspire.Dashboard/Components/Controls/TreeMetricSelector.razor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public partial class TreeMetricSelector
2020

2121
[Inject]
2222
public required TelemetryRepository TelemetryRepository { get; init; }
23+
24+
public void OnResourceChanged()
25+
{
26+
StateHasChanged();
27+
}
2328
}

src/Aspire.Dashboard/Components/Pages/Metrics.razor.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
126126
{
127127
viewModel.SelectedDuration = _durations.SingleOrDefault(d => (int)d.Id.TotalMinutes == DurationMinutes) ?? _durations.Single(d => d.Id == s_defaultDuration);
128128
viewModel.SelectedApplication = _applicationViewModels.GetApplication(Logger, ApplicationName, canSelectGrouping: true, _selectApplication);
129-
var selectedInstance = viewModel.SelectedApplication.Id?.GetApplicationKey();
130-
viewModel.Instruments = selectedInstance != null ? TelemetryRepository.GetInstrumentsSummaries(selectedInstance.Value) : null;
129+
130+
UpdateInstruments(viewModel);
131131

132132
viewModel.SelectedMeter = null;
133133
viewModel.SelectedInstrument = null;
@@ -144,6 +144,12 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
144144
return Task.CompletedTask;
145145
}
146146

147+
private void UpdateInstruments(MetricsViewModel viewModel)
148+
{
149+
var selectedInstance = viewModel.SelectedApplication.Id?.GetApplicationKey();
150+
viewModel.Instruments = selectedInstance != null ? TelemetryRepository.GetInstrumentsSummaries(selectedInstance.Value) : null;
151+
}
152+
147153
private void UpdateApplications()
148154
{
149155
_applications = TelemetryRepository.GetApplications();
@@ -154,22 +160,26 @@ private void UpdateApplications()
154160

155161
private async Task HandleSelectedApplicationChangedAsync()
156162
{
163+
UpdateInstruments(PageViewModel);
164+
157165
// The new resource might not have the currently selected meter/instrument.
158166
// Check whether the new resource has the current values or not, and clear if they're not available.
159167
if (PageViewModel.SelectedMeter != null ||
160168
PageViewModel.SelectedInstrument != null)
161169
{
162-
var selectedInstance = PageViewModel.SelectedApplication.Id?.GetApplicationKey();
163-
var instruments = selectedInstance != null ? TelemetryRepository.GetInstrumentsSummaries(selectedInstance.Value) : null;
164-
165-
if (instruments == null || ShouldClearSelectedMetrics(instruments))
170+
if (PageViewModel.Instruments == null || ShouldClearSelectedMetrics(PageViewModel.Instruments))
166171
{
167172
PageViewModel.SelectedMeter = null;
168173
PageViewModel.SelectedInstrument = null;
169174
}
170175
}
171176

172177
await this.AfterViewModelChangedAsync(_contentLayout, waitToApplyMobileChange: true);
178+
179+
// The mobile view doesn't update the URL when the application changes.
180+
// Because of this, the page doesn't autoamtically use updated instruments.
181+
// Force the metrics tree to update so it re-renders with the new app's instruments.
182+
_treeMetricSelector?.OnResourceChanged();
173183
}
174184

175185
private bool ShouldClearSelectedMetrics(List<OtlpInstrumentSummary> instruments)

src/Aspire.Dashboard/Components/Pages/Metrics.razor.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
}
8787

8888
::deep .metrics-content {
89-
margin-left: 10px;
89+
/* Match left padding of the page header */
90+
margin-left: calc(var(--design-unit)* 4.5px);
9091
}
9192

9293
::deep .plotly-chart-container {

0 commit comments

Comments
 (0)