-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSpanTitle.tsx
More file actions
243 lines (225 loc) · 5.82 KB
/
SpanTitle.tsx
File metadata and controls
243 lines (225 loc) · 5.82 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import { ChevronRightIcon } from "@heroicons/react/20/solid";
import { TaskEventStyle } from "@trigger.dev/core/v3";
import type { TaskEventLevel } from "@trigger.dev/database";
import { Fragment } from "react";
import { cn } from "~/utils/cn";
import { tablerIcons } from "~/utils/tablerIcons";
import tablerSpritePath from "~/components/primitives/tabler-sprite.svg";
type SpanTitleProps = {
message: string;
isError: boolean;
style: TaskEventStyle;
level: TaskEventLevel;
isPartial: boolean;
size: "small" | "large";
hideAccessory?: boolean;
};
export function SpanTitle(event: SpanTitleProps) {
return (
<span className={cn("flex items-center gap-x-2 overflow-x-hidden", eventTextClassName(event))}>
<span className="truncate">{event.message}</span>{" "}
{!event.hideAccessory && (
<SpanAccessory accessory={event.style.accessory} size={event.size} />
)}
</span>
);
}
function SpanAccessory({
accessory,
size,
}: {
accessory: TaskEventStyle["accessory"];
size: SpanTitleProps["size"];
}) {
if (!accessory) {
return null;
}
switch (accessory.style) {
case "codepath": {
return (
<SpanCodePathAccessory
accessory={accessory}
className={cn("overflow-x-hidden", size === "large" ? "text-sm" : "text-xs")}
/>
);
}
case "pills": {
return (
<div className="flex items-center gap-1">
{accessory.items.map((item, index) => (
<SpanPill key={index} text={item.text} icon={item.icon} />
))}
</div>
);
}
default: {
return (
<div className={cn("flex gap-1")}>
{accessory.items.map((item, index) => (
<span key={index} className={cn("inline-flex items-center gap-1")}>
{item.text}
</span>
))}
</div>
);
}
}
}
function SpanPill({ text, icon }: { text: string; icon?: string }) {
const hasIcon = icon && tablerIcons.has(icon);
return (
<span className="inline-flex items-center gap-0.5 rounded-full border border-charcoal-700 bg-charcoal-850 px-1.5 py-px text-xxs text-text-dimmed">
{hasIcon && (
<svg className="size-3 stroke-[1.5] text-text-dimmed/70">
<use xlinkHref={`${tablerSpritePath}#${icon}`} />
</svg>
)}
<span className="truncate">{text}</span>
</span>
);
}
export function SpanCodePathAccessory({
accessory,
className,
}: {
accessory: NonNullable<TaskEventStyle["accessory"]>;
className?: string;
}) {
return (
<code
className={cn(
"inline-flex items-center gap-0.5 truncate rounded border border-charcoal-700 bg-charcoal-800 px-1.5 py-0.5 font-mono text-text-dimmed",
className
)}
>
{accessory.items.map((item, index) => (
<Fragment key={index}>
<span className={cn("truncate", "text-text-dimmed")}>{item.text}</span>
{index < accessory.items.length - 1 && (
<span className="text-text-dimmed">
<ChevronRightIcon className="size-4" />
</span>
)}
</Fragment>
))}
</code>
);
}
function eventTextClassName(event: Pick<SpanTitleProps, "isError" | "style" | "level">) {
switch (event.level) {
case "TRACE": {
return textClassNameForVariant(event.style.variant);
}
case "LOG":
case "INFO":
case "DEBUG": {
return textClassNameForVariant(event.style.variant);
}
case "WARN": {
return "text-amber-400";
}
case "ERROR": {
return "text-error";
}
default: {
return textClassNameForVariant(event.style.variant);
}
}
}
type RunEvent = {
isError: boolean;
style: TaskEventStyle;
level: TaskEventLevel;
isPartial: boolean;
isCancelled: boolean;
};
export function eventBackgroundClassName(event: RunEvent) {
if (event.isError) {
return "bg-error";
}
if (event.isCancelled) {
return "bg-charcoal-600";
}
switch (event.level) {
case "TRACE": {
return backgroundClassNameForVariant(event.style.variant, event.isPartial);
}
case "LOG":
case "INFO":
case "DEBUG": {
return backgroundClassNameForVariant(event.style.variant, event.isPartial);
}
case "WARN": {
return "bg-amber-400";
}
case "ERROR": {
return "bg-error";
}
default: {
return backgroundClassNameForVariant(event.style.variant, event.isPartial);
}
}
}
export function eventBorderClassName(event: RunEvent) {
if (event.isError) {
return "border-error";
}
if (event.isCancelled) {
return "border-charcoal-600";
}
switch (event.level) {
case "TRACE": {
return borderClassNameForVariant(event.style.variant, event.isPartial);
}
case "LOG":
case "INFO":
case "DEBUG": {
return borderClassNameForVariant(event.style.variant, event.isPartial);
}
case "WARN": {
return "border-amber-400";
}
case "ERROR": {
return "border-error";
}
default: {
return borderClassNameForVariant(event.style.variant, event.isPartial);
}
}
}
function textClassNameForVariant(variant: TaskEventStyle["variant"]) {
switch (variant) {
case "primary": {
return "text-blue-500";
}
default: {
return "text-text-dimmed";
}
}
}
function backgroundClassNameForVariant(variant: TaskEventStyle["variant"], isPartial: boolean) {
switch (variant) {
case "primary": {
if (isPartial) {
return "bg-blue-500";
}
return "bg-success";
}
default: {
return "bg-charcoal-500";
}
}
}
function borderClassNameForVariant(variant: TaskEventStyle["variant"], isPartial: boolean) {
switch (variant) {
case "primary": {
if (isPartial) {
return "border-blue-500";
}
return "border-success";
}
default: {
return "border-charcoal-500";
}
}
}