Skip to content

Commit 9078091

Browse files
jeremymanningclaude
andcommitted
Implement conditional section visibility for Connection and Kubernetes Settings
- Hide entire Connection Settings section for local cluster type - Hide entire Kubernetes Settings section for non-Kubernetes cluster types - Show Connection Settings only for remote clusters (ssh, slurm, pbs, sge) - Show Kubernetes Settings only for kubernetes cluster type - Create section containers early in widget initialization - Replace individual field hiding with section-level visibility control Addresses issue #25 - Connection Settings should only appear for remote configs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 19b18ad commit 9078091

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

clustrix/notebook_magic.py

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ def _create_widgets(self):
345345
self._create_advanced_options()
346346
# Save configuration section
347347
self._create_save_section()
348+
# Create section containers
349+
self._create_section_containers()
348350
# Action buttons
349351
self.apply_btn = widgets.Button(
350352
description="Apply Configuration",
@@ -563,6 +565,25 @@ def _create_save_section(self):
563565
)
564566
self.save_btn.on_click(self._on_save_config)
565567

568+
def _create_section_containers(self):
569+
"""Create the main UI section containers."""
570+
# Connection fields (dynamically shown/hidden)
571+
self.connection_fields = widgets.VBox(
572+
[
573+
widgets.HTML("<h5>Connection Settings</h5>"),
574+
self.host_field,
575+
widgets.HBox([self.username_field, self.ssh_key_field]),
576+
self.port_field,
577+
]
578+
)
579+
# Kubernetes fields
580+
self.k8s_fields = widgets.VBox(
581+
[
582+
widgets.HTML("<h5>Kubernetes Settings</h5>"),
583+
widgets.HBox([self.k8s_namespace, self.k8s_image]),
584+
]
585+
)
586+
566587
def _validate_host(self, change):
567588
"""Validate host field input."""
568589
value = change["new"]
@@ -573,36 +594,24 @@ def _validate_host(self, change):
573594
self.host_field.layout.border = ""
574595

575596
def _on_cluster_type_change(self, change):
576-
"""Handle cluster type change to show/hide relevant fields."""
597+
"""Handle cluster type change to show/hide relevant sections."""
577598
cluster_type = change["new"]
578-
# Update field visibility based on cluster type
599+
# Update section visibility based on cluster type
579600
if cluster_type == "local":
580-
# Hide remote-specific fields
581-
self.host_field.layout.display = "none"
582-
self.username_field.layout.display = "none"
583-
self.ssh_key_field.layout.display = "none"
584-
self.port_field.layout.display = "none"
601+
# Hide both remote-specific sections
602+
self.connection_fields.layout.display = "none"
603+
self.k8s_fields.layout.display = "none"
585604
self.work_dir_field.layout.display = "none"
586-
self.k8s_namespace.layout.display = "none"
587-
self.k8s_image.layout.display = "none"
588605
elif cluster_type == "kubernetes":
589-
# Show Kubernetes-specific fields
590-
self.host_field.layout.display = ""
591-
self.username_field.layout.display = "none"
592-
self.ssh_key_field.layout.display = "none"
593-
self.port_field.layout.display = ""
606+
# Show Kubernetes-specific fields, hide SSH connection fields
607+
self.connection_fields.layout.display = "none"
608+
self.k8s_fields.layout.display = ""
594609
self.work_dir_field.layout.display = ""
595-
self.k8s_namespace.layout.display = ""
596-
self.k8s_image.layout.display = ""
597610
else: # ssh, slurm, pbs, sge
598-
# Show SSH-based fields
599-
self.host_field.layout.display = ""
600-
self.username_field.layout.display = ""
601-
self.ssh_key_field.layout.display = ""
602-
self.port_field.layout.display = ""
611+
# Show SSH-based connection fields, hide Kubernetes fields
612+
self.connection_fields.layout.display = ""
613+
self.k8s_fields.layout.display = "none"
603614
self.work_dir_field.layout.display = ""
604-
self.k8s_namespace.layout.display = "none"
605-
self.k8s_image.layout.display = "none"
606615

607616
def _load_config_to_widgets(self, config_name: str):
608617
"""Load a configuration into the widgets."""
@@ -877,22 +886,6 @@ def display(self):
877886
self.cluster_type,
878887
]
879888
)
880-
# Connection fields (dynamically shown/hidden)
881-
connection_fields = widgets.VBox(
882-
[
883-
widgets.HTML("<h5>Connection Settings</h5>"),
884-
self.host_field,
885-
widgets.HBox([self.username_field, self.ssh_key_field]),
886-
self.port_field,
887-
]
888-
)
889-
# Kubernetes fields
890-
k8s_fields = widgets.VBox(
891-
[
892-
widgets.HTML("<h5>Kubernetes Settings</h5>"),
893-
widgets.HBox([self.k8s_namespace, self.k8s_image]),
894-
]
895-
)
896889
# Resource fields
897890
resource_fields = widgets.VBox(
898891
[
@@ -921,8 +914,8 @@ def display(self):
921914
config_section,
922915
widgets.HTML("<hr>"),
923916
basic_fields,
924-
connection_fields,
925-
k8s_fields,
917+
self.connection_fields,
918+
self.k8s_fields,
926919
resource_fields,
927920
self.advanced_accordion,
928921
widgets.HTML("<hr>"),

0 commit comments

Comments
 (0)