Skip to content

FEAT: Server-side pagination and sorting for Jobs page#109

Open
Divyansh Maheshwari (divyansh1010x) wants to merge 2 commits into
mainfrom
feat/jobs-pagination-sorting
Open

FEAT: Server-side pagination and sorting for Jobs page#109
Divyansh Maheshwari (divyansh1010x) wants to merge 2 commits into
mainfrom
feat/jobs-pagination-sorting

Conversation

@divyansh1010x

@divyansh1010x Divyansh Maheshwari (divyansh1010x) commented Jun 15, 2026

Copy link
Copy Markdown

Jobs pagination + sorting

Adds server-side pagination and sorting to the Jobs page (UI + /jobs API).

Why this touches the API: the requirement was UI-only, but supporting sorting on arbitrary columns required extending /jobs — a single-column cursor can't support multiple sort orders.

Backend

  • Added order_by (whitelisted: id, created_at, updated_at) and direction (asc/desc) query parameters.
  • Unknown order_by values fall back to system_job_id.
  • Retained keyset/cursor pagination (not offset) for performance and consistency under inserts.
  • system_job_id is used as the tiebreaker for stable ordering.

Frontend

  • Added server-side pagination.
    • 20 rows per page.
    • Previous / Next controls.
    • Page indicator.
    • Displays counts as 20+, 40+, etc. while more pages exist.
  • Added server-side sorting for:
    • Job ID
    • Created At
    • Updated At
  • Replaces the previous client-side sorting of the currently loaded page.

Testing

Tested locally against the docker-compose stack:

docker compose up -d --build

Setup

Seed 25 jobs to create multiple pages (20/page):

for i in $(seq 1 25); do
  curl -s -X POST \
    -H "X-Pattern-User: test_user" \
    -H "Content-Type: application/json" \
    -d '{"name":"ping-'"$i"'","version":"0.0.1","context":{},"command_criteria":["type:ping"],"cluster_criteria":["type:localhost"]}' \
    http://127.0.0.1:9090/api/v1/job > /dev/null
done

1. First page returns a cursor

curl -s "http://127.0.0.1:9090/api/v1/jobs?limit=20&order_by=created_at&direction=desc" \
  | jq '{count: (.data|length), has_more, next_cursor}'

Expected:

  • count = 20
  • has_more = true
  • next_cursor present (opaque base64)

2. Cursor paging — no overlap across pages, including tied sort values

Jobs created in a tight loop share the same created_at, which is where naive cursor pagination often fails. Verified that the system_job_id tiebreaker correctly handles this case.

C=$(curl -s "http://127.0.0.1:9090/api/v1/jobs?limit=5&order_by=created_at&direction=desc" | jq -r '.next_cursor')

curl -s -G "http://127.0.0.1:9090/api/v1/jobs" \
  --data-urlencode "limit=5" \
  --data-urlencode "order_by=created_at" \
  --data-urlencode "direction=desc" \
  --data-urlencode "cursor=$C" \
  | jq -c '.data[] | {id: .id[0:8], created_at}'

Expected:

  • Page 2 resumes correctly from Page 1.
  • Rows sharing the same created_at continue correctly across pages.
  • No duplicated rows.
  • No skipped rows.

3. UI (browser)

Verified:

  • Jobs page loads paginated at 20 rows/page.
  • Previous / Next navigation works correctly.
  • Previous is disabled on page 1.
  • Next is disabled on the last page.
  • Result count displays:
    • 20+, 40+, etc. while more pages exist.
    • Exact count on the final page.
  • Clicking Job ID, Created At, or Updated At triggers server-side sorting and resets pagination to page 1.
  • Other columns are not sortable.
  • Applying or resetting filters resets pagination to page 1.

Copilot AI review requested due to automatic review settings June 15, 2026 10:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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