All files / components/macros MacroDetailDialog.tsx

84.61% Statements 11/13
87.5% Branches 7/8
80% Functions 4/5
83.33% Lines 10/12

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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132                                                      70x   10x 10x 10x         10x                                     1x 1x                   1x 1x                                                                               9x                                                
/**
 * Macro detail dialog component (Read-only)
 */
 
import { AppDialog } from '@/components/common/AppDialog';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Badge } from '@/components/ui/badge';
import { Calendar, User, Code2, Info, Terminal } from 'lucide-react';
import type { Macro } from '@/types/macro';
import { format } from 'date-fns';
 
interface MacroDetailDialogProps {
    open: boolean;
    onOpenChange: (open: boolean) => void;
    macro: Macro | null;
    onTest: (macro: Macro) => void;
    onEdit: (macro: Macro) => void;
}
 
export default function MacroDetailDialog({
    open,
    onOpenChange,
    macro,
    onTest,
    onEdit,
}: MacroDetailDialogProps) {
    if (!macro) return null;
 
    let params: string[] = [];
    try {
        params = JSON.parse(macro.parameters);
    } catch {
        params = [];
    }
 
    return (
        <AppDialog
            open={open}
            onOpenChange={onOpenChange}
            title={
                <span className="text-2xl flex items-center gap-2">
                    <span className="text-primary">@</span>
                    {macro.name}
                </span>
            }
            description={macro.description || 'No description provided.'}
            className="max-w-2xl"
            footer={
                <div className="flex gap-2 w-full sm:w-auto justify-between w-full">
                    <div className="flex gap-2">
                        <Button
                            variant="secondary"
                            className="flex-1 sm:flex-none gap-2"
                            onClick={() => {
                                onOpenChange(false);
                                onTest(macro);
                            }}
                        >
                            <Terminal className="h-4 w-4" />
                            Test Macro
                        </Button>
                        <Button
                            variant="outline"
                            className="flex-1 sm:flex-none"
                            onClick={() => {
                                onOpenChange(false);
                                onEdit(macro);
                            }}
                        >
                            Edit
                        </Button>
                    </div>
                    <Button variant="ghost" onClick={() => onOpenChange(false)}>
                        Close
                    </Button>
                </div>
            }
        >
            <div className="space-y-6">
                <div className="flex items-center gap-2 mb-1">
                    <Badge variant="outline" className="text-primary border-primary/20 bg-primary/5">
                        Macro
                    </Badge>
                    <span className="text-sm text-muted-foreground font-mono">ID: {macro.id}</span>
                </div>
 
                {/* Metadata Grid */}
                <div className="grid grid-cols-2 gap-4">
                    <div className="flex items-center gap-2 text-sm text-muted-foreground">
                        <Calendar className="h-4 w-4" />
                        <span>Updated: {format(new Date(macro.updated_at), 'PPP pp')}</span>
                    </div>
                    <div className="flex items-center gap-2 text-sm text-muted-foreground">
                        <User className="h-4 w-4" />
                        <span>Created by: {macro.created_by || 'System'}</span>
                    </div>
                </div>
 
                {/* Parameters Section */}
                <div className="space-y-3">
                    <Label className="text-xs uppercase text-muted-foreground font-semibold flex items-center gap-1.5">
                        <Info className="h-3.5 w-3.5" />
                        Parameters ({params.length})
                    </Label>
                    <div className="flex flex-wrap gap-2">
                        {params.map((param, index) => (
                            <Badge key={index} variant="secondary">
                                {param}
                            </Badge>
                        ))}
                        {params.length === 0 && (
                            <span className="text-sm text-muted-foreground italic">No parameters</span>
                        )}
                    </div>
                </div>
 
                {/* SQL Section */}
                <div className="space-y-3">
                    <Label className="text-xs uppercase text-muted-foreground font-semibold flex items-center gap-1.5">
                        <Code2 className="h-3.5 w-3.5" />
                        SQL Implementation
                    </Label>
                    <div className="bg-slate-950 text-slate-50 p-4 rounded-lg font-mono text-sm overflow-x-auto whitespace-pre leading-relaxed shadow-inner">
                        {macro.sql_query}
                    </div>
                </div>
            </div>
        </AppDialog>
    );
}