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

Add pagination on TUI #157

Merged
merged 1 commit into from
Aug 20, 2024
Merged

Conversation

ilmanzo
Copy link
Contributor

@ilmanzo ilmanzo commented Aug 18, 2024

  • use keys < > for previous page / next page, wrapping around on first/last.
  • give indication of current page / total number of pages in the header
  • bump minimum Go version to 1.21 (due to usage of the builtin min function), can be changed if 1.20 is a strict requirement
  • some minor refactoring / improvements : update project URLs to new repository, clean Makefile target, and so on

Fixes #106

@ilmanzo ilmanzo force-pushed the enable_pagination branch from 66a9108 to 1947b62 Compare August 18, 2024 08:50
Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Thank you Andrea, this looks already very good!

I've added some suggestions. Once we're done here, I still would like to test if this works with all display modes correctly, perhaps you can also have a look.

cmd/openqa-mon/tui.go Outdated Show resolved Hide resolved
cmd/openqa-mon/tui.go Outdated Show resolved Hide resolved
cmd/openqa-mon/tui.go Outdated Show resolved Hide resolved
tui.totalPages++
}
// safety check
if startIdx >= len(tui.Model.jobs) || endIdx > len(tui.Model.jobs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of returning, I would set startIdx and endIdx to the maximum values:

Suggested change
if startIdx >= len(tui.Model.jobs) || endIdx > len(tui.Model.jobs) {
startIdx = min(startIdx, len(tui.Model.jobs)-1)
endIdx = min(endIds, len(tui.Model.jobs)-1)

Like this the safety check ensure that the program still displays the jobs, otherwise we have a safety check that will prevent the program from crashing, but not displaying anything useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is still a glitch, when you have a small terminal (let's say 10 lines) and you enlarge it, the page recalc logic doesn't trigger immediately. To have a full responsive application we'd need to intercept the terminal resize event and act accordingly, but it would be easier to just use a proper terminal library as stated above :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add a comment or even better file an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added #158

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the if () statement can be omitted.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, why not apply them directly in line 348 and 349? 🤔

startIdx := min(tui.currentPage * pageHeight, len(tui.Model.jobs)-1)
endIdx := min(startIdx+pageHeight, len(tui.Model.jobs)-1)

go.mod Show resolved Hide resolved
.vscode/settings.json Outdated Show resolved Hide resolved
cmd/openqa-mon/tui.go Outdated Show resolved Hide resolved
tui.totalPages++
}
// safety check
if startIdx >= len(tui.Model.jobs) || endIdx > len(tui.Model.jobs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add a comment or even better file an issue for this?

Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Looks good so far. Will do some local testing and then report back.

.gitignore Outdated Show resolved Hide resolved
@grisu48
Copy link
Collaborator

grisu48 commented Aug 19, 2024

There are 2 visual issues that still need to be resolved:

  • Empty line below the footer (See first screenshot)
  • The footer is not at the bottom on the last page (See second screenshot)

image
image

@ilmanzo ilmanzo force-pushed the enable_pagination branch from 8012c39 to e4cabe6 Compare August 19, 2024 12:21
@ilmanzo
Copy link
Contributor Author

ilmanzo commented Aug 19, 2024

should be better now:

Screencast.from.2024-08-19.15-24-42.mp4

@grisu48
Copy link
Collaborator

grisu48 commented Aug 19, 2024

should be better now:
Screencast.from.2024-08-19.15-24-42.mp4

I still don't see any differences, but the last state is from an hour ago. Perhaps the last changes haven't been pushed yet?

@ilmanzo ilmanzo force-pushed the enable_pagination branch from e4cabe6 to fd4fa70 Compare August 19, 2024 13:35
@ilmanzo
Copy link
Contributor Author

ilmanzo commented Aug 19, 2024

should be better now:
Screencast.from.2024-08-19.15-24-42.mp4

I still don't see any differences, but the last state is from an hour ago. Perhaps the last changes haven't been pushed yet?

sorry, you're right.. Forgot to push :)

Copy link
Collaborator

@grisu48 grisu48 left a comment

Choose a reason for hiding this comment

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

Two minor comments, otherwise LGTM!

It looks great now 🙂

tui.totalPages++
}
// safety check
if startIdx >= len(tui.Model.jobs) || endIdx > len(tui.Model.jobs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the if () statement can be omitted.

tui.totalPages++
}
// safety check
if startIdx >= len(tui.Model.jobs) || endIdx > len(tui.Model.jobs) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, why not apply them directly in line 348 and 349? 🤔

startIdx := min(tui.currentPage * pageHeight, len(tui.Model.jobs)-1)
endIdx := min(startIdx+pageHeight, len(tui.Model.jobs)-1)

@ilmanzo ilmanzo force-pushed the enable_pagination branch from fd4fa70 to 77f50ef Compare August 20, 2024 06:52
@ilmanzo
Copy link
Contributor Author

ilmanzo commented Aug 20, 2024

Two minor comments, otherwise LGTM!

It looks great now 🙂

Actually your suggestion is a very good idea; I also got rid of the now useless offset :)

cmd/openqa-mon/tui.go Outdated Show resolved Hide resolved
@ilmanzo ilmanzo force-pushed the enable_pagination branch from 77f50ef to 6ddcae5 Compare August 20, 2024 07:49
@ilmanzo
Copy link
Contributor Author

ilmanzo commented Aug 20, 2024

how about a minor version bump ? I like 1.2.3 :D

@grisu48
Copy link
Collaborator

grisu48 commented Aug 20, 2024

how about a minor version bump ? I like 1.2.3 :D

Yes indeed. But I do version bumps in dedicated merge requests before a new release. This change would motivate one though.

@ilmanzo ilmanzo force-pushed the enable_pagination branch from 6ddcae5 to 32e5244 Compare August 20, 2024 08:42
@grisu48 grisu48 merged commit a54697f into os-autoinst:main Aug 20, 2024
2 checks passed
@grisu48
Copy link
Collaborator

grisu48 commented Aug 20, 2024

Thank you for adding pagination support in openqa-mon @ilmanzo 🥳

@ilmanzo ilmanzo deleted the enable_pagination branch August 20, 2024 09:21
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.

[openqa-mon] Add pagination
2 participants