Skip to content

feat: add status/author filters and sortable columns to sessions page#1518

Open
quay-devel wants to merge 5 commits intoambient-code:mainfrom
quay-devel:feature/issue-1515-session-filters-sort
Open

feat: add status/author filters and sortable columns to sessions page#1518
quay-devel wants to merge 5 commits intoambient-code:mainfrom
quay-devel:feature/issue-1515-session-filters-sort

Conversation

@quay-devel
Copy link
Copy Markdown

@quay-devel quay-devel commented May 7, 2026

Summary

  • Backend: Extended PaginationParams with phase, userId, sortBy, sortDirection query params. Added filterSessionsByPhase(), filterSessionsByUserID(), and sortSessions() functions to the ListSessions handler pipeline (applied after search, before pagination). Supports comma-separated phase values, configurable sort direction, and sorting by name or creation time.
  • Frontend: Added status filter dropdown (Active/Completed/Failed), "My sessions" toggle button (uses useCurrentUser() hook), and sortable "Created" and "Name" column headers with direction indicators. Clicking the active sort column toggles direction; clicking an inactive column switches to it with a sensible default (asc for name, desc for created). Active filters shown as dismissable chips. Pagination offset resets on any filter/sort change.
  • Tests: Backend — 5 new ginkgo test contexts covering phase filter (single/multi), userId filter, sort direction, and combined filters. Frontend — 4 new vitest tests verifying filter/sort params flow through the React Query hook.

Fixes #1515

Files Changed

File Change
components/backend/types/common.go Extended PaginationParams struct with 4 new fields
components/backend/handlers/sessions.go Added filter/sort functions, updated handler pipeline
components/backend/handlers/sessions_test.go Added createTestSessionWithOptions helper + 5 test contexts
components/frontend/src/types/api/common.ts Extended PaginationParams type
components/frontend/src/services/api/sessions.ts Forward new query params in listSessionsPaginated()
components/frontend/src/components/workspace-sections/sessions-section.tsx Filter UI, sortable Name + Created columns, filter chips, updated empty states
components/frontend/src/services/queries/__tests__/use-sessions.test.ts 4 new hook pass-through tests

Test plan

  • Verify ?phase=Running returns only Running sessions
  • Verify ?phase=Running,Pending returns sessions in either phase
  • Verify ?userId=<id> returns only that user's sessions
  • Verify ?sortBy=name&sortDirection=asc sorts alphabetically
  • Verify ?sortBy=created&sortDirection=desc sorts newest-first (default)
  • Verify combined filters work together
  • Verify status dropdown, "My sessions" toggle, and sort columns work in UI
  • Verify clicking Name column sorts alphabetically (asc default)
  • Verify clicking Created column sorts newest-first (desc default)
  • Verify clicking the active sort column toggles direction
  • Verify arrow icons only show on the active sort column
  • Verify filter chips appear and are dismissable
  • Verify offset resets when filters or sort change
  • Run go vet on backend changes
  • Run npx vitest run on frontend tests

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Sessions can now be filtered by phase status and specific user IDs
  • Added a "My sessions" toggle to quickly view only your own sessions
  • Enabled fully configurable session sorting with ascending/descending direction options
  • Improved the filter interface with removable filter chips for better visibility and management

quay-devel and others added 3 commits May 7, 2026 08:04
…sions list

Add phase filter dropdown (Active/Completed/Failed), "My sessions" toggle
using current user identity, and clickable sortable Created column header.
Filter params flow through PaginationParams -> API layer -> query keys for
proper cache isolation. Includes 4 new tests for filter param passthrough.

Ref: ambient-code#1515

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ist endpoint

