mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-10-19 05:18:50 +00:00
feat(ui): type the namespace when the cluster does not list them (#84)
Some users cannot list namespaces on a cluster. The add wizard showed an error and offered no way forward. The namespace step now switches to a text prompt when the list call fails or returns nothing. The prompt shows the reason and checks that the name is a valid DNS label. Esc from a later step returns to the prompt. The j and k keys now type into text fields. They moved the list cursor before, so a name such as kube-system could not be typed. Closes #66
This commit is contained in:
@@ -142,6 +142,10 @@ func (m model) renderSelectNamespace() string {
|
||||
b.WriteString(renderHeader("Add Port Forward", renderProgress(2, 7)))
|
||||
fmt.Fprintf(&b, "Context: %s\n\n", breadcrumbStyle.Render(wizard.selectedContext))
|
||||
|
||||
if wizard.namespaceManual {
|
||||
return m.renderManualNamespace(&b)
|
||||
}
|
||||
|
||||
b.WriteString("Select Namespace:\n\n")
|
||||
|
||||
// Show search input if there's a filter active
|
||||
@@ -177,6 +181,32 @@ func (m model) renderSelectNamespace() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// renderManualNamespace shows a free-text namespace prompt for clusters where
|
||||
// the namespace list is not available to the user.
|
||||
func (m model) renderManualNamespace(b *strings.Builder) string {
|
||||
wizard := m.ui.addWizard
|
||||
|
||||
b.WriteString("Enter Namespace:\n\n")
|
||||
if wizard.namespaceListErr != nil {
|
||||
b.WriteString(mutedStyle.Render(fmt.Sprintf("Could not list namespaces (%v).", wizard.namespaceListErr)))
|
||||
} else {
|
||||
b.WriteString(mutedStyle.Render("No namespaces found."))
|
||||
}
|
||||
b.WriteString("\n")
|
||||
b.WriteString(mutedStyle.Render("Type the namespace name instead."))
|
||||
b.WriteString("\n\n")
|
||||
|
||||
b.WriteString(renderTextInput("Namespace: ", wizard.textInput, wizard.textInput != ""))
|
||||
b.WriteString("\n")
|
||||
if wizard.error != nil {
|
||||
b.WriteString(errorStyle.Render(fmt.Sprintf("✗ %v\n", wizard.error)))
|
||||
}
|
||||
|
||||
b.WriteString("\n")
|
||||
b.WriteString(wrapHelpText("Enter: Continue Esc: Back Ctrl+C: Cancel", wizardHelpWidth(m.termWidth)))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (m model) renderSelectResourceType() string {
|
||||
wizard := m.ui.addWizard
|
||||
var b strings.Builder
|
||||
|
||||
Reference in New Issue
Block a user