Skip to content

Commit b3fc9d2

Browse files
jeremymanningclaude
andcommitted
Fix dropdown to show current config names dynamically
- Implement _update_config_dropdown() method to show display names in dropdown - Add real-time update when Config Name field changes - Use (display_name, config_key) tuples for dropdown options - Update all dropdown modifications to use the new method - Dropdown now reflects current Config Name field values immediately Addresses issue #24 - dropdown names should match Config Name field 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 600b5d1 commit b3fc9d2

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

clustrix/notebook_magic.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ def _create_widgets(self):
309309
full_layout = widgets.Layout(width="100%")
310310
# Configuration selector with add button
311311
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,
314314
description="Active Config:",
315315
style=style,
316316
layout=widgets.Layout(width="70%"),
@@ -340,6 +340,7 @@ def _create_widgets(self):
340340
style=style,
341341
layout=full_layout,
342342
)
343+
self.config_name.observe(self._on_config_name_change, names="value")
343344
# Advanced options
344345
self._create_advanced_options()
345346
# Save configuration section
@@ -361,10 +362,44 @@ def _create_widgets(self):
361362
self.delete_btn.on_click(self._on_delete_config)
362363
# Status output
363364
self.status_output = widgets.Output()
364-
# Load initial configuration
365+
# Update dropdown and load initial configuration
366+
self._update_config_dropdown()
365367
if self.configs:
366368
self._load_config_to_widgets(list(self.configs.keys())[0])
367369

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+
368403
def _create_dynamic_fields(self):
369404
"""Create dynamic fields that change based on cluster type."""
370405
style = {"description_width": "120px"}
@@ -686,7 +721,7 @@ def _on_add_config(self, button):
686721
"default_time": "01:00:00",
687722
}
688723
# Update dropdown
689-
self.config_dropdown.options = list(self.configs.keys())
724+
self._update_config_dropdown()
690725
self.config_dropdown.value = config_name
691726
print(f"✅ Created new configuration: {config_name}")
692727

@@ -705,8 +740,9 @@ def _on_delete_config(self, button):
705740
if self.current_config_name in self.config_file_map:
706741
del self.config_file_map[self.current_config_name]
707742
# 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]
710746
print(f"✅ Deleted configuration: {self.current_config_name}")
711747

712748
def _on_apply_config(self, button):
@@ -736,7 +772,7 @@ def _on_apply_config(self, button):
736772
self.current_config_name = new_config_name
737773

738774
# Update the config dropdown to reflect the new name
739-
self.config_dropdown.options = list(self.configs.keys())
775+
self._update_config_dropdown()
740776
self.config_dropdown.value = self.current_config_name
741777
# Prepare config for application
742778
apply_config = config.copy()
@@ -817,7 +853,7 @@ def _on_save_config(self, button):
817853
self.save_file_dropdown.options = file_options
818854

819855
# Update the config dropdown to reflect the new name
820-
self.config_dropdown.options = list(self.configs.keys())
856+
self._update_config_dropdown()
821857
self.config_dropdown.value = self.current_config_name
822858
except Exception as e:
823859
print(f"❌ Error saving configuration: {str(e)}")

0 commit comments

Comments
 (0)