- Add admin dashboard with sync controls and data browser - Implement RMM, Auvik, and Addigy organization mappings - Add chunked ticket sync with progress tracking - Implement entity sync service with rate limiting - Add analytics engine and performance optimizer - Create data browser for all PSA entities - Add navigation components and UI improvements - Implement background processing and sync services - Add comprehensive documentation and migration scripts - Update configuration items with multi-system support - Enhance contact management and purchase history - Add issue type assignment and LLM analyzer - Improve error handling and logging utilities
3.1 KiB
3.1 KiB
Time Entries Sorting Fix
Problem
The sort buttons on the time entries data browser page were not working. Clicking column headers to sort had no effect.
Root Cause
The DataTable component expects an onSort callback prop, but the time-entries page was not providing it.
Missing in original code:
<DataTable
data={timeEntries}
columns={columns}
// ... other props
// ❌ onSort prop was missing
/>
Solution
1. Added Sort State
// Sort states
const [sortBy, setSortBy] = useState('entry_date');
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
2. Updated fetchTimeEntries to Include Sort Parameters
params.append('sort_by', sortBy);
params.append('sort_order', sortOrder);
3. Created handleSort Function
const handleSort = async (column: string, direction: 'asc' | 'desc') => {
setSortBy(column);
setSortOrder(direction);
// Fetch with new sort parameters
// ... builds params with new sort values
// Resets to page 1 when sorting changes
};
4. Passed onSort to DataTable
<DataTable
data={timeEntries}
columns={columns}
isLoading={loading}
onRowClick={handleRowClick}
totalCount={totalCount}
page={currentPage}
pageSize={pageSize}
onPageChange={handlePageChange}
onSort={handleSort} // ✅ Now provided
/>
How It Works
- User clicks column header → DataTable calls
onSort(columnKey, direction) - handleSort updates state → Sets
sortByandsortOrder - handleSort fetches data → Calls API with
sort_byandsort_orderparams - Page resets to 1 → Sorting always shows results from the first page
- Table updates → New sorted data is displayed
API Parameters
The API endpoint /api/data/time-entries accepts:
sort_by- Column name to sort by (e.g., 'entry_date', 'hours_worked', 'resource_id')sort_order- Sort direction: 'asc' or 'desc'
Valid sort columns:
entry_datehours_workedcreated_atupdated_atresource_idticket_idtask_idproject_idcompany_idtitlebillableapproved
Default Sorting
- Column:
entry_date - Order:
desc(newest first)
User Experience
Before Fix
- ❌ Clicking column headers did nothing
- ❌ No visual feedback
- ❌ Data remained in default order
After Fix
- ✅ Clicking column headers sorts the data
- ✅ Arrow icons show current sort direction
- ✅ Data updates immediately
- ✅ Resets to page 1 when sorting changes
- ✅ Loading indicator shows during fetch
Testing
To test sorting:
- Navigate to
/admin/data-browser/time-entries - Click any column header with a sort icon
- Verify data is sorted correctly
- Click again to reverse sort direction
- Verify arrow icon changes direction
- Verify page resets to 1 when sorting
Files Modified
/app/admin/data-browser/time-entries/page.tsx- Added sort state and handler
Related Components
/components/admin/DataTable.tsx- Generic table component with sort support/app/api/data/time-entries/route.ts- API endpoint with sort parameters