@@ -70,11 +70,9 @@ function LMP() {
70
70
( a , b ) => new Date ( b . created_at ) - new Date ( a . created_at )
71
71
) ;
72
72
setVersionHistory ( sortedVersionHistory ) ;
73
- if ( sortedVersionHistory . length > 1 ) {
74
- setPreviousVersion ( sortedVersionHistory [ 1 ] ) ;
75
- }
76
-
77
-
73
+ const currentVersionIndex = sortedVersionHistory . findIndex ( v => v . lmp_id === latest_lmp . lmp_id ) ;
74
+ const hasPreviousVersion = sortedVersionHistory . length > 1 && currentVersionIndex < sortedVersionHistory . length - 1 ;
75
+ setPreviousVersion ( hasPreviousVersion ? sortedVersionHistory [ currentVersionIndex + 1 ] : null ) ;
78
76
79
77
const invocationsResponse = await axios . get (
80
78
`${ API_BASE_URL } /api/invocations/${ name } ${ id ? `/${ id } ` : "" } `
@@ -133,6 +131,8 @@ function LMP() {
133
131
setViewMode ( prevMode => prevMode === 'Source' ? 'Diff' : 'Source' ) ;
134
132
} ;
135
133
134
+
135
+
136
136
if ( ! lmp )
137
137
return (
138
138
< div className = "flex items-center justify-center h-screen bg-gray-900 text-gray-100" >
@@ -185,12 +185,12 @@ function LMP() {
185
185
) }
186
186
</ div >
187
187
< div className = "flex space-x-4 items-center" >
188
- < ToggleSwitch
188
+ { previousVersion && < ToggleSwitch
189
189
leftLabel = "Source"
190
190
rightLabel = "Diff"
191
191
isRight = { viewMode === 'Diff' }
192
192
onToggle = { handleViewModeToggle }
193
- />
193
+ /> }
194
194
< button
195
195
className = "p-1 rounded bg-[#2a2f3a] hover:bg-[#3a3f4b] transition-colors"
196
196
onClick = { handleCopyCode }
@@ -205,7 +205,7 @@ function LMP() {
205
205
selectedInvocation = { selectedTrace }
206
206
showDependenciesInitial = { ! ! id }
207
207
previousVersion = { previousVersion }
208
- viewMode = { viewMode }
208
+ viewMode = { previousVersion ? viewMode : 'Source' }
209
209
/>
210
210
</ div >
211
211
</ div >
0 commit comments