@@ -309,8 +309,8 @@ def _create_widgets(self):
309
309
full_layout = widgets .Layout (width = "100%" )
310
310
# Configuration selector with add button
311
311
self .config_dropdown = widgets .Dropdown (
312
- options = list ( self . configs . keys ()),
313
- value = list ( self . configs . keys ())[ 0 ] if self . configs else None ,
312
+ options = [], # Will be populated by _update_config_dropdown
313
+ value = None ,
314
314
description = "Active Config:" ,
315
315
style = style ,
316
316
layout = widgets .Layout (width = "70%" ),
@@ -340,6 +340,7 @@ def _create_widgets(self):
340
340
style = style ,
341
341
layout = full_layout ,
342
342
)
343
+ self .config_name .observe (self ._on_config_name_change , names = "value" )
343
344
# Advanced options
344
345
self ._create_advanced_options ()
345
346
# Save configuration section
@@ -361,10 +362,44 @@ def _create_widgets(self):
361
362
self .delete_btn .on_click (self ._on_delete_config )
362
363
# Status output
363
364
self .status_output = widgets .Output ()
364
- # Load initial configuration
365
+ # Update dropdown and load initial configuration
366
+ self ._update_config_dropdown ()
365
367
if self .configs :
366
368
self ._load_config_to_widgets (list (self .configs .keys ())[0 ])
367
369
370
+ def _update_config_dropdown (self ):
371
+ """Update the configuration dropdown with current config names."""
372
+ if not self .configs :
373
+ self .config_dropdown .options = []
374
+ self .config_dropdown .value = None
375
+ return
376
+
377
+ # Create options list with display names and config keys
378
+ options = []
379
+ for config_key , config_data in self .configs .items ():
380
+ display_name = config_data .get ("name" , config_key )
381
+ options .append ((display_name , config_key ))
382
+
383
+ # Store current selection
384
+ current_value = self .config_dropdown .value
385
+
386
+ # Update options
387
+ self .config_dropdown .options = options
388
+
389
+ # Restore selection if it still exists
390
+ if current_value and current_value in [opt [1 ] for opt in options ]:
391
+ self .config_dropdown .value = current_value
392
+ elif options :
393
+ self .config_dropdown .value = options [0 ][1 ]
394
+
395
+ def _on_config_name_change (self , change ):
396
+ """Handle changes to the config name field."""
397
+ if self .current_config_name and self .current_config_name in self .configs :
398
+ # Update the name in the current configuration
399
+ self .configs [self .current_config_name ]["name" ] = change ["new" ]
400
+ # Update the dropdown to reflect the new display name
401
+ self ._update_config_dropdown ()
402
+
368
403
def _create_dynamic_fields (self ):
369
404
"""Create dynamic fields that change based on cluster type."""
370
405
style = {"description_width" : "120px" }
@@ -686,7 +721,7 @@ def _on_add_config(self, button):
686
721
"default_time" : "01:00:00" ,
687
722
}
688
723
# Update dropdown
689
- self .config_dropdown . options = list ( self . configs . keys () )
724
+ self ._update_config_dropdown ( )
690
725
self .config_dropdown .value = config_name
691
726
print (f"✅ Created new configuration: { config_name } " )
692
727
@@ -705,8 +740,9 @@ def _on_delete_config(self, button):
705
740
if self .current_config_name in self .config_file_map :
706
741
del self .config_file_map [self .current_config_name ]
707
742
# Update dropdown
708
- self .config_dropdown .options = list (self .configs .keys ())
709
- self .config_dropdown .value = list (self .configs .keys ())[0 ]
743
+ self ._update_config_dropdown ()
744
+ if self .configs :
745
+ self .config_dropdown .value = list (self .configs .keys ())[0 ]
710
746
print (f"✅ Deleted configuration: { self .current_config_name } " )
711
747
712
748
def _on_apply_config (self , button ):
@@ -736,7 +772,7 @@ def _on_apply_config(self, button):
736
772
self .current_config_name = new_config_name
737
773
738
774
# Update the config dropdown to reflect the new name
739
- self .config_dropdown . options = list ( self . configs . keys () )
775
+ self ._update_config_dropdown ( )
740
776
self .config_dropdown .value = self .current_config_name
741
777
# Prepare config for application
742
778
apply_config = config .copy ()
@@ -817,7 +853,7 @@ def _on_save_config(self, button):
817
853
self .save_file_dropdown .options = file_options
818
854
819
855
# Update the config dropdown to reflect the new name
820
- self .config_dropdown . options = list ( self . configs . keys () )
856
+ self ._update_config_dropdown ( )
821
857
self .config_dropdown .value = self .current_config_name
822
858
except Exception as e :
823
859
print (f"❌ Error saving configuration: { str (e )} " )
0 commit comments