Skip to content

Commit 38eaee4

Browse files
committed
feat(sessions): enable sorting on sessions table (#5292)
1 parent e7da96e commit 38eaee4

File tree

9 files changed

+444
-62
lines changed

9 files changed

+444
-62
lines changed

app/schema.graphql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ type Project implements Node {
12801280
spanLatencyMsQuantile(probability: Float!, timeRange: TimeRange, filterCondition: String): Float
12811281
trace(traceId: ID!): Trace
12821282
spans(timeRange: TimeRange, first: Int = 50, last: Int, after: String, before: String, sort: SpanSort, rootSpansOnly: Boolean, filterCondition: String): SpanConnection!
1283-
sessions(timeRange: TimeRange, first: Int = 50, after: String, filterIoSubstring: String): ProjectSessionConnection!
1283+
sessions(timeRange: TimeRange, first: Int = 50, after: String, sort: ProjectSessionSort, filterIoSubstring: String): ProjectSessionConnection!
12841284

12851285
"""
12861286
Names of all available annotations for traces. (The list contains no duplicates.)
@@ -1339,6 +1339,13 @@ type ProjectSession implements Node {
13391339
traceLatencyMsQuantile(probability: Float!): Float
13401340
}
13411341

1342+
enum ProjectSessionColumn {
1343+
startTime
1344+
endTime
1345+
tokenCountTotal
1346+
numTraces
1347+
}
1348+
13421349
"""A connection to a list of items."""
13431350
type ProjectSessionConnection {
13441351
"""Pagination data for this connection"""
@@ -1357,6 +1364,12 @@ type ProjectSessionEdge {
13571364
node: ProjectSession!
13581365
}
13591366

1367+
"""The sort key and direction for ProjectSession connections."""
1368+
input ProjectSessionSort {
1369+
col: ProjectSessionColumn!
1370+
dir: SortDir!
1371+
}
1372+
13601373
type PromptResponse {
13611374
"""The prompt submitted to the LLM"""
13621375
prompt: String

app/src/pages/project/SessionsTable.tsx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import { IntCell, TextCell } from "../../components/table";
3131
import { TokenCount } from "../../components/trace/TokenCount";
3232

3333
import { SessionsTable_sessions$key } from "./__generated__/SessionsTable_sessions.graphql";
34-
import { SessionsTableQuery } from "./__generated__/SessionsTableQuery.graphql";
34+
import {
35+
ProjectSessionColumn,
36+
SessionsTableQuery,
37+
} from "./__generated__/SessionsTableQuery.graphql";
3538
import { useSessionSearchContext } from "./SessionSearchContext";
3639
import { SessionSearchField } from "./SessionSearchField";
3740
import { SessionsTableEmpty } from "./SessionsTableEmpty";
@@ -58,12 +61,17 @@ export function SessionsTable(props: SessionsTableProps) {
5861
@argumentDefinitions(
5962
after: { type: "String", defaultValue: null }
6063
first: { type: "Int", defaultValue: 50 }
64+
sort: {
65+
type: "ProjectSessionSort"
66+
defaultValue: { col: startTime, dir: desc }
67+
}
6168
filterIoSubstring: { type: "String", defaultValue: null }
6269
) {
6370
name
6471
sessions(
6572
first: $first
6673
after: $after
74+
sort: $sort
6775
filterIoSubstring: $filterIoSubstring
6876
timeRange: $timeRange
6977
) @connection(key: "SessionsTable_sessions") {
@@ -93,8 +101,11 @@ export function SessionsTable(props: SessionsTableProps) {
93101
props.project
94102
);
95103
const tableData = useMemo(() => {
96-
return data.sessions.edges.map(({ session }) => session);
97-
}, [data]);
104+
return data.sessions.edges.map(({ session }) => ({
105+
...session,
106+
tokenCountTotal: session.tokenUsage.total,
107+
}));
108+
}, [data.sessions]);
98109
type TableRow = (typeof tableData)[number];
99110
const columns: ColumnDef<TableRow>[] = [
100111
{
@@ -118,19 +129,19 @@ export function SessionsTable(props: SessionsTableProps) {
118129
{
119130
header: "start time",
120131
accessorKey: "startTime",
121-
enableSorting: false,
132+
enableSorting: true,
122133
cell: TimestampCell,
123134
},
124135
{
125136
header: "end time",
126137
accessorKey: "endTime",
127-
enableSorting: false,
138+
enableSorting: true,
128139
cell: TimestampCell,
129140
},
130141
{
131142
header: "total tokens",
132-
accessorKey: "tokenUsage.total",
133-
enableSorting: false,
143+
accessorKey: "tokenCountTotal",
144+
enableSorting: true,
134145
minSize: 80,
135146
cell: ({ row, getValue }) => {
136147
const value = getValue();
@@ -150,14 +161,21 @@ export function SessionsTable(props: SessionsTableProps) {
150161
{
151162
header: "total traces",
152163
accessorKey: "numTraces",
153-
enableSorting: false,
164+
enableSorting: true,
154165
cell: IntCell,
155166
},
156167
];
157168
useEffect(() => {
169+
const sort = sorting[0];
158170
startTransition(() => {
159171
refetch(
160172
{
173+
sort: sort
174+
? {
175+
col: sort.id as ProjectSessionColumn,
176+
dir: sort.desc ? "desc" : "asc",
177+
}
178+
: { col: "startTime", dir: "desc" },
161179
after: null,
162180
first: PAGE_SIZE,
163181
filterIoSubstring: filterIoSubstring,

app/src/pages/project/__generated__/ProjectPageSessionsQuery.graphql.ts

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)