Add server-side filtering by phase and userId, plus configurable sort
direction to the ListSessions handler, supporting the sessions page
filter/sort UI (ambient-code#1515).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused sortSessionsByCreationTime() function (replaced by sortSessions())
- Add sortDirection to offset reset dependency array for correct UX on sort toggle

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for cheerful-kitten-f556a0 canceled.

Name Link
🔨 Latest commit 4690f30
🔍 Latest deploy log https://app.netlify.com/projects/cheerful-kitten-f556a0/deploys/69fc4ccfaf00bc00080ad4ec

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

@quay-devel has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 49 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5560454b-c566-45b3-a83e-7c2e017594f0

📥 Commits

Reviewing files that changed from the base of the PR and between 0d2928f and 4690f30.

📒 Files selected for processing (3)
  • components/backend/handlers/sessions.go
  • components/backend/handlers/sessions_test.go
  • components/frontend/src/components/workspace-sections/sessions-section.tsx
📝 Walkthrough

Walkthrough

This PR adds server-side filtering and sorting to the sessions list. Backend extends ListSessions to apply phase and userId filters, then sort by configurable column and direction. Frontend adds a filter bar with phase dropdown, "My sessions" toggle, and sortable column headers, wiring them to the updated API.

Changes

Sessions Filtering & Sorting

Layer / File(s) Summary
Type Extensions
components/backend/types/common.go, components/frontend/src/types/api/common.ts
PaginationParams extended with phase, userId, sortBy, and sortDirection fields on both backend (Go structs with form tags) and frontend (TypeScript interface with optional types).
Backend Filtering & Sorting
components/backend/handlers/sessions.go
ListSessions applies phase and userId filters after search filtering, replaces hardcoded descending-creation-timestamp sort with generalized sortSessions using configurable column and direction. Adds filterSessionsByPhase, filterSessionsByUserID, and sortSessions helpers.
API Client & Hooks
components/frontend/src/services/api/sessions.ts, components/frontend/src/services/queries/use-sessions.ts
listSessionsPaginated passes phase, userId, sortBy, and sortDirection as URL query params; useSessionsPaginated hook forwards these filter/sort options to the API.
Frontend Filter UI
components/frontend/src/components/workspace-sections/sessions-section.tsx
Introduces phase dropdown, "My sessions" toggle, and removable filter chips in header; makes "Name" and "Created" columns clickable to control sort column and direction; consolidates empty-state messaging for filtered vs. unfiltered results.
Tests & Coverage
components/backend/handlers/sessions_test.go, components/frontend/src/services/queries/__tests__/use-sessions.test.ts
Backend tests verify phase filtering (single/multiple), userId filtering, sort direction, and combined filters; frontend tests verify query key generation includes filters and hook properly forwards filter/sort params to API. Adds createTestSessionWithOptions test helper to parametrize session phase and userId.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant Frontend as SessionsSection
    participant API as API Client
    participant Backend as ListSessions Handler
    participant K8s as K8s API

    User->>Frontend: Select phase filter, toggle "My sessions", click sort column
    Frontend->>Frontend: Update state (phaseFilter, mySessionsOnly, sortBy, sortDirection)
    Frontend->>API: listSessionsPaginated({phase, userId, sortBy, sortDirection})
    API->>Backend: GET /sessions?phase=Running,Pending&userId=user123&sortBy=created&sortDirection=asc
    Backend->>K8s: List all AgenticSession CRs
    K8s-->>Backend: All sessions
    Backend->>Backend: Apply search filter
    Backend->>Backend: Apply phase filter (comma-separated values)
    Backend->>Backend: Apply userId filter
    Backend->>Backend: Sort by (column, direction)
    Backend-->>API: Filtered & sorted sessions
    API-->>Frontend: Sessions data
    Frontend->>Frontend: Render table with active filter chips, sort indicators
    Frontend-->>User: Display results
Loading
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title follows Conventional Commits format (feat: scope/description) and accurately summarizes the main changes: adding phase/status filters and sortable columns to sessions.
Linked Issues check ✅ Passed All primary coding objectives from #1515 are met: phase filtering (single/multi), userId filtering (My sessions toggle), sortable columns (Created/Name with direction control), and server-side filter application before pagination.
Out of Scope Changes check ✅ Passed All changes directly support #1515 objectives: PaginationParams extensions, ListSessions filtering/sorting pipeline, frontend filter UI, API passthrough, and comprehensive test coverage align with the stated scope.
Performance And Algorithmic Complexity ✅ Passed Backend sort/filter use O(n log n) and O(n). Pagination enforced (20 default, max 100). Cache TTL eviction prevents unbounded growth. No new N+1s or algorithmic regressions.
Security And Secret Handling ✅ Passed No security violations found. No hardcoded secrets, injection vulnerabilities, auth bypass, service account misuse, or sensitive data leakage detected in filtering/sorting implementation.
Kubernetes Resource Safety ✅ Passed PR contains only application code (Go handlers, TypeScript components). No K8s manifests, RBAC policies, or resource specs. Check not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Make the Name column header clickable for sorting, matching the
existing Created column behavior. Clicking the active sort column
toggles direction; clicking an inactive column switches to it with
a sensible default (asc for name, desc for created). Arrow icons
only show on the active sort column.

The backend already supports sortBy=name, so no backend changes needed.

Refs ambient-code#1515
@quay-devel quay-devel marked this pull request as ready for review May 7, 2026 08:19
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
components/backend/handlers/sessions_test.go (1)

342-386: ⚡ Quick win

Add coverage for sortBy=name path

Current additions validate sortDirection, but not the "name" branch itself. A regression in sortBy=name wouldn’t be caught by this suite.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/backend/handlers/sessions_test.go` around lines 342 - 386, Add a
test case that exercises the "sortBy=name" branch by calling the ListSessions
handler with the query param sortBy=name (and both sortDirection=asc and the
default/desc case) using httpUtils.CreateTestGinContext and the existing
createTestSessionWithOptions("alpha-"+randomName...) /
createTestSessionWithOptions("beta-"+randomName...) setup; assert HTTP 200,
parse response items, and verify ordering by metadata.name (alpha before beta
for asc, beta before alpha for desc) so the sortBy=name code path is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/backend/handlers/sessions.go`:
- Around line 803-816: The comparator used by sort.Slice currently compares
sessions[i].Metadata["name"] but the UI displays spec.displayName ||
metadata.name; update the "name" case in the comparator to compute vi and vj by
first checking the session's spec.displayName (type-assert to string) and using
it if non-empty, otherwise falling back to sessions[].Metadata["name"]; then
lowercase both values for comparison. Modify the comparator inside sort.Slice
(the "name" case) to read spec.displayName for sessions[i] and sessions[j],
fallback to metadata.name, and set vi/vj accordingly before returning vi < vj
(leaving the default case using getSessionCreationTimestamp unchanged).

In `@components/frontend/src/components/workspace-sections/sessions-section.tsx`:
- Around line 329-362: The sortable TableHead elements (the ones toggling sort
for 'name' and 'created') are currently click-only; make them
keyboard-accessible by ensuring they are focusable and respond to Enter/Space:
add tabIndex={0} (or use a semantic <button>), a role="button" if not a native
button, and an onKeyDown handler that invokes the same logic used in the onClick
(toggling setSortDirection or setting setSortBy and default sortDirection). Also
add ARIA state like aria-sort on those headers to reflect sortBy/sortDirection
for screen readers (use 'none'/'ascending'/'descending' based on sortBy and
sortDirection). Ensure handlers reference the same setSortBy/setSortDirection
logic currently in the TableHead click handlers for 'name' and 'created'.
- Around line 118-120: The request builder is using mySessionsOnly while
currentUser may still be unresolved, causing userId to be undefined and
returning unfiltered results; update the logic in the SessionsSection where
userId is set (userId: mySessionsOnly ? currentUser?.userId : undefined) to only
include userId when currentUser?.userId exists (e.g., userId: mySessionsOnly &&
currentUser?.userId ? currentUser.userId : undefined) so the API is not queried
as "my sessions" with an undefined id, and also disable the "My sessions" toggle
control (the UI toggle bound to mySessionsOnly) until currentUser is loaded so
the user cannot enable the filter before currentUser is known.

---

Nitpick comments:
In `@components/backend/handlers/sessions_test.go`:
- Around line 342-386: Add a test case that exercises the "sortBy=name" branch
by calling the ListSessions handler with the query param sortBy=name (and both
sortDirection=asc and the default/desc case) using
httpUtils.CreateTestGinContext and the existing
createTestSessionWithOptions("alpha-"+randomName...) /
createTestSessionWithOptions("beta-"+randomName...) setup; assert HTTP 200,
parse response items, and verify ordering by metadata.name (alpha before beta
for asc, beta before alpha for desc) so the sortBy=name code path is covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 02606c11-9e03-4797-9a17-67b53f51995f

📥 Commits

Reviewing files that changed from the base of the PR and between 7149354 and 0d2928f.

📒 Files selected for processing (7)
  • components/backend/handlers/sessions.go
  • components/backend/handlers/sessions_test.go
  • components/backend/types/common.go
  • components/frontend/src/components/workspace-sections/sessions-section.tsx
  • components/frontend/src/services/api/sessions.ts
  • components/frontend/src/services/queries/__tests__/use-sessions.test.ts
  • components/frontend/src/types/api/common.ts

Comment thread components/backend/handlers/sessions.go
Comment thread components/frontend/src/components/workspace-sections/sessions-section.tsx Outdated
- Sort-by-name now uses displayName with fallback to metadata.name,
  matching what the UI displays
- "My sessions" toggle disabled while currentUser is loading, and
  userId guard prevents unfiltered queries when user is unresolved
- Sortable table headers are keyboard-accessible (tabIndex, role,
  onKeyDown, aria-sort)
- Added sortBy=name test coverage (ascending and descending)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Sessions page: add status/author filters and sortable columns

1 participant