Skip to content

Commit 30ce106

Browse files
committed
types fixes
1 parent c961037 commit 30ce106

File tree

7 files changed

+87
-47
lines changed

7 files changed

+87
-47
lines changed

apps/webapp/app/components/logs/LogDetailView.tsx

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { useEnvironment } from "~/hooks/useEnvironment";
2121
import { useOrganization } from "~/hooks/useOrganizations";
2222
import { useProject } from "~/hooks/useProject";
2323
import type { LogEntry } from "~/presenters/v3/LogsListPresenter.server";
24-
import { getLevelColor } from "~/utils/logUtils";
24+
import { getLevelColor, getKindColor, getKindLabel } from "~/utils/logUtils";
2525
import { v3RunSpanPath, v3RunsPath, v3DeploymentVersionPath } from "~/utils/pathBuilder";
2626
import type { loader as logDetailLoader } from "~/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.logs.$logId";
2727
import { TaskRunStatusCombo, descriptionForTaskRunStatus } from "~/components/runs/v3/TaskRunStatus";
@@ -54,46 +54,6 @@ type LogAttributes = Record<string, unknown> & {
5454
};
5555
};
5656

57-
// Event kind badge color styles
58-
function getKindColor(kind: string): string {
59-
if (kind === "SPAN") {
60-
return "text-purple-400 bg-purple-500/10 border-purple-500/20";
61-
}
62-
if (kind === "SPAN_EVENT") {
63-
return "text-amber-400 bg-amber-500/10 border-amber-500/20";
64-
}
65-
if (kind.startsWith("LOG_")) {
66-
return "text-blue-400 bg-blue-500/10 border-blue-500/20";
67-
}
68-
return "text-charcoal-400 bg-charcoal-700 border-charcoal-600";
69-
}
70-
71-
// Get human readable kind label
72-
function getKindLabel(kind: string): string {
73-
switch (kind) {
74-
case "SPAN":
75-
return "Span";
76-
case "SPAN_EVENT":
77-
return "Event";
78-
case "LOG_DEBUG":
79-
return "Log";
80-
case "LOG_INFO":
81-
return "Log";
82-
case "LOG_WARN":
83-
return "Log";
84-
case "LOG_ERROR":
85-
return "Log";
86-
case "LOG_LOG":
87-
return "Log";
88-
case "DEBUG_EVENT":
89-
return "Debug";
90-
case "ANCESTOR_OVERRIDE":
91-
return "Override";
92-
default:
93-
return kind;
94-
}
95-
}
96-
9757
function formatStringJSON(str: string): string {
9858
return str
9959
.replace(/\\n/g, "\n") // Converts literal "\n" to newline

apps/webapp/app/components/logs/LogsTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { PopoverMenuItem } from "~/components/primitives/Popover";
2828
type LogsTableProps = {
2929
logs: LogEntry[];
3030
hasFilters: boolean;
31-
filters: LogsListAppliedFilters;
3231
searchTerm?: string;
3332
isLoading?: boolean;
3433
isLoadingMore?: boolean;

apps/webapp/app/components/primitives/Table.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const variants = {
2222
},
2323
"bright/no-hover": {
2424
header: "bg-transparent",
25+
headerCell: "px-3 py-2.5 pb-3 text-sm",
2526
cell: "group-hover/table-row:bg-transparent",
27+
cellSize: "px-3 py-3",
28+
cellText: "text-xs",
2629
stickyCell: "bg-background-bright",
2730
menuButton: "bg-background-bright",
2831
menuButtonDivider: "",

apps/webapp/app/presenters/RunFilters.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type TaskRunStatus } from "@trigger.dev/database";
12
import {
23
getRunFiltersFromSearchParams,
34
TaskRunListSearchFilters,
@@ -39,7 +40,7 @@ export async function getRunFiltersFromRequest(request: Request): Promise<Filter
3940
return {
4041
tasks,
4142
versions,
42-
statuses,
43+
statuses: statuses as TaskRunStatus[] | undefined,
4344
tags,
4445
period,
4546
bulkId,

apps/webapp/app/presenters/v3/LogsListPresenter.server.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import { z } from "zod";
12
import { type ClickHouse, type LogsListResult } from "@internal/clickhouse";
23
import { MachinePresetName } from "@trigger.dev/core/v3";
34
import {
45
type PrismaClient,
56
type PrismaClientOrTransaction,
67
type TaskRunStatus,
8+
TaskRunStatus as TaskRunStatusEnum,
79
TaskTriggerSource,
810
} from "@trigger.dev/database";
11+
12+
// Create a schema that validates TaskRunStatus enum values
13+
const TaskRunStatusSchema = z.array(z.string()).refine(
14+
(val) => val.every((v) => Object.values(TaskRunStatusEnum).includes(v)),
15+
{ message: "Invalid TaskRunStatus values" }
16+
) as unknown as z.ZodSchema<TaskRunStatus[]>;
917
import parseDuration from "parse-duration";
1018
import { type Direction } from "~/components/ListPagination";
1119
import { timeFilters } from "~/components/runs/v3/SharedFilters";
@@ -57,6 +65,32 @@ export type LogsListOptions = {
5765
pageSize?: number;
5866
};
5967

68+
export const LogsListOptionsSchema = z.object({
69+
userId: z.string().optional(),
70+
projectId: z.string(),
71+
tasks: z.array(z.string()).optional(),
72+
versions: z.array(z.string()).optional(),
73+
statuses: TaskRunStatusSchema.optional(),
74+
tags: z.array(z.string()).optional(),
75+
scheduleId: z.string().optional(),
76+
period: z.string().optional(),
77+
bulkId: z.string().optional(),
78+
from: z.number().int().nonnegative().optional(),
79+
to: z.number().int().nonnegative().optional(),
80+
isTest: z.boolean().optional(),
81+
rootOnly: z.boolean().optional(),
82+
batchId: z.string().optional(),
83+
runId: z.array(z.string()).optional(),
84+
queues: z.array(z.string()).optional(),
85+
machines: z.array(z.string()).optional(),
86+
levels: z.array(z.enum(["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "CANCELLED"])).optional(),
87+
search: z.string().max(1000).optional(),
88+
includeDebugLogs: z.boolean().optional(),
89+
direction: z.enum(["forward", "backward"]).optional(),
90+
cursor: z.string().optional(),
91+
pageSize: z.number().int().positive().max(1000).optional(),
92+
});
93+
6094
const DEFAULT_PAGE_SIZE = 50;
6195
const MAX_RUN_IDS = 5000;
6296

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.logs.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EnvironmentParamSchema } from "~/utils/pathBuilder";
55
import { findProjectBySlug } from "~/models/project.server";
66
import { findEnvironmentBySlug } from "~/models/runtimeEnvironment.server";
77
import { getRunFiltersFromRequest } from "~/presenters/RunFilters.server";
8-
import { LogsListPresenter, type LogLevel } from "~/presenters/v3/LogsListPresenter.server";
8+
import { LogsListPresenter, type LogLevel, LogsListOptionsSchema } from "~/presenters/v3/LogsListPresenter.server";
99
import { $replica } from "~/db.server";
1010
import { clickhouseClient } from "~/services/clickhouseInstance.server";
1111

@@ -44,16 +44,19 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
4444
const levels = parseLevelsFromUrl(url);
4545
const showDebug = url.searchParams.get("showDebug") === "true";
4646

47-
const presenter = new LogsListPresenter($replica, clickhouseClient);
48-
const result = await presenter.call(project.organizationId, environment.id, {
47+
48+
const options = LogsListOptionsSchema.parse({
4949
userId,
5050
projectId: project.id,
5151
...filters,
5252
search,
5353
cursor,
5454
levels,
5555
includeDebugLogs: isAdmin && showDebug,
56-
});
56+
}) as any; // Validated by LogsListOptionsSchema at runtime
57+
58+
const presenter = new LogsListPresenter($replica, clickhouseClient);
59+
const result = await presenter.call(project.organizationId, environment.id, options);
5760

5861
return json({
5962
logs: result.logs,

apps/webapp/app/utils/logUtils.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,43 @@ export function getLevelColor(level: LogLevel): string {
107107
return "text-text-dimmed bg-charcoal-750 border-charcoal-700";
108108
}
109109
}
110+
111+
// Event kind badge color styles
112+
export function getKindColor(kind: string): string {
113+
if (kind === "SPAN") {
114+
return "text-purple-400 bg-purple-500/10 border-purple-500/20";
115+
}
116+
if (kind === "SPAN_EVENT") {
117+
return "text-amber-400 bg-amber-500/10 border-amber-500/20";
118+
}
119+
if (kind.startsWith("LOG_")) {
120+
return "text-blue-400 bg-blue-500/10 border-blue-500/20";
121+
}
122+
return "text-charcoal-400 bg-charcoal-700 border-charcoal-600";
123+
}
124+
125+
// Get human readable kind label
126+
export function getKindLabel(kind: string): string {
127+
switch (kind) {
128+
case "SPAN":
129+
return "Span";
130+
case "SPAN_EVENT":
131+
return "Event";
132+
case "LOG_DEBUG":
133+
return "Log";
134+
case "LOG_INFO":
135+
return "Log";
136+
case "LOG_WARN":
137+
return "Log";
138+
case "LOG_ERROR":
139+
return "Log";
140+
case "LOG_LOG":
141+
return "Log";
142+
case "DEBUG_EVENT":
143+
return "Debug";
144+
case "ANCESTOR_OVERRIDE":
145+
return "Override";
146+
default:
147+
return kind;
148+
}
149+
}

0 commit comments

Comments
 (0)