Skip to content

Add pagination support for instances listing in CLI and web interface#3

Merged
tayyebi merged 4 commits intomainfrom
copilot/add-pagination-to-instances
Jan 7, 2026
Merged

Add pagination support for instances listing in CLI and web interface#3
tayyebi merged 4 commits intomainfrom
copilot/add-pagination-to-instances

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

Implements page-based navigation for instance lists to handle large result sets. Pagination defaults to disabled (showing all instances) to preserve existing behavior.

Changes

Backend (src/api/instances.rs)

  • New PaginatedInstances struct returns instances with metadata: total_count, current_page, total_pages, per_page
  • Updated load_instances_for_user signature to accept page and per_page parameters
  • Page 0 or per_page 0 bypasses pagination and returns all instances

Web Interface

  • Handler extracts query parameters: ?page=N&per_page=M (defaults: page=1, per_page=20)
  • Pagination controls show when total_pages > 1:
    • Current state: "Showing X of Y instances (Page N of M)"
    • Previous/Next buttons with disabled states
    • CSS styled for light/dark themes

Template updates:

  • src/handlers/instances.rs - Query parameter extraction
  • src/templates/instances_page_template.rs - Added pagination fields
  • templates/instances.html - Pagination UI
  • static/styles.css - Pagination styling

CLI

  • New flags: --page <N> (alias -p), --per-page <M>
  • Defaults: page=0 (all instances), per_page=20
  • Displays pagination info and navigation hints when enabled

Example:

# Show all (default, backward compatible)
zy instances list

# Paginated view
zy instances list --page 1 --per-page 20

# Output includes navigation hints:
# Page 1 of 5 | Showing 20 of 100 total instances
# → Next page: zy instances list --page 2 --per-page 20

Screenshot

Instances page with pagination structure

Empty state shown; pagination controls appear when multiple pages exist

