@@ -33,6 +33,7 @@ export class SideNav implements OnInit, OnDestroy {
3333 selectedTagInternal = '' ;
3434 selectedHostInternal = '' ;
3535 selectedHostsInternal : string [ ] = [ ] ;
36+ selectedHostsPending : string [ ] = [ ] ;
3637 selectedModuleInternal = '' ;
3738 navigationParams : { [ key : string ] : string | boolean } = { } ;
3839 multiHostEnabledTools : string [ ] = [ 'trace_viewer' , 'trace_viewer@' ] ;
@@ -141,10 +142,14 @@ export class SideNav implements OnInit, OnDestroy {
141142 this . selectedTagInternal = tag ;
142143 this . selectedModuleInternal = moduleName ;
143144
144- if ( hostsParam ) {
145- this . selectedHostsInternal = hostsParam . split ( ',' ) ;
145+ if ( this . isMultiHostsEnabled ) {
146+ if ( hostsParam ) {
147+ this . selectedHostsInternal = hostsParam . split ( ',' ) ;
148+ }
149+ this . selectedHostsPending = [ ...this . selectedHostsInternal ] ;
150+ } else {
151+ this . selectedHostInternal = host ;
146152 }
147- this . selectedHostInternal = host ;
148153 this . update ( ) ;
149154 }
150155
@@ -168,7 +173,7 @@ export class SideNav implements OnInit, OnDestroy {
168173 ...this . navigationParams ,
169174 } ;
170175 if ( this . isMultiHostsEnabled ) {
171- navigationEvent . hosts = this . selectedHosts ;
176+ navigationEvent . hosts = this . selectedHostsInternal ;
172177 } else {
173178 navigationEvent . host = this . selectedHost ;
174179 }
@@ -258,9 +263,35 @@ export class SideNav implements OnInit, OnDestroy {
258263 this . afterUpdateTag ( ) ;
259264 }
260265
261- onTagSelectionChange ( tag : string ) {
266+ async onTagSelectionChange ( tag : string ) {
267+ const previousSelectedTag = this . selectedTagInternal ;
262268 this . selectedTagInternal = tag ;
263- this . afterUpdateTag ( ) ;
269+
270+ const isChangingToMultiHost = ! previousSelectedTag ||
271+ ( this . isMultiHostsEnabled && previousSelectedTag !== this . selectedTag ) ;
272+
273+ this . selectedHostsInternal = [ ] ;
274+ this . selectedHostsPending = [ ] ;
275+ this . selectedHostInternal = '' ;
276+
277+ if ( isChangingToMultiHost ) {
278+ this . hosts = await this . getHostsForSelectedTag ( ) ;
279+ if ( this . hosts . length > 0 ) {
280+ this . selectedHostsInternal = [ this . hosts [ 0 ] ] ;
281+ } else {
282+ this . selectedHostsInternal = [ ] ;
283+ }
284+ this . selectedHostsPending = [ ...this . selectedHostsInternal ] ;
285+
286+ if ( this . is_hlo_tool ) {
287+ this . moduleList = await this . getModuleListForSelectedTag ( ) ;
288+ }
289+
290+ this . navigateTools ( ) ;
291+
292+ } else {
293+ this . afterUpdateTag ( ) ;
294+ }
264295 }
265296
266297 afterUpdateTag ( ) {
@@ -271,8 +302,17 @@ export class SideNav implements OnInit, OnDestroy {
271302 // Keep them under the same update function as initial step of the separation.
272303 async updateHosts ( ) {
273304 this . hosts = await this . getHostsForSelectedTag ( ) ;
274- this . selectedHostsInternal = [ this . hosts [ 0 ] ] ;
275- this . selectedHostInternal = this . hosts [ 0 ] ;
305+
306+ if ( this . isMultiHostsEnabled ) {
307+ if ( this . selectedHostsInternal . length === 0 && this . hosts . length > 0 ) {
308+ this . selectedHostsInternal = [ this . hosts [ 0 ] ] ;
309+ }
310+ this . selectedHostsPending = [ ...this . selectedHostsInternal ] ;
311+ } else {
312+ if ( ! this . selectedHostInternal && this . hosts . length > 0 ) {
313+ this . selectedHostInternal = this . hosts [ 0 ] ;
314+ }
315+ }
276316 if ( this . is_hlo_tool ) {
277317 this . moduleList = await this . getModuleListForSelectedTag ( ) ;
278318 }
@@ -282,13 +322,16 @@ export class SideNav implements OnInit, OnDestroy {
282322
283323 onHostSelectionChange ( selection : string ) {
284324 this . selectedHostInternal = selection ;
285- this . selectedHostsInternal = [ ] ;
286325 this . navigateTools ( ) ;
287326 }
288327
289328 onHostsSelectionChange ( selection : string [ ] ) {
290- this . selectedHostsInternal = selection ;
291- this . selectedHostInternal = '' ; // Ensure single-host is empty
329+ this . selectedHostsPending =
330+ Array . isArray ( selection ) ? selection : [ selection ] ;
331+ }
332+
333+ onSubmitHosts ( ) {
334+ this . selectedHostsInternal = [ ...this . selectedHostsPending ] ;
292335 this . navigateTools ( ) ;
293336 }
294337
@@ -298,7 +341,9 @@ export class SideNav implements OnInit, OnDestroy {
298341 }
299342
300343 afterUpdateHost ( ) {
301- this . navigateTools ( ) ;
344+ if ( ! this . isMultiHostsEnabled ) {
345+ this . navigateTools ( ) ;
346+ }
302347 }
303348
304349 // Helper function to serialize query parameters
0 commit comments