๐Ÿ”ง Shot Table Sort Direction Fix

โŒ Issue Identified

Problem: Shot table header sorting direction only goes down (descending) and never goes up (ascending).

Root Cause: Incorrect logic in toggleSorting parameter in frontend/src/components/shot/columns.ts

๐Ÿ” Technical Analysis

The issue was in the TanStack Table toggleSorting method call:

โŒ Before (Broken)

onClick: () => column.toggleSorting(column.getIsSorted() === 'asc')

Logic:

  • When currently ascending โ†’ passes true โ†’ forces descending
  • When currently descending โ†’ passes false โ†’ should go ascending but doesn't work properly
  • When no sort โ†’ passes false โ†’ goes ascending (this worked)

โœ… After (Fixed)

onClick: () => column.toggleSorting(column.getIsSorted() === 'desc')

Logic:

  • When currently ascending โ†’ passes false โ†’ toggles to descending
  • When currently descending โ†’ passes true โ†’ toggles to ascending
  • When no sort โ†’ passes false โ†’ goes ascending

๐Ÿ“ TanStack Table toggleSorting Method

According to TanStack Table documentation:

toggleSorting(desc?: boolean) - toggleSorting() - cycles: none โ†’ asc โ†’ desc โ†’ none - toggleSorting(false) - cycles: none โ†’ asc โ†’ desc โ†’ none - toggleSorting(true) - cycles: none โ†’ desc โ†’ asc โ†’ none

The parameter desc indicates whether to prefer descending sort when toggling from no sort.

โœ… Files Fixed

Updated frontend/src/components/shot/columns.ts - Fixed all sortable columns:

Note: Task status columns are dynamically generated and inherit the same pattern, so they're also fixed.

๐Ÿงช Testing Instructions

To verify the fix works correctly:

  1. Navigate to Shot Table: Go to any project's shots page and switch to table view
  2. Test Sort Cycle: Click on any sortable column header (e.g., "Shot Name")
  3. Verify Ascending: First click should sort ascending (Aโ†’Z, 1โ†’9) with up arrow โ†‘
  4. Verify Descending: Second click should sort descending (Zโ†’A, 9โ†’1) with down arrow โ†“
  5. Verify Clear: Third click should clear sort (original order) with up-down arrow โ†•
  6. Test Multiple Columns: Repeat for Episode, Frame Range, Frames, Status, Description
  7. Visual Feedback: Confirm icons change correctly: โ†• โ†’ โ†‘ โ†’ โ†“ โ†’ โ†•

๐ŸŽฏ Expected Behavior

After the fix, clicking column headers should cycle through:

1. No Sort (โ†• up-down arrow) โ†’ Original data order 2. Ascending (โ†‘ up arrow) โ†’ A-Z, 1-9, earliest-latest 3. Descending (โ†“ down arrow) โ†’ Z-A, 9-1, latest-earliest 4. Back to No Sort (โ†• up-down arrow)

๐Ÿ”„ Related Issue

Note: The same issue exists in frontend/src/components/task/columns.ts and should be fixed there as well for consistency.

This affects the task table sorting behavior in the same way.

โœ… Fix Summary

Changed: column.getIsSorted() === 'asc' โ†’ column.getIsSorted() === 'desc'

Result: Proper sort direction cycling with correct visual feedback

Impact: All sortable columns in shot table now work correctly

Status: Ready for testing