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

feat: show pagination #261

Merged
merged 4 commits into from
May 10, 2024
Merged

feat: show pagination #261

merged 4 commits into from
May 10, 2024

Conversation

dbolson
Copy link
Contributor

@dbolson dbolson commented May 9, 2024

In a plaintext response that shows multiple items, we now show pagination if there is any.

# when the response includes default pagination
> ldcli members list
* m1@test.com (id-123)
* ...
Showing results 1 - 20 of 48. Use --offset 20 for additional results.

# with a offset value
> ldcli members list --offset 20
* m1@test.com (id-123)
* ...
Showing results 21 - 40 of 48. Use --offset 40 for additional results.

# with an offset value that does not have any more pagination
> ldcli members list --offset 40
* m1@test.com (id-123)
* ...
Showing results 41 - 48 of 48.

# with an offset and a limit
> ldcli members list --offset 1 --limit 1
* m1@test.com (id-123)
Showing results 2 - 2 of 48. Use --offset 2 for additional results.

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Provide links to any issues in this repository or elsewhere relating to this pull request.

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

@dbolson dbolson requested a review from k3llymariee May 9, 2024 23:11
if len(maybeResources.Items) == 0 {
return "No items found", nil
}
if !isMultipleResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reversed this check to remove the indentation.

limit int
offset int
)
self, ok := maybeResources.Links["self"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This gets the pagination values from the HATEOAS "self" link.

}
}

if successMessage != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to do some newline + space manipulation to make things work for a single response and multiple responses. We should refactor this to make it easier to reason about.

@dbolson dbolson merged commit 9a71cfe into main May 10, 2024
2 checks passed
@dbolson dbolson deleted the sc-243519/pagination branch May 10, 2024 17:34
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.

2 participants