Edge Cases

  • Invalid page numbers clamped to valid range [1, total_pages]
  • Empty results and single-page lists hide pagination controls
  • User permissions respected during pagination (owners see all, users see assigned only)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.cloudzy.com
    • Triggering command: target/debug/zy target/debug/zy serve --host 127.0.0.1 --port 5050 lib/rustlib/x86_/home/REDACTED/work/cli/cli/target/debug/deps/askama_derive-a0d8116b74b54c6a.askam--norc lib/rustlib/x86_/home/REDACTED/work/cli/cli/target/debug/deps/askama_derive-a0d8116b74b54c6a.askam--noprofile c1c51275a3f.thisgit c1c51275a3f.thischeckout c1c51275a3f.thiscopilot/add-pagination-to-instances c1c51275a3f.thiserror_impl.a5ec9bc65d29fa06-cgu.03.rcgu.o c1c5�� c1c51275a3f.thiserror_impl.a5ec9bc65d29fa06-cgu.05.rcgu.o c1c51275a3f.thiserror_impl.a5ec9bc65d29fa06-cgu.06.rcgu.o c1c51275a3f.thiserror_impl.a5ec9bc65d29fa06-cgu.07.rcgu.o c1c51275a3f.thisbash c1c51275a3f.this--norc c1c51275a3f.this--noprofile c1c51275a3f.thiserror_impl.a5ec9bc65d29fa06-cgu.11.rcgu.o (dns block)
    • Triggering command: target/debug/zy target/debug/zy instances list --silent lib/�� lib/rustlib/x86_debuginfo=2 lib/rustlib/x86_--check-cfg f/hex-0.4.3/src/lib.rs lib/rustlib/x86_git lib/rustlib/x86_add lib/rustlib/x86_. lib/rustlib/x86_-v lib/�� lib/rustlib/x86_64-REDACTED-linux-gnu/lib/librustc_std_workspace_alloc-05b02707a5b2a256.rlib lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-5312b588e5cfab93.rlib _macros-c909fd3ee8b31b7d.time_ma--crate-type b2a256.rlib _macros-c909fd3e--type=utility _macros-c909fd3e--utility-sub-type=network.mojom.NetworkService _macros-c909fd3e--lang=en-US (dns block)
    • Triggering command: target/debug/zy target/debug/zy instances list --page 1 --per-page 10 --silent 5a3956f1.axum_magit 5a3956f1.axum_macommit 5a3956f1.axum_ma-m bin/cargo 5a39�� 5a3956f1.axum_macros.db1037a7690a587-cgu.13.rcgu.o 5a3956f1.axum_macros.db1037a7690a587-cgu.14.rcgu.o 569.rlib 07a.rlib 84a9e5.rlib 42.rlib 9d2.rlib (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Overview

Implement next page and previous page style pagination for listing instances in both the CLI and web interface. This will improve usability when there are a large number of instances, limiting results shown at once and allowing navigation through pages of results.

Requirements

CLI Implementation

  • Add pagination support to the zy instances list command
  • Add flags for page navigation:
    • --page <number> or -p <number>: Specify which page to display
    • --per-page <number>: Number of instances per page (default: 20)
  • Display pagination information in the output:
    • Show current page number
    • Show total pages
    • Show "Next page" and "Previous page" indicators when applicable
  • Preserve existing functionality (e.g., --page 0 or omitting the flag shows all instances)

Web Interface Implementation

  • Add pagination controls to the /instances page (templates/instances.html)
  • Implement pagination in the handler (src/handlers/instances.rs)
  • Support query parameters for pagination:
    • ?page=<number>: Current page (1-indexed)
    • ?per_page=<number>: Items per page (default: 20)
  • Display pagination controls with:
    • "Previous" button (disabled on first page)
    • Current page indicator (e.g., "Page 2 of 5")
    • "Next" button (disabled on last page)
  • Style pagination controls consistently with existing UI

Implementation Details

Files to Modify

CLI:

  • src/cli/commands/instances.rs - Add pagination flags and logic to list command
  • src/cli/mod.rs - Update command parsing if needed

Web:

  • src/handlers/instances.rs - Modify instances_real handler to accept pagination parameters
  • templates/instances.html - Add pagination UI controls
  • src/templates/instances_page_template.rs - Add pagination fields to template struct
  • static/styles.css - Add styles for pagination controls (if needed)

Shared:

  • src/api/instances.rs - Update load_instances_for_user to support pagination parameters
  • Return both the paginated data and metadata (total count, current page, total pages)

Technical Approach

  1. Backend Pagination Logic:

    • Modify load_instances_for_user to accept page and per_page parameters
    • Calculate offset: (page - 1) * per_page
    • Return a struct containing:
      • instances: Vec<InstanceView> - The paginated instances
      • total_count: usize - Total number of instances
      • current_page: usize - Current page number
      • total_pages: usize - Total number of pages
  2. Web Handler:

    • Extract query parameters for page and per_page from the request
    • Pass to the instances loading function
    • Pass pagination metadata to the template
  3. Web Template:

    • Add pagination controls below the instances table
    • Generate links with proper query parameters
    • Show/hide Previous/Next buttons based on current page
  4. CLI Command:

    • Parse --page and --per-page flags
    • Display pagination info after the instance list
    • Show navigation hints (e.g., "Use --page 3 to view next page")

Acceptance Criteria

  • ✅ CLI command zy instances list --page 2 --per-page 10 works correctly
  • ✅ Web interface shows pagination controls on /instances page
  • ✅ Navigation between pages works smoothly in both CLI and web
  • ✅ Pagination respects user permissions (owners see all, users see assigned only)
  • ✅ Edge cases handled (empty list, single page, invalid page numbers)
  • ✅ Clear user feedback on current page and navigation options
  • ✅ Existing functionality preserved (no pagination by default or page 0 shows all)

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 7, 2026 08:07
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
…per-page in CLI hints

Co-authored-by: tayyebi <14053493+tayyebi@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement pagination for listing instances in CLI and web interface Add pagination support for instances listing in CLI and web interface Jan 7, 2026
Copilot AI requested a review from tayyebi January 7, 2026 08:18
@tayyebi tayyebi marked this pull request as ready for review January 7, 2026 11:21
@tayyebi tayyebi merged commit ab1c547 into main Jan 7, 2026
@tayyebi tayyebi deleted the copilot/add-pagination-to-instances branch January 7, 2026 15:01
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