mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-29 13:07:07 -05:00
Compare commits
6 Commits
b22546e7f2
...
edit/edt-f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
809b5c7287 | ||
|
|
db111d7a68 | ||
|
|
aed16f688a | ||
|
|
a35486fb11 | ||
|
|
3d3ae57ee3 | ||
|
|
46c08e10e8 |
67
src/components/moderation/DetailedViewCollapsible.tsx
Normal file
67
src/components/moderation/DetailedViewCollapsible.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { ChevronDown, ChevronUp } from 'lucide-react';
|
||||||
|
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@/components/ui/collapsible';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface DetailedViewCollapsibleProps {
|
||||||
|
isCollapsed: boolean;
|
||||||
|
onToggle: () => void;
|
||||||
|
children: React.ReactNode;
|
||||||
|
fieldCount?: number;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collapsible wrapper for detailed field-by-field view sections
|
||||||
|
* Provides expand/collapse functionality with visual indicators
|
||||||
|
*/
|
||||||
|
export function DetailedViewCollapsible({
|
||||||
|
isCollapsed,
|
||||||
|
onToggle,
|
||||||
|
children,
|
||||||
|
fieldCount,
|
||||||
|
className
|
||||||
|
}: DetailedViewCollapsibleProps) {
|
||||||
|
return (
|
||||||
|
<Collapsible open={!isCollapsed} onOpenChange={() => onToggle()}>
|
||||||
|
<div className={cn("mt-6 pt-6 border-t", className)}>
|
||||||
|
<CollapsibleTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="w-full flex items-center justify-between hover:bg-muted/50 p-2 h-auto transition-colors"
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
|
||||||
|
All Fields (Detailed View)
|
||||||
|
</span>
|
||||||
|
{fieldCount !== undefined && fieldCount > 0 && (
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className="h-5 px-1.5 text-xs font-normal transition-transform duration-200 hover:scale-105"
|
||||||
|
>
|
||||||
|
{fieldCount}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-xs text-muted-foreground normal-case font-normal">
|
||||||
|
{isCollapsed ? 'Show' : 'Hide'}
|
||||||
|
</span>
|
||||||
|
{isCollapsed ? (
|
||||||
|
<ChevronDown className="h-4 w-4 text-muted-foreground transition-transform duration-200" />
|
||||||
|
) : (
|
||||||
|
<ChevronUp className="h-4 w-4 text-muted-foreground transition-transform duration-200" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</CollapsibleTrigger>
|
||||||
|
|
||||||
|
<CollapsibleContent className="mt-3 data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down">
|
||||||
|
{children}
|
||||||
|
</CollapsibleContent>
|
||||||
|
</div>
|
||||||
|
</Collapsible>
|
||||||
|
);
|
||||||
|
}
|
||||||
125
src/components/moderation/ItemLevelApprovalHistory.tsx
Normal file
125
src/components/moderation/ItemLevelApprovalHistory.tsx
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
import { memo } from 'react';
|
||||||
|
import { formatDistanceToNow } from 'date-fns';
|
||||||
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { CheckCircle2, User } from 'lucide-react';
|
||||||
|
import type { SubmissionItem } from '@/types/moderation';
|
||||||
|
|
||||||
|
interface ItemLevelApprovalHistoryProps {
|
||||||
|
items: SubmissionItem[];
|
||||||
|
reviewerProfile?: {
|
||||||
|
user_id: string;
|
||||||
|
username: string;
|
||||||
|
display_name?: string | null;
|
||||||
|
avatar_url?: string | null;
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ItemLevelApprovalHistory = memo(({
|
||||||
|
items,
|
||||||
|
reviewerProfile,
|
||||||
|
}: ItemLevelApprovalHistoryProps) => {
|
||||||
|
// Filter to only approved items with timestamps
|
||||||
|
const approvedItems = items.filter(
|
||||||
|
item => item.status === 'approved' && (item as any).approved_at
|
||||||
|
);
|
||||||
|
|
||||||
|
if (approvedItems.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by approval time (newest first)
|
||||||
|
const sortedItems = [...approvedItems].sort((a, b) => {
|
||||||
|
const timeA = new Date((a as any).approved_at).getTime();
|
||||||
|
const timeB = new Date((b as any).approved_at).getTime();
|
||||||
|
return timeB - timeA;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Helper to get item display name
|
||||||
|
const getItemName = (item: SubmissionItem): string => {
|
||||||
|
const entityData = item.entity_data || item.item_data;
|
||||||
|
if (entityData && typeof entityData === 'object' && 'name' in entityData) {
|
||||||
|
return String(entityData.name);
|
||||||
|
}
|
||||||
|
return `${item.item_type} #${item.order_index}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to get action label
|
||||||
|
const getActionLabel = (actionType: string): string => {
|
||||||
|
switch (actionType) {
|
||||||
|
case 'create': return 'Created';
|
||||||
|
case 'edit': return 'Edited';
|
||||||
|
case 'delete': return 'Deleted';
|
||||||
|
default: return 'Modified';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-2">
|
||||||
|
<CheckCircle2 className="h-3.5 w-3.5" />
|
||||||
|
Item Approvals
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
{sortedItems.map((item) => {
|
||||||
|
const approvedAt = (item as any).approved_at;
|
||||||
|
const itemName = getItemName(item);
|
||||||
|
const actionLabel = getActionLabel(item.action_type);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={item.id}
|
||||||
|
className="flex items-start gap-3 text-sm bg-success/5 border border-success/20 rounded-md p-3"
|
||||||
|
>
|
||||||
|
{/* Approval Icon */}
|
||||||
|
<div className="flex-shrink-0 mt-0.5">
|
||||||
|
<CheckCircle2 className="h-4 w-4 text-success" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Item Info */}
|
||||||
|
<div className="flex-1 min-w-0 space-y-1">
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
|
<span className="font-medium text-foreground truncate">
|
||||||
|
{itemName}
|
||||||
|
</span>
|
||||||
|
<Badge variant="outline" className="text-xs">
|
||||||
|
{actionLabel}
|
||||||
|
</Badge>
|
||||||
|
<Badge variant="secondary" className="text-xs font-mono">
|
||||||
|
{item.item_type}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<span className="text-xs text-muted-foreground whitespace-nowrap">
|
||||||
|
{formatDistanceToNow(new Date(approvedAt), { addSuffix: true })}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Reviewer Info */}
|
||||||
|
{reviewerProfile && (
|
||||||
|
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<Avatar className="h-5 w-5">
|
||||||
|
<AvatarImage src={reviewerProfile.avatar_url ?? undefined} />
|
||||||
|
<AvatarFallback className="text-[10px]">
|
||||||
|
<User className="h-3 w-3" />
|
||||||
|
</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<span>
|
||||||
|
Approved by{' '}
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
{reviewerProfile.display_name || reviewerProfile.username}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ItemLevelApprovalHistory.displayName = 'ItemLevelApprovalHistory';
|
||||||
@@ -23,6 +23,7 @@ import { QueueItemActions } from './renderers/QueueItemActions';
|
|||||||
import { SubmissionMetadataPanel } from './SubmissionMetadataPanel';
|
import { SubmissionMetadataPanel } from './SubmissionMetadataPanel';
|
||||||
import { AuditTrailViewer } from './AuditTrailViewer';
|
import { AuditTrailViewer } from './AuditTrailViewer';
|
||||||
import { RawDataViewer } from './RawDataViewer';
|
import { RawDataViewer } from './RawDataViewer';
|
||||||
|
import { ItemLevelApprovalHistory } from './ItemLevelApprovalHistory';
|
||||||
|
|
||||||
interface QueueItemProps {
|
interface QueueItemProps {
|
||||||
item: ModerationItem;
|
item: ModerationItem;
|
||||||
@@ -330,6 +331,15 @@ export const QueueItem = memo(({
|
|||||||
{item.type === 'content_submission' && (
|
{item.type === 'content_submission' && (
|
||||||
<div className="mt-6 space-y-4">
|
<div className="mt-6 space-y-4">
|
||||||
<SubmissionMetadataPanel item={item} />
|
<SubmissionMetadataPanel item={item} />
|
||||||
|
|
||||||
|
{/* Item-level approval history */}
|
||||||
|
{item.submission_items && item.submission_items.length > 0 && (
|
||||||
|
<ItemLevelApprovalHistory
|
||||||
|
items={item.submission_items}
|
||||||
|
reviewerProfile={item.reviewer_profile}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<AuditTrailViewer submissionId={item.id} />
|
<AuditTrailViewer submissionId={item.id} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { RichRideDisplay } from './displays/RichRideDisplay';
|
|||||||
import { RichCompanyDisplay } from './displays/RichCompanyDisplay';
|
import { RichCompanyDisplay } from './displays/RichCompanyDisplay';
|
||||||
import { RichRideModelDisplay } from './displays/RichRideModelDisplay';
|
import { RichRideModelDisplay } from './displays/RichRideModelDisplay';
|
||||||
import { RichTimelineEventDisplay } from './displays/RichTimelineEventDisplay';
|
import { RichTimelineEventDisplay } from './displays/RichTimelineEventDisplay';
|
||||||
|
import { DetailedViewCollapsible } from './DetailedViewCollapsible';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
@@ -17,6 +18,7 @@ import type { ParkSubmissionData, RideSubmissionData, CompanySubmissionData, Rid
|
|||||||
import type { TimelineSubmissionData } from '@/types/timeline';
|
import type { TimelineSubmissionData } from '@/types/timeline';
|
||||||
import { getErrorMessage, handleNonCriticalError } from '@/lib/errorHandler';
|
import { getErrorMessage, handleNonCriticalError } from '@/lib/errorHandler';
|
||||||
import { ModerationErrorBoundary } from '@/components/error/ModerationErrorBoundary';
|
import { ModerationErrorBoundary } from '@/components/error/ModerationErrorBoundary';
|
||||||
|
import { useDetailedViewState } from '@/hooks/useDetailedViewState';
|
||||||
|
|
||||||
interface SubmissionItemsListProps {
|
interface SubmissionItemsListProps {
|
||||||
submissionId: string;
|
submissionId: string;
|
||||||
@@ -34,11 +36,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const { isCollapsed, toggle } = useDetailedViewState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchSubmissionItems();
|
fetchSubmissionItems();
|
||||||
}, [submissionId]);
|
}, [submissionId]);
|
||||||
|
|
||||||
|
// Helper function to count non-null fields in entity data
|
||||||
|
const countFields = (data: any): number => {
|
||||||
|
if (!data || typeof data !== 'object') return 0;
|
||||||
|
return Object.values(data).filter(value => value !== null && value !== undefined).length;
|
||||||
|
};
|
||||||
|
|
||||||
const fetchSubmissionItems = async () => {
|
const fetchSubmissionItems = async () => {
|
||||||
try {
|
try {
|
||||||
// Only show skeleton on initial load, show refreshing indicator on refresh
|
// Only show skeleton on initial load, show refreshing indicator on refresh
|
||||||
@@ -188,17 +197,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
data={entityData as unknown as ParkSubmissionData}
|
data={entityData as unknown as ParkSubmissionData}
|
||||||
actionType={actionType}
|
actionType={actionType}
|
||||||
/>
|
/>
|
||||||
<div className="mt-6 pt-6 border-t">
|
<DetailedViewCollapsible
|
||||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3">
|
isCollapsed={isCollapsed}
|
||||||
All Fields (Detailed View)
|
onToggle={toggle}
|
||||||
</div>
|
fieldCount={countFields(entityData)}
|
||||||
|
>
|
||||||
<SubmissionChangesDisplay
|
<SubmissionChangesDisplay
|
||||||
item={item}
|
item={item}
|
||||||
view="detailed"
|
view="detailed"
|
||||||
showImages={showImages}
|
showImages={showImages}
|
||||||
submissionId={submissionId}
|
submissionId={submissionId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</DetailedViewCollapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -211,17 +221,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
data={entityData as unknown as RideSubmissionData}
|
data={entityData as unknown as RideSubmissionData}
|
||||||
actionType={actionType}
|
actionType={actionType}
|
||||||
/>
|
/>
|
||||||
<div className="mt-6 pt-6 border-t">
|
<DetailedViewCollapsible
|
||||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3">
|
isCollapsed={isCollapsed}
|
||||||
All Fields (Detailed View)
|
onToggle={toggle}
|
||||||
</div>
|
fieldCount={countFields(entityData)}
|
||||||
|
>
|
||||||
<SubmissionChangesDisplay
|
<SubmissionChangesDisplay
|
||||||
item={item}
|
item={item}
|
||||||
view="detailed"
|
view="detailed"
|
||||||
showImages={showImages}
|
showImages={showImages}
|
||||||
submissionId={submissionId}
|
submissionId={submissionId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</DetailedViewCollapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -234,17 +245,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
data={entityData as unknown as CompanySubmissionData}
|
data={entityData as unknown as CompanySubmissionData}
|
||||||
actionType={actionType}
|
actionType={actionType}
|
||||||
/>
|
/>
|
||||||
<div className="mt-6 pt-6 border-t">
|
<DetailedViewCollapsible
|
||||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3">
|
isCollapsed={isCollapsed}
|
||||||
All Fields (Detailed View)
|
onToggle={toggle}
|
||||||
</div>
|
fieldCount={countFields(entityData)}
|
||||||
|
>
|
||||||
<SubmissionChangesDisplay
|
<SubmissionChangesDisplay
|
||||||
item={item}
|
item={item}
|
||||||
view="detailed"
|
view="detailed"
|
||||||
showImages={showImages}
|
showImages={showImages}
|
||||||
submissionId={submissionId}
|
submissionId={submissionId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</DetailedViewCollapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -257,17 +269,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
data={entityData as unknown as RideModelSubmissionData}
|
data={entityData as unknown as RideModelSubmissionData}
|
||||||
actionType={actionType}
|
actionType={actionType}
|
||||||
/>
|
/>
|
||||||
<div className="mt-6 pt-6 border-t">
|
<DetailedViewCollapsible
|
||||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3">
|
isCollapsed={isCollapsed}
|
||||||
All Fields (Detailed View)
|
onToggle={toggle}
|
||||||
</div>
|
fieldCount={countFields(entityData)}
|
||||||
|
>
|
||||||
<SubmissionChangesDisplay
|
<SubmissionChangesDisplay
|
||||||
item={item}
|
item={item}
|
||||||
view="detailed"
|
view="detailed"
|
||||||
showImages={showImages}
|
showImages={showImages}
|
||||||
submissionId={submissionId}
|
submissionId={submissionId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</DetailedViewCollapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -280,17 +293,18 @@ export const SubmissionItemsList = memo(function SubmissionItemsList({
|
|||||||
data={entityData as unknown as TimelineSubmissionData}
|
data={entityData as unknown as TimelineSubmissionData}
|
||||||
actionType={actionType}
|
actionType={actionType}
|
||||||
/>
|
/>
|
||||||
<div className="mt-6 pt-6 border-t">
|
<DetailedViewCollapsible
|
||||||
<div className="text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3">
|
isCollapsed={isCollapsed}
|
||||||
All Fields (Detailed View)
|
onToggle={toggle}
|
||||||
</div>
|
fieldCount={countFields(entityData)}
|
||||||
|
>
|
||||||
<SubmissionChangesDisplay
|
<SubmissionChangesDisplay
|
||||||
item={item}
|
item={item}
|
||||||
view="detailed"
|
view="detailed"
|
||||||
showImages={showImages}
|
showImages={showImages}
|
||||||
submissionId={submissionId}
|
submissionId={submissionId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</DetailedViewCollapsible>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
48
src/hooks/useDetailedViewState.ts
Normal file
48
src/hooks/useDetailedViewState.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'detailed-view-collapsed';
|
||||||
|
|
||||||
|
interface UseDetailedViewStateReturn {
|
||||||
|
isCollapsed: boolean;
|
||||||
|
toggle: () => void;
|
||||||
|
setCollapsed: (value: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook to manage detailed view collapsed/expanded state
|
||||||
|
* Syncs with localStorage for persistence across sessions
|
||||||
|
* Defaults to collapsed to reduce visual clutter
|
||||||
|
*/
|
||||||
|
export function useDetailedViewState(): UseDetailedViewStateReturn {
|
||||||
|
const [isCollapsed, setIsCollapsed] = useState<boolean>(() => {
|
||||||
|
// Initialize from localStorage on mount
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
|
// Default to collapsed (true) to reduce visual clutter
|
||||||
|
return stored ? JSON.parse(stored) : true;
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn('Error reading detailed view state from localStorage', { error });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Sync to localStorage when state changes
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(isCollapsed));
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn('Error saving detailed view state to localStorage', { error });
|
||||||
|
}
|
||||||
|
}, [isCollapsed]);
|
||||||
|
|
||||||
|
const toggle = () => setIsCollapsed(prev => !prev);
|
||||||
|
|
||||||
|
const setCollapsed = (value: boolean) => setIsCollapsed(value);
|
||||||
|
|
||||||
|
return {
|
||||||
|
isCollapsed,
|
||||||
|
toggle,
|
||||||
|
setCollapsed,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user