9
9
StopCircleIcon ,
10
10
} from "@heroicons/react/20/solid" ;
11
11
import type { Location } from "@remix-run/react" ;
12
- import { useLocation , useParams } from "@remix-run/react" ;
12
+ import { useParams } from "@remix-run/react" ;
13
13
import { LoaderFunctionArgs } from "@remix-run/server-runtime" ;
14
14
import { Virtualizer } from "@tanstack/react-virtual" ;
15
15
import {
@@ -64,7 +64,7 @@ import { useOrganization } from "~/hooks/useOrganizations";
64
64
import { useProject } from "~/hooks/useProject" ;
65
65
import { useReplaceLocation } from "~/hooks/useReplaceLocation" ;
66
66
import { Shortcut , useShortcutKeys } from "~/hooks/useShortcutKeys" ;
67
- import { Trace , TraceEvent , useTrace } from "~/hooks/useTrace" ;
67
+ import { TraceEvent , useTrace } from "~/hooks/useTrace" ;
68
68
import { useUser } from "~/hooks/useUser" ;
69
69
import { RunPresenter } from "~/presenters/v3/RunPresenter.server" ;
70
70
import { getResizableSnapshot } from "~/services/resizablePanel.server" ;
@@ -80,7 +80,6 @@ import {
80
80
} from "~/utils/pathBuilder" ;
81
81
import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route" ;
82
82
import { SpanView } from "../resources.orgs.$organizationSlug.projects.v3.$projectParam.runs.$runParam.spans.$spanParam/route" ;
83
- import { useOptimisticLocation } from "~/hooks/useOptimisticLocation" ;
84
83
85
84
const resizableSettings = {
86
85
parent : {
@@ -146,29 +145,21 @@ function getSpanId(location: Location<any>): string | undefined {
146
145
147
146
export default function Page ( ) {
148
147
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
+
155
149
const user = useUser ( ) ;
156
150
const organization = useOrganization ( ) ;
157
151
const project = useProject ( ) ;
158
152
159
153
const { location, replaceSearchParam } = useReplaceLocation ( ) ;
160
154
const selectedSpanId = getSpanId ( location ) ;
161
155
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 ;
165
161
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 ;
172
163
173
164
return (
174
165
< >
@@ -262,20 +253,13 @@ export default function Page() {
262
253
min = { resizableSettings . parent . main . min }
263
254
>
264
255
< 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
+ ) }
279
263
</ ClientOnly >
280
264
</ ResizablePanel >
281
265
< ResizableHandle id = { resizableSettings . parent . handleId } />
@@ -289,7 +273,7 @@ export default function Page() {
289
273
< SpanView
290
274
runParam = { run . friendlyId }
291
275
spanId = { inspectorSpanId }
292
- closePanel = { trace ? ( ) => replaceSearchParam ( "span" ) : undefined }
276
+ closePanel = { ! run . logsDeletedAt ? ( ) => replaceSearchParam ( "span" ) : undefined }
293
277
/>
294
278
</ ResizablePanel >
295
279
) : null }
@@ -300,20 +284,45 @@ export default function Page() {
300
284
) ;
301
285
}
302
286
287
+ function View ( { resizable, run } : LoaderData ) { }
288
+
303
289
type TraceData = {
304
290
run : LoaderData [ "run" ] ;
305
- trace : Trace ;
306
291
selectedSpanId : string | undefined ;
307
292
replaceSearchParam : ( key : string , value ?: string ) => void ;
308
293
} ;
309
294
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
+ } ) ;
312
302
313
303
const changeToSpan = useDebounce ( ( selectedSpan : string ) => {
314
304
replaceSearchParam ( "span" , selectedSpan ) ;
315
305
} , 250 ) ;
316
306
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
+
317
326
return (
318
327
< TasksTreeView
319
328
selectedId = { selectedSpanId }
@@ -1206,7 +1215,7 @@ export function Loading() {
1206
1215
< div className = "grid h-full grid-rows-[2.5rem_1fr_3.25rem] overflow-hidden" >
1207
1216
< div className = "mx-3 flex items-center gap-2 border-b border-grid-dimmed" >
1208
1217
< 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" >
1210
1219
Loading logs
1211
1220
</ Paragraph >
1212
1221
</ div >
0 commit comments