Skip to content

Conversation

sarub0b0
Copy link
Owner

@sarub0b0 sarub0b0 commented Oct 19, 2025

Summary

This PR implements a namespace preservation feature when switching contexts. Users can now maintain their current namespaces across different clusters when the same namespace names exist, enabling smoother transitions without re-selecting namespaces.

Key Changes:

  • Add Ctrl+Space option to preserve current namespaces when switching contexts
  • Implement intelligent fallback handling when namespaces don't exist in the target context

Implementation Details

Message Layer Extension (src/features/context/message.rs:14-20)

  • Add keep_namespace flag to ContextRequest::Set
  • Allow specification of whether to preserve namespaces during context switching

UI Layer Improvements (src/features/context/view/dialog.rs)

  • Normal selection (Enter): Switch to previously used namespaces in the target context (existing behavior, uses store cache)
  • Ctrl+Space: Preserve current namespaces when switching context (new feature)
  • Refactored to reduce code duplication by extracting common helper functions

Controller Layer Logic (src/workers/kube/controller.rs:228-250, 588-622)

  • When keep_namespace: true, pass current namespace list to the next context
  • Verify namespace existence in the new context:
    • All exist: Use them as-is
    • Partial match: Use only available namespaces (respect user intent as much as possible)
    • None exist: Fallback to store cache
  • Output appropriate log information for each case (info/warn levels)

User Experience

Users can switch contexts in two ways:

  1. Enter: Switch to previously used namespaces in the target context (existing behavior, uses store cache)
  2. Ctrl+Space: Preserve current namespaces if they exist, or fallback appropriately (new feature)

Example Use Case

Scenario:

  • prod environment: team-a, team-b, team-c, monitoring
  • dev environment: team-a, team-b, default

When switching from prod to dev while viewing team-a, team-b, team-c:

  • Enter: Switch to previously used namespaces in dev (e.g., default)
  • Ctrl+Space: Show only team-a, team-b (team-c is excluded as it doesn't exist, warning logged)

Additional Improvements

Code Quality

  • Refactored context dialog to reduce code duplication (~50 lines)
  • Extracted common logic into helper functions (clear_widgets_and_close_dialog, switch_context)
  • Removed unused imports for cleaner code

Documentation

  • Added Context Dialog section to in-app help dialog (? key)
  • Updated README.md with Ctrl+Space keybinding documentation
  • Documented the difference between Enter and Ctrl+Space behavior

Test plan

  • Verify namespace preservation when switching between contexts with the same namespaces using Ctrl+Space
  • Verify only available namespaces are shown when switching to a context with partial namespace matches using Ctrl+Space
  • Verify fallback to store cache when switching to a context with no matching namespaces using Ctrl+Space
  • Verify Enter key switching works as before
  • Verify behavior when multiple namespaces are selected

Future Work

When some namespaces are not found, we currently output warnings to logs. In the future, we plan to consider UI notifications as well. (Notification system will be proposed in a separate issue)

@sarub0b0 sarub0b0 force-pushed the 780-when-switching-contexts-use-the-same-namespace-instead-of-default-namespace-if-possible branch from ed76842 to 2b623e4 Compare October 19, 2025 18:44
Implement namespace preservation feature when switching contexts using Ctrl+Space:
- Add keep_namespace flag to ContextRequest::Set
- Support two switching modes: Enter (use cached namespaces) and Ctrl+Space (preserve current namespaces)
- Handle partial namespace matches intelligently (use available ones, fallback to cache if none found)
- Add appropriate logging for each case (info/warn levels)
@sarub0b0 sarub0b0 force-pushed the 780-when-switching-contexts-use-the-same-namespace-instead-of-default-namespace-if-possible branch from 2b623e4 to f4e05c7 Compare October 19, 2025 18:46
Extract common logic into helper functions:
- Add clear_widgets_and_close_dialog for widget cleanup
- Add switch_context to handle context switching logic
- Simplify switch_context_with_namespace and on_select functions
- Remove unused KeyModifiers import

This reduces code duplication by ~50 lines and improves maintainability.
Add documentation for namespace preservation feature:
- Add Context Dialog section to help dialog
- Add Context Dialog subsection to README.md
- Document Enter vs Ctrl+Space behavior difference
@sarub0b0 sarub0b0 merged commit f08aede into main Oct 19, 2025
1 check passed
@sarub0b0 sarub0b0 deleted the 780-when-switching-contexts-use-the-same-namespace-instead-of-default-namespace-if-possible branch October 19, 2025 19:39
sarub0b0 added a commit that referenced this pull request Oct 19, 2025
When PR #853 added modifier key checking for Ctrl+Space support,
it inadvertently blocked Shift key combinations, preventing uppercase
input. This change allows Shift key modifiers while still blocking
Control and Alt key combinations, enabling uppercase character input
while preserving existing keyboard shortcuts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When switching contexts, use the same namespace instead of default namespace if possible

1 participant