@@ -126,8 +126,8 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
126
126
{
127
127
viewModel . SelectedDuration = _durations . SingleOrDefault ( d => ( int ) d . Id . TotalMinutes == DurationMinutes ) ?? _durations . Single ( d => d . Id == s_defaultDuration ) ;
128
128
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 ) ;
131
131
132
132
viewModel . SelectedMeter = null ;
133
133
viewModel . SelectedInstrument = null ;
@@ -144,6 +144,12 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
144
144
return Task . CompletedTask ;
145
145
}
146
146
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
+
147
153
private void UpdateApplications ( )
148
154
{
149
155
_applications = TelemetryRepository . GetApplications ( ) ;
@@ -154,22 +160,26 @@ private void UpdateApplications()
154
160
155
161
private async Task HandleSelectedApplicationChangedAsync ( )
156
162
{
163
+ UpdateInstruments ( PageViewModel ) ;
164
+
157
165
// The new resource might not have the currently selected meter/instrument.
158
166
// Check whether the new resource has the current values or not, and clear if they're not available.
159
167
if ( PageViewModel . SelectedMeter != null ||
160
168
PageViewModel . SelectedInstrument != null )
161
169
{
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 ) )
166
171
{
167
172
PageViewModel . SelectedMeter = null ;
168
173
PageViewModel . SelectedInstrument = null ;
169
174
}
170
175
}
171
176
172
177
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 ( ) ;
173
183
}
174
184
175
185
private bool ShouldClearSelectedMetrics ( List < OtlpInstrumentSummary > instruments )
0 commit comments