@@ -21,10 +21,11 @@ import { HttpSetup } from '../../../../../../../src/core/public';
21
21
import { TraceAnalyticsMode } from '../../../../../common/types/trace_analytics' ;
22
22
import { coreRefs } from '../../../../framework/core_refs' ;
23
23
import { Plt } from '../../../visualizations/plotly/plot' ;
24
+ import { hitsToSpanDetailData } from '../../requests/traces_request_handler' ;
25
+ import { TraceFilter } from '../common/constants' ;
24
26
import { PanelTitle , parseHits } from '../common/helper_functions' ;
25
27
import { SpanDetailFlyout } from './span_detail_flyout' ;
26
28
import { SpanDetailTable , SpanDetailTableHierarchy } from './span_detail_table' ;
27
- import { hitsToSpanDetailData } from '../../requests/traces_request_handler' ;
28
29
29
30
export function SpanDetailPanel ( props : {
30
31
http : HttpSetup ;
@@ -33,6 +34,8 @@ export function SpanDetailPanel(props: {
33
34
mode : TraceAnalyticsMode ;
34
35
dataSourceMDSId : string ;
35
36
dataSourceMDSLabel : string | undefined ;
37
+ spanFilters : TraceFilter [ ] ;
38
+ setSpanFiltersWithStorage : ( newFilters : TraceFilter [ ] ) => void ;
36
39
page ?: string ;
37
40
openSpanFlyout ?: any ;
38
41
data ?: { gantt : any [ ] ; table : any [ ] ; ganttMaxX : number } ;
@@ -44,11 +47,8 @@ export function SpanDetailPanel(props: {
44
47
} ) {
45
48
const { chrome } = coreRefs ;
46
49
const { mode } = props ;
47
- const storedFilters = sessionStorage . getItem ( 'TraceAnalyticsSpanFilters' ) ;
48
50
const fromApp = props . page === 'app' ;
49
- const [ spanFilters , setSpanFilters ] = useState < Array < { field : string ; value : any } > > (
50
- storedFilters ? JSON . parse ( storedFilters ) : [ ]
51
- ) ;
51
+
52
52
let data : { gantt : any [ ] ; table : any [ ] ; ganttMaxX : number } ;
53
53
let setData : ( data : { gantt : any [ ] ; table : any [ ] ; ganttMaxX : number } ) => void ;
54
54
const [ localData , localSetData ] = useState < { gantt : any [ ] ; table : any [ ] ; ganttMaxX : number } > ( {
@@ -109,70 +109,34 @@ export function SpanDetailPanel(props: {
109
109
setSelectedRange ( fullRange ) ;
110
110
} , [ data . ganttMaxX ] ) ;
111
111
112
- const setSpanFiltersWithStorage = ( newFilters : Array < { field : string ; value : any } > ) => {
113
- setSpanFilters ( newFilters ) ;
114
- sessionStorage . setItem ( 'TraceAnalyticsSpanFilters' , JSON . stringify ( newFilters ) ) ;
115
- } ;
116
-
117
112
const addSpanFilter = ( field : string , value : any ) => {
118
- const newFilters = [ ...spanFilters ] ;
113
+ const newFilters = [ ...props . spanFilters ] ;
119
114
const index = newFilters . findIndex ( ( { field : filterField } ) => field === filterField ) ;
120
115
if ( index === - 1 ) {
121
116
newFilters . push ( { field, value } ) ;
122
117
} else {
123
118
newFilters . splice ( index , 1 , { field, value } ) ;
124
119
}
125
- setSpanFiltersWithStorage ( newFilters ) ;
120
+ props . setSpanFiltersWithStorage ( newFilters ) ;
126
121
} ;
127
122
128
123
const removeSpanFilter = ( field : string ) => {
129
- const newFilters = [ ...spanFilters ] ;
124
+ const newFilters = [ ...props . spanFilters ] ;
130
125
const index = newFilters . findIndex ( ( { field : filterField } ) => field === filterField ) ;
131
126
if ( index !== - 1 ) {
132
127
newFilters . splice ( index , 1 ) ;
133
- setSpanFiltersWithStorage ( newFilters ) ;
134
- }
135
- } ;
136
-
137
- const parseAndFilterHits = (
138
- payloadData : string ,
139
- traceMode : string ,
140
- payloadSpanFilters : any [ ]
141
- ) => {
142
- try {
143
- let hits = parseHits ( props . payloadData ) ;
144
-
145
- if ( payloadSpanFilters . length > 0 ) {
146
- hits = hits . filter ( ( hit ) => {
147
- return payloadSpanFilters . every ( ( { field, value } ) => {
148
- const fieldValue = field . split ( '.' ) . reduce ( ( acc , part ) => acc ?. [ part ] , hit . _source ) ;
149
- return fieldValue === value ;
150
- } ) ;
151
- } ) ;
152
- }
153
-
154
- hits = hits . filter ( ( hit ) => {
155
- if ( traceMode === 'jaeger' ) {
156
- return Boolean ( hit . _source ?. process ?. serviceName ) ;
157
- } else {
158
- return Boolean ( hit . _source ?. serviceName ) ;
159
- }
160
- } ) ;
161
-
162
- return hits ;
163
- } catch ( error ) {
164
- console . error ( 'Error processing payloadData in parseAndFilterHits:' , error ) ;
165
- return [ ] ;
128
+ props . setSpanFiltersWithStorage ( newFilters ) ;
166
129
}
167
130
} ;
168
131
169
132
useEffect ( ( ) => {
170
133
if ( ! props . payloadData ) {
171
- console . warn ( 'No payloadData provided to SpanDetailPanel' ) ;
134
+ props . setGanttChartLoading ?.( false ) ;
135
+ console . error ( 'No payloadData provided to SpanDetailPanel' ) ;
172
136
return ;
173
137
}
174
138
175
- const hits = parseAndFilterHits ( props . payloadData , mode , spanFilters ) ;
139
+ const hits = parseHits ( props . payloadData ) ;
176
140
177
141
if ( hits . length === 0 ) {
178
142
return ;
@@ -186,11 +150,9 @@ export function SpanDetailPanel(props: {
186
150
console . error ( 'Error in hitsToSpanDetailData:' , error ) ;
187
151
} )
188
152
. finally ( ( ) => {
189
- if ( props . setGanttChartLoading ) {
190
- props . setGanttChartLoading ( false ) ;
191
- }
153
+ props . setGanttChartLoading ?.( false ) ;
192
154
} ) ;
193
- } , [ props . payloadData , props . colorMap , mode , spanFilters ] ) ;
155
+ } , [ props . payloadData , props . colorMap , mode , props . spanFilters ] ) ;
194
156
195
157
const getSpanDetailLayout = (
196
158
plotTraces : Plotly . Data [ ] ,
@@ -317,7 +279,7 @@ export function SpanDetailPanel(props: {
317
279
) ;
318
280
319
281
const renderFilters = useMemo ( ( ) => {
320
- return spanFilters . map ( ( { field, value } ) => (
282
+ return props . spanFilters . map ( ( { field, value } ) => (
321
283
< EuiFlexItem grow = { false } key = { `span-filter-badge-${ field } ` } >
322
284
< EuiBadge
323
285
iconType = "cross"
@@ -329,7 +291,7 @@ export function SpanDetailPanel(props: {
329
291
</ EuiBadge >
330
292
</ EuiFlexItem >
331
293
) ) ;
332
- } , [ spanFilters ] ) ;
294
+ } , [ props . spanFilters ] ) ;
333
295
334
296
const onHover = useCallback ( ( ) => {
335
297
const dragLayer = document . getElementsByClassName ( 'nsewdrag' ) ?. [ 0 ] ;
@@ -387,11 +349,11 @@ export function SpanDetailPanel(props: {
387
349
dataSourceMDSId = { props . dataSourceMDSId }
388
350
availableWidth = { dynamicLayoutAdjustment }
389
351
payloadData = { props . payloadData }
390
- filters = { spanFilters }
352
+ filters = { props . spanFilters }
391
353
/>
392
354
</ div >
393
355
) ,
394
- [ setCurrentSpan , dynamicLayoutAdjustment , props . payloadData , spanFilters ]
356
+ [ setCurrentSpan , dynamicLayoutAdjustment , props . payloadData , props . spanFilters ]
395
357
) ;
396
358
397
359
const spanDetailTableHierarchy = useMemo (
@@ -411,11 +373,11 @@ export function SpanDetailPanel(props: {
411
373
dataSourceMDSId = { props . dataSourceMDSId }
412
374
availableWidth = { dynamicLayoutAdjustment }
413
375
payloadData = { props . payloadData }
414
- filters = { spanFilters }
376
+ filters = { props . spanFilters }
415
377
/>
416
378
</ div >
417
379
) ,
418
- [ setCurrentSpan , dynamicLayoutAdjustment , props . payloadData , spanFilters ]
380
+ [ setCurrentSpan , dynamicLayoutAdjustment , props . payloadData , props . spanFilters ]
419
381
) ;
420
382
421
383
const ganttChart = useMemo (
@@ -491,7 +453,7 @@ export function SpanDetailPanel(props: {
491
453
</ div >
492
454
) : (
493
455
< >
494
- { spanFilters . length > 0 && (
456
+ { props . spanFilters . length > 0 && (
495
457
< EuiFlexItem grow = { false } >
496
458
< EuiSpacer size = "s" />
497
459
< EuiFlexGroup gutterSize = "s" wrap >
0 commit comments