Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up state search UI #3099

Merged
merged 39 commits into from
Feb 15, 2024
Merged

Clean up state search UI #3099

merged 39 commits into from
Feb 15, 2024

Conversation

MDrakos
Copy link
Member

@MDrakos MDrakos commented Feb 11, 2024

StoryDX-2400 Clean up the `state search` UI

This uses the viewport bubble to handle rendering and scrolling. Example here for reference.

@MDrakos MDrakos changed the base branch from master to version/0-44-0-RC1 February 11, 2024 22:30
@MDrakos MDrakos requested a review from Naatan February 12, 2024 18:23
internal/runners/packages/search.go Outdated Show resolved Hide resolved
Comment on lines 111 to 116
table, err := createSearchTable(v.width, v.height, processedPackages, vulns)
if err != nil {
return errs.Wrap(err, "Could not create search table")
}
v.content = table.Content()
v.packageNames = table.packageNames
Copy link
Member

Choose a reason for hiding this comment

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

It feels like the table should itself be the view.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this a bit so that the view is more encapsulated. We are still using this type to process the search results but any view processing for the viewport is now done elsewhere.

Comment on lines 118 to 119
if s.out.Type().IsStructured() {
s.out.Print(table)
Copy link
Member

Choose a reason for hiding this comment

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

Handling structured output through the table feels overloaded. It seems the table is both responsible for handling view logic and for handling data parsing. I'd try to calculate the structured data first and foremost, and if that's all the user requested we never even touch any bubbletea or view logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've moved the table view calculation to the actual view type. We are still using this table type to calculate the structured search results and the view does further processing for the plain output. Otherwise we dump the table from the search results.

internal/runners/packages/search.go Outdated Show resolved Hide resolved
internal/runners/packages/search.go Show resolved Hide resolved
}

func NewView() (*view, error) {
width, height, err := term.GetSize(int(os.Stdout.Fd()))
Copy link
Member

Choose a reason for hiding this comment

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

Don't use os directly, instead use output.Config().OutWriter.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is expecting a file descriptor. The OutWriter is an io.Writer interface.

Copy link
Member

Choose a reason for hiding this comment

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

Can we add the Fd() method on Outwriter? I'm not confident that we'll end up using this long term but having everything agree on a same source of truth will make refactoring this later easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a method to the output Config type.

internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
Base automatically changed from version/0-44-0-RC1 to beta February 13, 2024 17:56
@MDrakos MDrakos changed the base branch from beta to version/0-44-0-RC1 February 14, 2024 00:44
@MDrakos MDrakos requested a review from Naatan February 14, 2024 19:22
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

I can't select text in my terminal when viewing search results. There's a weird symbol on my cursor that I think indicates it has some sort of lock. Possibly this is something the viewport imposes, but we might be able to configure it?

internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/search.go Show resolved Hide resolved
cmds []tea.Cmd
)

switch msg := msg.(type) {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like scrolling is already handled through the viewport lib:

https://github.com/charmbracelet/bubbles/blob/master/viewport/viewport.go#L287

Is there a reason we can't make use of that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Took some time to try and use this. The Update method does not implement the correct interface so it's not a simple replacement. We would likely have to do some wrapping. I didn't realize the viewport had these methods as I was following the example that I linked in my initial comment.

Copy link
Member

Choose a reason for hiding this comment

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

Can't you just call the viewport's Update() method from your Update() method? ie. handle whatever you need to handle, then defer the rest to the viewport package.

Copy link
Member Author

@MDrakos MDrakos Feb 15, 2024

Choose a reason for hiding this comment

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

Took another look at this and no, it's not that simple. Again, the Update() function return a struct that doesn't satisfy the tea.Model interface. This means that we can't just return the values that the Update() function returns.

I didn't spend a lot of time trying to get this working but I managed to by replacing the underlying viewport. Unfortunately, this means we lose the header and footer spacing that we want to setup so it looks a bit off.

Looking at bit more at the code you linked it's not immediately evident what benefit we get from using this Update function. It would be handling the scrolling keys for us but that's about it.

If there is some other benefit or if this is something that we need before this can be merged I can try to get it working but it will take some time. If you have an idea on how this might work that I'm not seeing feel free to take a stab at it or just let me know.

internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/styles.go Outdated Show resolved Hide resolved
pkg/platform/model/vulnerabilities.go Outdated Show resolved Hide resolved
@MDrakos
Copy link
Member Author

MDrakos commented Feb 14, 2024

I can't select text in my terminal when viewing search results. There's a weird symbol on my cursor that I think indicates it has some sort of lock. Possibly this is something the viewport imposes, but we might be able to configure it?

Unfortunately, it doesn't appear that this is currently supported: charmbracelet/bubbletea#162

@MDrakos MDrakos requested a review from Naatan February 15, 2024 00:20
@mitchell-as
Copy link
Contributor

Try holding down Shift and click-dragging with the mouse. At least in Linux this should work with terminals whose current applications are handling mouse events.

@Naatan
Copy link
Member

Naatan commented Feb 15, 2024

I can't select text in my terminal when viewing search results. There's a weird symbol on my cursor that I think indicates it has some sort of lock. Possibly this is something the viewport imposes, but we might be able to configure it?

Unfortunately, it doesn't appear that this is currently supported: charmbracelet/bubbletea#162

Bah.. ok let's revert mouse scrolling then. It's more important that you can select text than that you can scroll with your mouse. And git log apparently has the same limitation.

@mitchell-as shift+click didn't do anything for me in iTerm :\

Comment on lines +31 to +34
result.Name = ptr.From(pkg.Ingredient.Name, "")
result.Description = ptr.From(pkg.Ingredient.Description, "")
result.Website = pkg.Ingredient.Website.String()
result.License = ptr.From(pkg.LatestVersion.LicenseExpression, "")
Copy link
Member

Choose a reason for hiding this comment

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

Author information is missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have noted this somewhere but we discussed during stand that retrieving the author information requires us to make a separate API call for each package in the search results. We deemed that this would slow down the command too much so opted to leave the authors out.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, forgot about that. I filed DX-2581 and a blocker with XT to hopefully get this resolved.

internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
internal/runners/packages/searchView.go Outdated Show resolved Hide resolved
@MDrakos MDrakos requested a review from Naatan February 15, 2024 21:55
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Nearly there, two remaining issues:

  1. Vulnerabilities is not colored correctly, and has inconsistent indentation:

image

  1. Authors is still missing.

@MDrakos
Copy link
Member Author

MDrakos commented Feb 15, 2024

Missed the vulnerabilities key on the last round of changes. Should be updated now as well as the vulnerability colours.

As for the authors see this comment: #3099 (comment)

@MDrakos MDrakos requested a review from Naatan February 15, 2024 22:30
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Great work!

@MDrakos MDrakos merged commit 65b39c6 into version/0-44-0-RC1 Feb 15, 2024
6 of 7 checks passed
@MDrakos MDrakos deleted the DX-2400 branch February 15, 2024 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants