upbound / up

The @upbound CLI
Apache License 2.0
49 stars 42 forks source link

ctx: Enable navigation between cloud and disconnected Spaces #546

Closed adamwg closed 1 month ago

adamwg commented 1 month ago

In the root/home screen of up ctx, include "Disconnected Spaces" alongside the list of cloud organizations. The "Disconnected Spaces" section lists all kubeconfig contexts that contain a Space, as determined by either the spaces extension being present in the config, or the mxp ConfigMap being present in the cluster.

Since the home screen is now available regardless of the user's current kubeconfig context, display a message (rather than an error) if we're unable to list organizations from cloud. This ensures that users who aren't logged in (because they use only disconnected Spaces) can still use up ctx.

This also makes it necessary to improve how we handle cursor manipulation in the list view. We programmatically manipulate the cursor in two cases:

  1. When constructing the list of items, to place the cursor below the "back" item in the list if it exists.
  2. When the cursor comes across an unselectable item, to "skip" it.

We now need to also handle unselectable items in case (1), and case (2) didn't correctly handle lists with unselectable items at the beginning or end.

Consolidate this handling by introducing some helper functions that handle the cursor movement and correctly handle the corner cases. We handle unselectable items at the beginning or end of lists by "bouncing" back in the direction the user was moving until we hit a selectable item; in the corner case where all items are unselectable we'll end up with an unselectable item selected, which is probably the best we can do given the constraints of the list library.

Fixes #542

adamwg commented 1 month ago

Opened this by accident when testing a feature in the gh CLI, so marking as draft while I clean it up to be ready for review :smile: