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

Allow sorting by column in list panels #384

Open
jesseduffield opened this issue Oct 13, 2022 · 8 comments
Open

Allow sorting by column in list panels #384

jesseduffield opened this issue Oct 13, 2022 · 8 comments
Labels
enhancement New feature or request hacktoberfest

Comments

@jesseduffield
Copy link
Owner

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:

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!

@jesseduffield jesseduffield added enhancement New feature or request hacktoberfest labels Oct 13, 2022
@mark2185
Copy link
Contributor

Both 's' and 'S' are already used in the containers panel for starting and stopping containers, so that's off the cards.

But why? Different panel, different context, different action.

'o' is the next most obvious candidate i.e. 'order', so let's go with that.

o might have a better function down the road, like open something? Of course, the mapping doesn't have to make sense, but I'd somehow rather save up o for something "better". What about z?

@jesseduffield
Copy link
Owner Author

although my examples above were for the image panel, the goal is to have this functionality for all list panels

@jesseduffield
Copy link
Owner Author

good point about using 'o' to open something though

@jesseduffield
Copy link
Owner Author

Happy to go with 'z'

@26tanishabanik
Copy link

26tanishabanik commented Nov 28, 2022

@jesseduffield , I would like to work on this issue, can you guide me how and from where I should start with the development, also like the setup in local for dev?

@jesseduffield
Copy link
Owner Author

I recommend using either github codespaces or a dev container in VSCode (to minimise the setup time). I've neglected to add instructions to the lazydocker contributing guide but you can use the lazygit contribute guide as a guide: https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#running-in-a-vscode-dev-container

@26tanishabanik
Copy link

I recommend using either github codespaces or a dev container in VSCode (to minimise the setup time). I've neglected to add instructions to the lazydocker contributing guide but you can use the lazygit contribute guide as a guide: https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#running-in-a-vscode-dev-container

Got it @jesseduffield , will look into that guide

@26tanishabanik
Copy link

@jesseduffield , what should be the binding struct for this feature in keybindings.go ?
And where to apply the sorting for all the views?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants