mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 18:11:12 -05:00
Fix: Restore escalated sort order
This commit is contained in:
@@ -253,11 +253,15 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
const sortAscending = sort.direction === 'asc';
|
const sortAscending = sort.direction === 'asc';
|
||||||
|
|
||||||
console.log('[Query] Applying sort:', {
|
console.log('[Query] Applying sort:', {
|
||||||
|
sortLevels: [
|
||||||
|
'1. escalated DESC (always first)',
|
||||||
|
`2. ${sortColumn} ${sortAscending ? 'ASC' : 'DESC'} (user selected)`,
|
||||||
|
sortColumn !== 'created_at' ? '3. created_at ASC (tie-breaker)' : null
|
||||||
|
].filter(Boolean),
|
||||||
uiField: sort.field,
|
uiField: sort.field,
|
||||||
dbColumn: sortColumn,
|
dbColumn: sortColumn,
|
||||||
direction: sort.direction,
|
direction: sort.direction,
|
||||||
ascending: sortAscending,
|
ascending: sortAscending,
|
||||||
sortObjectRef: sort,
|
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -273,6 +277,10 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
})(),
|
})(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Always prioritize escalated submissions first
|
||||||
|
submissionsQuery = submissionsQuery.order('escalated', { ascending: false });
|
||||||
|
|
||||||
|
// Then apply user-selected sort
|
||||||
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
||||||
|
|
||||||
// CRITICAL: Verify the query builder chain is working
|
// CRITICAL: Verify the query builder chain is working
|
||||||
@@ -281,7 +289,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
throw new Error('Supabase query builder is not functioning correctly');
|
throw new Error('Supabase query builder is not functioning correctly');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Secondary sort by created_at for consistency when primary sort has ties
|
// Tertiary sort by created_at for consistency (only if not already the user's sort choice)
|
||||||
if (sortColumn !== 'created_at') {
|
if (sortColumn !== 'created_at') {
|
||||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||||
}
|
}
|
||||||
@@ -387,14 +395,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
// VALIDATE: Log first few items to verify sort is working
|
// VALIDATE: Log first few items to verify sort is working
|
||||||
if (submissions && submissions.length > 0) {
|
if (submissions && submissions.length > 0) {
|
||||||
console.log('[Query] Results returned (first 3 items):', {
|
console.log('[Query] Results returned (first 3 items):', {
|
||||||
sortColumn,
|
sortLevels: `escalated DESC → ${sortColumn} ${sortAscending ? 'ASC' : 'DESC'}`,
|
||||||
sortDirection: sortAscending ? 'ASC' : 'DESC',
|
|
||||||
items: submissions.slice(0, 3).map(s => ({
|
items: submissions.slice(0, 3).map(s => ({
|
||||||
id: s.id.substring(0, 8),
|
id: s.id.substring(0, 8),
|
||||||
|
escalated: s.escalated,
|
||||||
type: s.submission_type,
|
type: s.submission_type,
|
||||||
status: s.status,
|
status: s.status,
|
||||||
created: s.created_at,
|
created: s.created_at,
|
||||||
escalated: s.escalated,
|
|
||||||
sortValue: s[sortColumn as keyof typeof s]
|
sortValue: s[sortColumn as keyof typeof s]
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user