@@ -8,6 +8,9 @@ import { FixedSizeList as List, ListChildComponentProps } from 'react-window';
88
99import { styled } from '../../styles'
1010import { ArrowIcon , Icon , WarningIcon } from '../../icons' ;
11+
12+ import { ContextMenuItem , ClickEventType , BaseContextMenuItem , SubMenuItem , GetNewContextMenu } from './context-menu' ;
13+
1114import {
1215 CollectedEvent ,
1316 HttpExchange ,
@@ -33,22 +36,6 @@ import { StatusCode } from '../common/status-code';
3336
3437import { HEADER_FOOTER_HEIGHT } from './view-event-list-footer' ;
3538
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 ;
5239const SCROLL_BOTTOM_MARGIN = 5 ; // If you're in the last 5 pixels of the scroll area, we say you're at the bottom
5340
5441const EmptyStateOverlay = styled ( EmptyState ) `
@@ -372,6 +359,33 @@ const EventRow = observer((props: EventRowProps) => {
372359 }
373360} ) ;
374361
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+
375389const ExchangeRow = observer ( ( {
376390 index,
377391 isSelected,
@@ -396,7 +410,7 @@ const ExchangeRow = observer(({
396410 aria-rowindex = { index + 1 }
397411 data-event-id = { exchange . id }
398412 tabIndex = { isSelected ? 0 : - 1 }
399- onContextMenu = { e => displayMenu ( e , exchange ) }
413+ onContextMenu = { aMenu . GetContextMenuHandler ( { exchange : exchange } ) }
400414 className = { isSelected ? 'selected' : '' }
401415 style = { style }
402416 >
@@ -688,22 +702,7 @@ async function copyToClipboard(textToCopy: string) {
688702 console . error ( "Clipboard copy failure" , error ) ;
689703 }
690704}
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+
707706@observer
708707export class ViewEventList extends React . Component < ViewEventListProps > {
709708
@@ -790,14 +789,7 @@ export class ViewEventList extends React.Component<ViewEventListProps> {
790789 } </ Observer >
791790 } </ AutoSizer >
792791 }
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 }
801793 </ ListContainer > ;
802794 }
803795
0 commit comments