()
| 18 | import type { SessionStatus } from '../api/types'; |
| 19 | |
| 20 | export function Sessions() { |
| 21 | const navigate = useNavigate(); |
| 22 | const [statusFilter, setStatusFilter] = useState<string>(''); |
| 23 | const [searchQuery, setSearchQuery] = useState(''); |
| 24 | |
| 25 | const { data, isLoading, refetch, isFetching } = useSessions({ |
| 26 | status: statusFilter || undefined, |
| 27 | limit: 50, |
| 28 | }); |
| 29 | |
| 30 | const filteredSessions = data?.sessions?.filter((session) => { |
| 31 | if (!searchQuery) return true; |
| 32 | return ( |
| 33 | session.id.toLowerCase().includes(searchQuery.toLowerCase()) || |
| 34 | session.agent_id?.toLowerCase().includes(searchQuery.toLowerCase()) || |
| 35 | session.agent_name?.toLowerCase().includes(searchQuery.toLowerCase()) |
| 36 | ); |
| 37 | }); |
| 38 | |
| 39 | return ( |
| 40 | <div className="flex flex-col h-full"> |
| 41 | <Header |
| 42 | title="Sessions" |
| 43 | subtitle="会话历史记录" |
| 44 | isRefreshing={isFetching} |
| 45 | onRefresh={() => refetch()} |
| 46 | /> |
| 47 | |
| 48 | <div className="flex-1 overflow-auto"> |
| 49 | {/* Filters */} |
| 50 | <div className="p-4 border-b border-[var(--color-border)] bg-[var(--color-surface)]"> |
| 51 | <div className="flex items-center gap-4"> |
| 52 | {/* Search */} |
| 53 | <div className="flex-1 relative"> |
| 54 | <Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--color-text-muted)]" /> |
| 55 | <input |
| 56 | type="text" |
| 57 | placeholder="搜索 Session ID、Agent..." |
| 58 | value={searchQuery} |
| 59 | onChange={(e) => setSearchQuery(e.target.value)} |
| 60 | className="w-full pl-10 pr-4 py-2 bg-[var(--color-background)] border border-[var(--color-border)] rounded-lg text-sm text-[var(--color-text-primary)] placeholder:text-[var(--color-text-muted)] focus:outline-none focus:border-[var(--color-primary)]" |
| 61 | /> |
| 62 | </div> |
| 63 | |
| 64 | {/* Status Filter */} |
| 65 | <div className="flex items-center gap-2"> |
| 66 | <Filter className="w-4 h-4 text-[var(--color-text-muted)]" /> |
| 67 | <select |
| 68 | value={statusFilter} |
| 69 | onChange={(e) => setStatusFilter(e.target.value)} |
| 70 | className="px-3 py-2 bg-[var(--color-background)] border border-[var(--color-border)] rounded-lg text-sm text-[var(--color-text-primary)] focus:outline-none focus:border-[var(--color-primary)]" |
| 71 | > |
| 72 | <option value="">全部状态</option> |
| 73 | <option value="active">活跃</option> |
| 74 | <option value="completed">已完成</option> |
| 75 | <option value="suspended">暂停</option> |
| 76 | </select> |
| 77 | </div> |
nothing calls this directly
no test coverage detected