@@ -8,6 +8,9 @@ import { FixedSizeList as List, ListChildComponentProps } from 'react-window';
8
8
9
9
import { styled } from '../../styles'
10
10
import { ArrowIcon , Icon , WarningIcon } from '../../icons' ;
11
+
12
+ import { ContextMenuItem , ClickEventType , BaseContextMenuItem , SubMenuItem , GetNewContextMenu } from './context-menu' ;
13
+
11
14
import {
12
15
CollectedEvent ,
13
16
HttpExchange ,
@@ -33,22 +36,6 @@ import { StatusCode } from '../common/status-code';
33
36
34
37
import { HEADER_FOOTER_HEIGHT } from './view-event-list-footer' ;
35
38
36
- import {
37
- Menu ,
38
- Item ,
39
- Separator ,
40
- Submenu ,
41
- useContextMenu ,
42
- ItemProps ,
43
- ItemParams ,
44
- } from "react-contexify" ;
45
- const MENU_VIEW_EVENT_ID = "MENU_VIEW_EVENT_LIST" ;
46
-
47
-
48
- const { show } = useContextMenu ( {
49
- id : MENU_VIEW_EVENT_ID
50
- } ) ;
51
- type ItemData = any ;
52
39
const SCROLL_BOTTOM_MARGIN = 5 ; // If you're in the last 5 pixels of the scroll area, we say you're at the bottom
53
40
54
41
const EmptyStateOverlay = styled ( EmptyState ) `
@@ -372,6 +359,33 @@ const EventRow = observer((props: EventRowProps) => {
372
359
}
373
360
} ) ;
374
361
362
+ interface ExchangeOnClickFunc {
363
+ ( e : ClickEventType , props : object , exchange : HttpExchange ) : void ;
364
+ }
365
+ function getExchangeOnClick ( func : ExchangeOnClickFunc ) {
366
+ return ( e : ClickEventType , props : object ) => func ( e , props , ( props as any ) . exchange as HttpExchange ) ;
367
+
368
+ }
369
+ let aMenu = GetNewContextMenu ( ) ;
370
+ let cntr = 0 ;
371
+ let arr : BaseContextMenuItem [ ] = [
372
+ new ContextMenuItem ( { title : "Toggle Pin" , disabled : ( ) => ( cntr ++ % 2 ) == 0 , onClick : getExchangeOnClick ( ( e , props , exchange ) => runInAction ( ( ) => exchange . pinned = ! exchange . pinned ) ) } ) ,
373
+ new SubMenuItem ( {
374
+ title : "Copy" ,
375
+ sub_items : [ new ContextMenuItem (
376
+ {
377
+ title : "Decoded Body" , onClick : getExchangeOnClick ( ( e , props , exchange ) => {
378
+ if ( exchange && exchange . hasResponseBody ( ) && exchange . response . body )
379
+ exchange . response . body . decodedPromise . then ( val => { copyToClipboard ( UTF8Decoder . decode ( val ) ) } ) ;
380
+ }
381
+ )
382
+
383
+ } ) ]
384
+ } )
385
+
386
+ ] ;
387
+ let addItem = aMenu . CreateContextMenu ( arr ) ;
388
+
375
389
const ExchangeRow = observer ( ( {
376
390
index,
377
391
isSelected,
@@ -396,7 +410,7 @@ const ExchangeRow = observer(({
396
410
aria-rowindex = { index + 1 }
397
411
data-event-id = { exchange . id }
398
412
tabIndex = { isSelected ? 0 : - 1 }
399
- onContextMenu = { e => displayMenu ( e , exchange ) }
413
+ onContextMenu = { aMenu . GetContextMenuHandler ( { exchange : exchange } ) }
400
414
className = { isSelected ? 'selected' : '' }
401
415
style = { style }
402
416
>
@@ -688,22 +702,7 @@ async function copyToClipboard(textToCopy: string) {
688
702
console . error ( "Clipboard copy failure" , error ) ;
689
703
}
690
704
}
691
- const ContextMenuItemClicked = ( { id, event, props, data, triggerEvent } : ItemParams < ItemProps , ItemData > ) => {
692
- let exchange = ( props as any ) . exchange as HttpExchange ;
693
- switch ( id ) {
694
- case "TogglePin" :
695
- runInAction ( ( ) => exchange . pinned = ! exchange . pinned ) ;
696
- break ;
697
- case "DecodedBody" :
698
- if ( exchange && exchange . hasResponseBody ( ) && exchange . response . body )
699
- exchange . response . body . decodedPromise . then ( val => { copyToClipboard ( UTF8Decoder . decode ( val ) ) } ) ;
700
- break ;
701
- }
702
-
703
- } ;
704
- function displayMenu ( e : React . MouseEvent , exchange : HttpExchange ) {
705
- show ( { event : e , props : { exchange : exchange } } ) ;
706
- }
705
+
707
706
@observer
708
707
export class ViewEventList extends React . Component < ViewEventListProps > {
709
708
@@ -790,14 +789,7 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
790
789
} </ Observer >
791
790
} </ AutoSizer >
792
791
}
793
-
794
- < Menu id = { MENU_VIEW_EVENT_ID } >
795
- < Item id = "TogglePin" onClick = { ContextMenuItemClicked } > Toggle Pinned</ Item >
796
- < Separator />
797
- < Submenu label = "Copy" >
798
- < Item id = "DecodedBody" onClick = { ContextMenuItemClicked } > Decoded Body</ Item >
799
- </ Submenu >
800
- </ Menu >
792
+ { aMenu . menu }
801
793
</ ListContainer > ;
802
794
}
803
795
0 commit comments