Skip to content

Commit 0b71f8a

Browse files
committed
Updated dashboard to show latest runIds
1 parent 59622b6 commit 0b71f8a

2 files changed

Lines changed: 44 additions & 9 deletions

File tree

dashboard/src/components/StatesByRunId.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use client';
22

33
import React, { useState, useEffect, useMemo } from 'react';
4+
import { formatDistanceToNow } from 'date-fns';
45
import { apiService } from '@/services/api';
56
import {
67
CurrentStatesResponse,
78
StatesByRunIdResponse,
8-
StateListItem
9+
StateListItem,
10+
RunSummary
911
} from '@/types/state-manager';
1012
import { GraphVisualization } from './GraphVisualization';
1113
import {
@@ -25,7 +27,7 @@ interface StatesByRunIdProps {
2527
namespace: string;
2628
apiKey: string;
2729
}
28-
30+
// my new function
2931
export const StatesByRunId: React.FC<StatesByRunIdProps> = ({
3032
namespace,
3133
apiKey
@@ -43,6 +45,13 @@ export const StatesByRunId: React.FC<StatesByRunIdProps> = ({
4345
return m;
4446
}, [currentStates]);
4547

48+
const sortedRunIds = React.useMemo(() => {
49+
if (!currentStates?.run_ids) return [];
50+
return [...currentStates.run_ids].sort((a, b) =>
51+
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
52+
);
53+
}, [currentStates?.run_ids]);
54+
4655
const loadCurrentStates = async () => {
4756
setIsLoading(true);
4857
setError(null);
@@ -53,7 +62,7 @@ export const StatesByRunId: React.FC<StatesByRunIdProps> = ({
5362

5463
// Auto-select the first run ID if available
5564
if (data.run_ids.length > 0 && !selectedRunId) {
56-
setSelectedRunId(data.run_ids[0]);
65+
setSelectedRunId(data.run_ids[0].run_id);
5766
}
5867
} catch (err) {
5968
setError(err instanceof Error ? err.message : 'Failed to load current states');
@@ -177,6 +186,28 @@ export const StatesByRunId: React.FC<StatesByRunIdProps> = ({
177186
</button>
178187
</div>
179188
</div>
189+
{/* my react component for latest run id's */}
190+
<div className="mt-4">
191+
<h3 className="text-lg font-semibold mb-2">Latest Run ID</h3>
192+
<div className="max-h-60 overflow-y-auto border rounded-lg p-2">
193+
{sortedRunIds.length > 0 ? (
194+
<ul className="divide-y divide-gray-200">
195+
{sortedRunIds.map((run) => (
196+
<li key={run.run_id} className="py-2">
197+
<div className="flex justify-between items-center">
198+
<span className="font-mono text-sm">{run.run_id}</span>
199+
<span className="text-xs text-gray-500">
200+
{formatDistanceToNow(new Date(run.created_at), { addSuffix: true })}
201+
</span>
202+
</div>
203+
</li>
204+
))}
205+
</ul>
206+
) : (
207+
<p className="text-sm text-gray-500">No run IDs found</p>
208+
)}
209+
</div>
210+
</div>
180211

181212
{/* Run ID Selector */}
182213
{currentStates && currentStates.run_ids.length > 0 && (
@@ -189,19 +220,19 @@ export const StatesByRunId: React.FC<StatesByRunIdProps> = ({
189220
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
190221
{currentStates.run_ids.map((runId) => (
191222
<button
192-
key={runId}
193-
onClick={() => setSelectedRunId(runId)}
223+
key={runId.run_id}
224+
onClick={() => setSelectedRunId(runId.run_id)}
194225
className={`p-4 rounded-lg border-2 transition-colors ${
195-
selectedRunId === runId
226+
selectedRunId === runId.run_id
196227
? 'border-[#031035] bg-[#031035]/5'
197228
: 'border-gray-200 hover:border-gray-300'
198229
}`}
199230
>
200231
<div className="text-sm font-medium text-gray-900 truncate">
201-
{runId}
232+
{runId.run_id}
202233
</div>
203234
<div className="text-xs text-gray-500 mt-1">
204-
{countsByRunId.get(runId) ?? 0} states
235+
{countsByRunId.get(runId.run_id) ?? 0} states
205236
</div>
206237
</button>
207238
))}

dashboard/src/types/state-manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,15 @@ export interface StatesByRunIdResponse {
146146
states: StateListItem[];
147147
}
148148

149+
export interface RunSummary {
150+
run_id: string;
151+
created_at: string;
152+
}
149153
export interface CurrentStatesResponse {
150154
namespace: string;
151155
count: number;
152156
states: StateListItem[];
153-
run_ids: string[];
157+
run_ids: RunSummary[];
154158
}
155159

156160
export interface WorkflowStep {

0 commit comments

Comments
 (0)