Fix: Remove invalid sort options and validate sort fields

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 01:28:49 +00:00
parent 3b568712d9
commit ad096b05c6
2 changed files with 9 additions and 8 deletions

View File

@@ -15,7 +15,6 @@ interface QueueSortControlsProps {
const getSortFieldLabel = (field: SortField): string => { const getSortFieldLabel = (field: SortField): string => {
switch (field) { switch (field) {
case 'created_at': return 'Date Created'; case 'created_at': return 'Date Created';
case 'username': return 'Submitter';
case 'submission_type': return 'Type'; case 'submission_type': return 'Type';
case 'status': return 'Status'; case 'status': return 'Status';
case 'escalated': return 'Escalated'; case 'escalated': return 'Escalated';
@@ -58,7 +57,6 @@ export const QueueSortControls = ({
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="created_at">{getSortFieldLabel('created_at')}</SelectItem> <SelectItem value="created_at">{getSortFieldLabel('created_at')}</SelectItem>
<SelectItem value="username">{getSortFieldLabel('username')}</SelectItem>
<SelectItem value="submission_type">{getSortFieldLabel('submission_type')}</SelectItem> <SelectItem value="submission_type">{getSortFieldLabel('submission_type')}</SelectItem>
<SelectItem value="status">{getSortFieldLabel('status')}</SelectItem> <SelectItem value="status">{getSortFieldLabel('status')}</SelectItem>
<SelectItem value="escalated">{getSortFieldLabel('escalated')}</SelectItem> <SelectItem value="escalated">{getSortFieldLabel('escalated')}</SelectItem>

View File

@@ -223,14 +223,17 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
`, `,
); );
// Map sort fields to correct database columns // Validate sort field is an actual column in content_submissions
const sortField = const validSortFields = ['created_at', 'submission_type', 'status', 'escalated', 'submitted_at'];
sort.config.field === 'username' ? 'user_id' : let sortField = sort.config.field;
sort.config.field;
if (!validSortFields.includes(sortField)) {
console.warn('[Query] Invalid sort field:', sortField, '- falling back to created_at');
sortField = 'created_at';
}
console.log('[Query] Sorting by:', { console.log('[Query] Sorting by:', {
originalField: sort.config.field, field: sortField,
mappedField: sortField,
direction: sort.config.direction, direction: sort.config.direction,
ascending: sort.config.direction === 'asc' ascending: sort.config.direction === 'asc'
}); });