Skip to content

selection: set Aborted when user cancels TUI picker - #1051

Open
CygnusMaximillian wants to merge 1 commit into
goharbor:mainfrom
CygnusMaximillian:pkg/model.go
Open

selection: set Aborted when user cancels TUI picker#1051
CygnusMaximillian wants to merge 1 commit into
goharbor:mainfrom
CygnusMaximillian:pkg/model.go

Conversation

@CygnusMaximillian

Copy link
Copy Markdown
Contributor

Fixes #947

Summary

Interactive selection views did not record user cancellation correctly. The shared Bubbletea selection model already had an Aborted field, but Update() never set it when users pressed q, esc, or ctrl+c.

This PR handles those keys in the base selection model and sets Aborted = true before quitting, so callers can distinguish cancellation from an empty selection.

Scope: This PR only changes pkg/views/base/selection/model.go. Updating all selection wrappers to consume Aborted is intentionally left for a follow-up PR, per maintainer feedback on #947.

Problem

When a command is run without a positional argument, Harbor CLI opens an interactive picker. If the user cancels with q, esc, or ctrl+c, the picker closes but the base model returned with:

  • Aborted = false
  • Choice = ""

Callers that check Aborted (e.g. project selection) fell through to a misleading "no project selected" error. Callers that do not check Aborted (e.g. registry selection) could continue with empty values or zero IDs.

Demo

Screencast.From.2026-07-14.15-28-11.mp4

What the screencast shows:

  1. Before fix: harbor project view → picker opens → press q → error: no project selected
  2. After fix: same flow → error: user aborted project selection
  3. Filter mode preserved: press / to filter → esc exits filter mode without aborting the picker

Changes

In pkg/views/base/selection/model.go:

  • Handle ctrl+c → set Aborted = true, quit
  • Handle q / esc → set Aborted = true, quit
  • Skip abort when FilterState() == list.Filtering so q can be typed in the search box and esc exits filter mode

Code path

cmd/harbor/root/project/view.go
  └─ prompt.GetProjectNameFromUser()
       └─ pkg/views/project/select/view.go
            └─ tea.NewProgram(selection.Model).Run()
                 └─ pkg/views/base/selection/model.go   ← fix applied here
                      └─ user presses q / esc / ctrl+c
                      └─ Aborted = true, tea.Quit
            └─ wrapper checks model.Aborted
            └─ returns ErrUserAborted

Signed-off-by: CygnusMaximillian <dprajjwal11@gmail.com>
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.54%. Comparing base (60ad0bd) to head (34d9815).
⚠️ Report is 196 commits behind head on main.

Files with missing lines Patch % Lines
pkg/views/base/selection/model.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main   #1051      +/-   ##
=========================================
- Coverage   10.99%   9.54%   -1.45%     
=========================================
  Files         173     321     +148     
  Lines        8671   16097    +7426     
=========================================
+ Hits          953    1536     +583     
- Misses       7612   14427    +6815     
- Partials      106     134      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NucleoFusion NucleoFusion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!
thanks for the contribution

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.

[bug]: TUI selection cancel returns empty or zero-value choice instead of aborting

2 participants