jesseduffield / jesseduffield/lazydocker

Allow sorting by column in list panels

Open
#384 9 comments 2 reactions 0 assignees View on GitHub
enhancement hacktoberfest
Dominant language
Go
Stars
52.8k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
When there are a large amount of items in a list panel, it can be convenient to sort by a particular column. For example, you may want to know which images have the greatest size, so you'd want to sort by image size descending and look at what's at the top.

**Describe the solution you'd like**
As an example, if I'm in the images panel I want to be able to press a key and see a menu with the options:
* sort by name (ascending)
* sort by name (descending)
* sort by tag (ascending)
* sort by tag (descending)
* sort by size (ascending)
* sort by size (descending)
* default sort

Both 's' and 'S' are already used in the containers panel for starting and stopping containers, so that's off the cards. 'o' is the next most obvious candidate i.e. 'order', so let's go with that.

**Additional context**
This issue doesn't care about persisting sorting between different runs of the application, nor does it care about configuring a default sort order. Those can be tackled in separate issues.

In lazygit we have the ability to have keybindings against menu items so that you don't need to navigate through the list to select an item. Once we have that feature, we can apply it here so that for example you can press 'o', 's' for sorting by size ascending, and 'o', 'S' for size descending. But that's out of scope for this issue.

We'll need to maintain the sorting state against each list panel, so we can create a `SortBy` field in each of the list panels' `panelStates` struct (which you'll find in `pkg/gui/gui.go`). We'll also need a `SortDirection` field:

```go
type imagePanelState struct {
SelectedLine int
ContextIndex int // for specifying if you are looking at logs/stats/config/etc
SortBy string // One of "default", "name", "tag", "size"
SortAscending bool // ignored when SortBy is 'default'
}
```

The purpose of the default sort is for when e.g. we're in the services panel which has some bespoke sorting logic. If we're not on the default sort, any bespoke sorting logic will be ignored.

We can then apply the sort logic in `pkg/commands/image.go` in the `RefreshImages()` function.

If you would like to pick this up let me know!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.