Skip to content

Commit 67ec4f0

Browse files
committed
Switched structure around again so we only call the useTrace hook from the client
1 parent e63ee9e commit 67ec4f0

File tree

1 file changed

+46
-37
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam

1 file changed

+46
-37
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam/route.tsx

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
StopCircleIcon,
1010
} from "@heroicons/react/20/solid";
1111
import type { Location } from "@remix-run/react";
12-
import { useLocation, useParams } from "@remix-run/react";
12+
import { useParams } from "@remix-run/react";
1313
import { LoaderFunctionArgs } from "@remix-run/server-runtime";
1414
import { Virtualizer } from "@tanstack/react-virtual";
1515
import {
@@ -64,7 +64,7 @@ import { useOrganization } from "~/hooks/useOrganizations";
6464
import { useProject } from "~/hooks/useProject";
6565
import { useReplaceLocation } from "~/hooks/useReplaceLocation";
6666
import { Shortcut, useShortcutKeys } from "~/hooks/useShortcutKeys";
67-
import { Trace, TraceEvent, useTrace } from "~/hooks/useTrace";
67+
import { TraceEvent, useTrace } from "~/hooks/useTrace";
6868
import { useUser } from "~/hooks/useUser";
6969
import { RunPresenter } from "~/presenters/v3/RunPresenter.server";
7070
import { getResizableSnapshot } from "~/services/resizablePanel.server";
@@ -80,7 +80,6 @@ import {
8080
} from "~/utils/pathBuilder";
8181
import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route";
8282
import { SpanView } from "../resources.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam.spans.$spanParam/route";
83-
import { useOptimisticLocation } from "~/hooks/useOptimisticLocation";
8483

8584
const resizableSettings = {
8685
parent: {
@@ -146,29 +145,21 @@ function getSpanId(location: Location<any>): string | undefined {
146145

147146
export default function Page() {
148147
const { run, resizable } = useTypedLoaderData<typeof loader>();
149-
const appOrigin = useAppOrigin();
150-
const { isUpToDate, trace } = useTrace({
151-
origin: appOrigin,
152-
traceId: run.traceId,
153-
spanId: run.spanId,
154-
});
148+
155149
const user = useUser();
156150
const organization = useOrganization();
157151
const project = useProject();
158152

159153
const { location, replaceSearchParam } = useReplaceLocation();
160154
const selectedSpanId = getSpanId(location);
161155

162-
const usernameForEnv = user.id !== run.environment.userId ? run.environment.userName : undefined;
163-
164-
const initialLoad = !isUpToDate && !trace;
156+
const inspectorSpanId = selectedSpanId
157+
? selectedSpanId
158+
: run.logsDeletedAt
159+
? run.spanId
160+
: undefined;
165161

166-
let inspectorSpanId = selectedSpanId;
167-
if (!inspectorSpanId) {
168-
if (initialLoad || !trace) {
169-
inspectorSpanId = run.spanId;
170-
}
171-
}
162+
const usernameForEnv = user.id !== run.environment.userId ? run.environment.userName : undefined;
172163

173164
return (
174165
<>
@@ -262,20 +253,13 @@ export default function Page() {
262253
min={resizableSettings.parent.main.min}
263254
>
264255
<ClientOnly fallback={<Loading />}>
265-
{() =>
266-
initialLoad ? (
267-
<Loading />
268-
) : trace ? (
269-
<TraceView
270-
run={run}
271-
trace={trace}
272-
selectedSpanId={selectedSpanId}
273-
replaceSearchParam={replaceSearchParam}
274-
/>
275-
) : (
276-
<NoLogsView run={run} />
277-
)
278-
}
256+
{() => (
257+
<TraceView
258+
run={run}
259+
selectedSpanId={selectedSpanId}
260+
replaceSearchParam={replaceSearchParam}
261+
/>
262+
)}
279263
</ClientOnly>
280264
</ResizablePanel>
281265
<ResizableHandle id={resizableSettings.parent.handleId} />
@@ -289,7 +273,7 @@ export default function Page() {
289273
<SpanView
290274
runParam={run.friendlyId}
291275
spanId={inspectorSpanId}
292-
closePanel={trace ? () => replaceSearchParam("span") : undefined}
276+
closePanel={!run.logsDeletedAt ? () => replaceSearchParam("span") : undefined}
293277
/>
294278
</ResizablePanel>
295279
) : null}
@@ -300,20 +284,45 @@ export default function Page() {
300284
);
301285
}
302286

287+
function View({ resizable, run }: LoaderData) {}
288+
303289
type TraceData = {
304290
run: LoaderData["run"];
305-
trace: Trace;
306291
selectedSpanId: string | undefined;
307292
replaceSearchParam: (key: string, value?: string) => void;
308293
};
309294

310-
function TraceView({ run, trace, selectedSpanId, replaceSearchParam }: TraceData) {
311-
const { events, parentRunFriendlyId, duration, rootSpanStatus, rootStartedAt } = trace;
295+
function TraceView({ run, selectedSpanId, replaceSearchParam }: TraceData) {
296+
const appOrigin = useAppOrigin();
297+
const { isUpToDate, trace } = useTrace({
298+
origin: appOrigin,
299+
traceId: run.traceId,
300+
spanId: run.spanId,
301+
});
312302

313303
const changeToSpan = useDebounce((selectedSpan: string) => {
314304
replaceSearchParam("span", selectedSpan);
315305
}, 250);
316306

307+
if (!isUpToDate) {
308+
return <Loading />;
309+
}
310+
311+
if (!trace) {
312+
return <NoLogsView run={run} />;
313+
}
314+
315+
const initialLoad = !isUpToDate && !trace;
316+
317+
let inspectorSpanId = selectedSpanId;
318+
if (!inspectorSpanId) {
319+
if (initialLoad || !trace) {
320+
inspectorSpanId = run.spanId;
321+
}
322+
}
323+
324+
const { events, parentRunFriendlyId, duration, rootSpanStatus, rootStartedAt } = trace;
325+
317326
return (
318327
<TasksTreeView
319328
selectedId={selectedSpanId}
@@ -1206,7 +1215,7 @@ export function Loading() {
12061215
<div className="grid h-full grid-rows-[2.5rem_1fr_3.25rem] overflow-hidden">
12071216
<div className="mx-3 flex items-center gap-2 border-b border-grid-dimmed">
12081217
<Spinner className="size-4" />
1209-
<Paragraph variant="small" className="flex items-center gap-2">
1218+
<Paragraph variant="extra-small" className="flex items-center gap-2">
12101219
Loading logs
12111220
</Paragraph>
12121221
</div>

0 commit comments

Comments
 (0)