File size: 5,267 Bytes
c2ea5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
/**
 * Trace Content Modal Component
 *
 * Modal for viewing and editing trace content, moved from the left panel
 */

import React from "react";
import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { Eye, Edit, AlertCircle, FileText } from "lucide-react";
import { Trace } from "@/types";

interface TraceContentModalProps {
  isOpen: boolean;
  onClose: () => void;
  trace: Trace;
  traceContent: string;
  traceContentLoading: boolean;
  traceContentError: string | null;
  onEditTrace: () => void;
}

export function TraceContentModal({
  isOpen,
  onClose,
  trace,
  traceContent,
  traceContentLoading,
  traceContentError,
  onEditTrace,
}: TraceContentModalProps) {
  return (
    <Dialog open={isOpen} onOpenChange={onClose}>
      <DialogContent className="max-w-6xl max-h-[90vh] flex flex-col">
        <DialogHeader className="flex-shrink-0">
          <div className="flex items-center justify-between">
            <div className="flex items-center gap-3">
              <div className="p-2 rounded-lg bg-primary/10">
                <Eye className="h-5 w-5 text-primary" />
              </div>
              <div>
                <DialogTitle className="text-lg">Trace Content</DialogTitle>
                <p className="text-sm text-muted-foreground">
                  View and edit the raw trace data
                </p>
              </div>
            </div>
            {traceContent && (
              <Button
                variant="outline"
                size="sm"
                onClick={() => {
                  onEditTrace();
                  onClose();
                }}
                className="gap-2 shrink-0"
              >
                <Edit className="h-4 w-4" />
                Edit
              </Button>
            )}
          </div>
        </DialogHeader>

        <div className="flex-1 overflow-hidden">
          <Card className="border-border h-full">
            <CardContent className="p-4 h-full">
              <div className="space-y-4 h-full flex flex-col">
                {/* Source Information Block */}
                {trace.description && (
                  <div className="bg-muted/30 rounded-lg p-3">
                    <h4 className="text-sm font-semibold mb-2 flex items-center gap-2">
                      <FileText className="h-4 w-4" />
                      Source Information
                    </h4>
                    <p className="text-xs text-muted-foreground">
                      {trace.description}
                    </p>
                  </div>
                )}

                {/* Content Display - Full Height */}
                <div className="flex-1 min-h-0">
                  {traceContentLoading ? (
                    <div className="flex flex-col items-center justify-center py-8 h-full">
                      <div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin mb-3" />
                      <p className="text-sm text-muted-foreground">
                        Loading trace content...
                      </p>
                    </div>
                  ) : traceContentError ? (
                    <div className="flex flex-col items-center justify-center py-8 text-center h-full">
                      <div className="p-3 rounded-full bg-destructive/10 mb-3">
                        <AlertCircle className="h-6 w-6 text-destructive" />
                      </div>
                      <p className="text-sm font-medium text-destructive mb-1">
                        Failed to Load Content
                      </p>
                      <p className="text-xs text-muted-foreground">
                        {traceContentError}
                      </p>
                    </div>
                  ) : traceContent ? (
                    <div className="w-full h-full">
                      <div className="bg-muted/30 rounded-lg border w-full h-full">
                        <div className="w-full h-full overflow-y-auto p-4">
                          <pre className="text-xs text-foreground whitespace-pre-wrap break-words font-mono leading-relaxed">
                            {traceContent}
                          </pre>
                        </div>
                      </div>
                    </div>
                  ) : (
                    <div className="flex flex-col items-center justify-center py-8 text-center h-full">
                      <div className="p-3 rounded-full bg-muted/50 mb-3">
                        <FileText className="h-6 w-6 text-muted-foreground" />
                      </div>
                      <p className="text-sm font-medium text-muted-foreground mb-1">
                        No Content Available
                      </p>
                      <p className="text-xs text-muted-foreground">
                        Content could not be loaded
                      </p>
                    </div>
                  )}
                </div>
              </div>
            </CardContent>
          </Card>
        </div>
      </DialogContent>
    </Dialog>
  );
}