All files / components/collections ViewCollectionDialog.tsx

80% Statements 4/5
89.47% Branches 17/19
66.66% Functions 2/3
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                                          69x   11x                                                     44x                                                                                                  
/**
 * View collection dialog component
 * Displays collection schema in read-only mode
 */
 
import { AppDialog } from '@/components/common/AppDialog';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import type { Collection } from '@/services/collections.service';
 
interface ViewCollectionDialogProps {
    open: boolean;
    onOpenChange: (open: boolean) => void;
    collection: Collection | null;
}
 
export default function ViewCollectionDialog({
    open,
    onOpenChange,
    collection,
}: ViewCollectionDialogProps) {
    if (!collection) return null;
 
    return (
        <AppDialog
            open={open}
            onOpenChange={onOpenChange}
            title={collection.name}
            description={`Collection schema with ${collection.schema.length} fields`}
            className="max-w-2xl"
            footer={
                <Button variant="outline" onClick={() => onOpenChange(false)}>Close</Button>
            }
        >
            <div className="space-y-4">
                <div className="grid grid-cols-2 gap-4 text-sm">
                    <div>
                        <span className="text-muted-foreground">ID:</span>
                        <span className="ml-2 font-mono">{collection.id}</span>
                    </div>
                    <div>
                        <span className="text-muted-foreground">Table:</span>
                        <span className="ml-2 font-mono">{collection.table_name}</span>
                    </div>
                </div>
 
                <div>
                    <h3 className="font-semibold mb-3">Fields</h3>
                    <div className="space-y-3">
                        {collection.schema.map((field, index) => (
                            <div
                                key={index}
                                className="border rounded-lg p-4 space-y-2"
                            >
                                <div className="flex items-center justify-between">
                                    <span className="font-medium">{field.name}</span>
                                    <div className="flex gap-2">
                                        <Badge variant="secondary">{field.type}</Badge>
                                        {field.required && <Badge>Required</Badge>}
                                        {field.unique && <Badge>Unique</Badge>}
                                        {field.pii && <Badge variant="destructive">PII</Badge>}
                                    </div>
                                </div>
                                {field.default !== null && field.default !== undefined && (
                                    <div className="text-sm text-muted-foreground">
                                        Default: <span className="font-mono">{String(field.default)}</span>
                                    </div>
                                )}
                                {field.type === 'reference' && field.collection && (
                                    <div className="text-sm text-muted-foreground">
                                        References: <span className="font-mono">{field.collection}</span>
                                        {field.on_delete && ` (on delete: ${field.on_delete})`}
                                    </div>
                                )}
                                {field.pii && field.mask_type && (
                                    <div className="text-sm text-muted-foreground">
                                        Mask type: {field.mask_type}
                                    </div>
                                )}
                            </div>
                        ))}
                    </div>
                </div>
 
                <div className="bg-muted/50 rounded-lg p-4">
                    <h4 className="font-medium mb-2 text-sm">System Fields (Auto-added)</h4>
                    <div className="text-sm text-muted-foreground space-y-1">
                        <div>• id (TEXT PRIMARY KEY)</div>
                        <div>• account_id (TEXT NOT NULL)</div>
                        <div>• created_at (DATETIME)</div>
                        <div>• created_by (TEXT)</div>
                        <div>• updated_at (DATETIME)</div>
                        <div>• updated_by (TEXT)</div>
                    </div>
                </div>
            </div>
        </AppDialog>
    );
}