@@ -74,6 +74,73 @@ export function TracesContent(props: TracesProps) {
74
74
const [ includeMetrics , setIncludeMetrics ] = useState ( false ) ;
75
75
const isNavGroupEnabled = coreRefs ?. chrome ?. navGroup . getNavGroupEnabled ( ) ;
76
76
77
+ //ADAM TESITNG DELETE console.log
78
+ const defaultSortField = props . tracesTableMode === 'traces' ? 'last_updated' : 'endTime' ;
79
+ const [ sortingColumns , setSortingColumns ] = useState < { id : string ; direction : "desc" | "asc" } [ ] > ( [ { id : defaultSortField , direction : "desc" } ] ) ;
80
+ /** Sorting state */
81
+ //const [sortingColumns, setSortingColumns] = useState<{ id: string; direction: "desc" | "asc" }[]>([]);
82
+
83
+ const [ pageIndex , setPageIndex ] = useState ( 0 ) ;
84
+ const [ pageSize , setPageSize ] = useState ( 10 ) ;
85
+
86
+ const onSort = ( sortColumns : { id : string ; direction : "desc" | "asc" } [ ] ) => {
87
+ console . log ( "THE SORTING ADAM" , sortColumns ) ; //ADAM DELETE
88
+
89
+ if ( ! sortColumns || sortColumns . length === 0 ) {
90
+ setSortingColumns ( [ ] ) ;
91
+ refresh ( undefined , query , pageIndex , pageSize ) ;
92
+ return ;
93
+ }
94
+
95
+ const sortField = sortColumns [ 0 ] ?. id ;
96
+ const sortDirection = sortColumns [ 0 ] ?. direction ;
97
+
98
+ if ( ! sortField || ! sortDirection ) {
99
+ console . error ( "Invalid sorting column:" , sortColumns ) ;
100
+ return ;
101
+ }
102
+
103
+ setSortingColumns ( sortColumns ) ;
104
+ refresh (
105
+ { field : sortField , direction : sortDirection } ,
106
+ query ,
107
+ pageIndex ,
108
+ pageSize
109
+ ) ;
110
+ } ;
111
+
112
+ const [ totalHits , setTotalHits ] = useState ( 0 ) ;
113
+
114
+ const pagination = {
115
+ pageIndex,
116
+ pageSize,
117
+ pageSizeOptions : [ 5 , 10 , 15 ] ,
118
+ totalItemCount : totalHits ,
119
+ onChangePage : ( newPage ) => {
120
+ setPageIndex ( newPage ) ;
121
+ refresh (
122
+ sortingColumns . length > 0
123
+ ? { field : sortingColumns [ 0 ] . id , direction : sortingColumns [ 0 ] . direction }
124
+ : undefined ,
125
+ query ,
126
+ newPage ,
127
+ pageSize
128
+ ) ;
129
+ } ,
130
+ onChangeItemsPerPage : ( newSize ) => {
131
+ setPageSize ( newSize ) ;
132
+ setPageIndex ( 0 ) ;
133
+ refresh (
134
+ sortingColumns . length > 0
135
+ ? { field : sortingColumns [ 0 ] . id , direction : sortingColumns [ 0 ] . direction }
136
+ : undefined ,
137
+ query ,
138
+ 0 ,
139
+ newSize
140
+ ) ;
141
+ } ,
142
+ } ;
143
+
77
144
useEffect ( ( ) => {
78
145
chrome . setBreadcrumbs ( [
79
146
...( isNavGroupEnabled ? [ ] : [ props . parentBreadcrumb ] ) ,
@@ -141,7 +208,12 @@ export function TracesContent(props: TracesProps) {
141
208
setFilters ( newFilters ) ;
142
209
} ;
143
210
144
- const refresh = async ( sort ?: PropertySort , overrideQuery ?: string ) => {
211
+ const refresh = async (
212
+ sort ?: PropertySort ,
213
+ overrideQuery ?: string ,
214
+ newPageIndex : number = pageIndex ,
215
+ newPageSize : number = pageSize
216
+ ) => {
145
217
const filterQuery = overrideQuery ?? query ;
146
218
const DSL = filtersToDsl (
147
219
mode ,
@@ -164,6 +236,7 @@ export function TracesContent(props: TracesProps) {
164
236
165
237
setIsTraceTableLoading ( true ) ;
166
238
239
+ //console.log("THE SORTING ADAM",sort?.field, sort?.direction);//ADAM DELETE
167
240
if ( mode === 'custom_data_prepper' ) {
168
241
// Remove serviceName filter from service map query
169
242
const serviceMapDSL = cloneDeep ( DSL ) ;
@@ -174,28 +247,31 @@ export function TracesContent(props: TracesProps) {
174
247
const tracesRequest =
175
248
tracesTableMode !== 'traces'
176
249
? handleCustomIndicesTracesRequest (
177
- http ,
178
- DSL ,
179
- tableItems ,
180
- setTableItems ,
181
- setColumns ,
182
- mode ,
183
- props . dataSourceMDSId [ 0 ] . id ,
184
- sort ,
185
- tracesTableMode ,
186
- isUnderOneHour
187
- )
250
+ http ,
251
+ DSL ,
252
+ tableItems ,
253
+ setTableItems ,
254
+ setColumns ,
255
+ mode ,
256
+ newPageIndex ,
257
+ newPageSize ,
258
+ setTotalHits ,
259
+ props . dataSourceMDSId [ 0 ] ?. id ,
260
+ sort ,
261
+ tracesTableMode ,
262
+ isUnderOneHour
263
+ )
188
264
: handleTracesRequest (
189
- http ,
190
- DSL ,
191
- timeFilterDSL ,
192
- tableItems ,
193
- setTableItems ,
194
- mode ,
195
- props . dataSourceMDSId [ 0 ] . id ,
196
- sort ,
197
- isUnderOneHour
198
- ) ;
265
+ http ,
266
+ DSL ,
267
+ timeFilterDSL ,
268
+ tableItems ,
269
+ setTableItems ,
270
+ mode ,
271
+ props . dataSourceMDSId [ 0 ] . id ,
272
+ sort ,
273
+ isUnderOneHour
274
+ ) ;
199
275
200
276
tracesRequest . finally ( ( ) => setIsTraceTableLoading ( false ) ) ;
201
277
@@ -272,6 +348,7 @@ export function TracesContent(props: TracesProps) {
272
348
< TracesCustomIndicesTable
273
349
columnItems = { columns }
274
350
items = { tableItems }
351
+ totalHits = { totalHits }
275
352
refresh = { refresh }
276
353
mode = { mode }
277
354
loading = { isTraceTableLoading }
@@ -281,6 +358,9 @@ export function TracesContent(props: TracesProps) {
281
358
dataPrepperIndicesExist = { dataPrepperIndicesExist }
282
359
tracesTableMode = { tracesTableMode }
283
360
setTracesTableMode = { setTracesTableMode }
361
+ sorting = { sortingColumns }
362
+ pagination = { pagination }
363
+ onSort = { onSort }
284
364
/>
285
365
) : (
286
366
< TracesTable
0 commit comments