1+ import * as _ from 'lodash' ;
12import * as React from 'react' ;
23import { observer } from 'mobx-react-lite' ;
34
45import { css , styled } from '../../styles' ;
56
6- import { SendRequest } from '../../model/send/send-request-model' ;
7+ import { RequestInput , SendRequest } from '../../model/send/send-request-model' ;
78import { getMethodColor } from '../../model/events/categorization' ;
9+ import { ContextMenuItem } from '../../model/ui/context-menu' ;
810
911import { UnstyledButton } from '../common/inputs' ;
1012import { IconButton } from '../common/icon-button' ;
@@ -114,7 +116,8 @@ const SendTab = observer((props: {
114116 sendRequest : SendRequest ,
115117 isSelectedTab : boolean ,
116118 onSelectTab : ( request : SendRequest ) => void ,
117- onCloseTab : ( request : SendRequest ) => void
119+ onCloseTab : ( request : SendRequest ) => void ,
120+ onContextMenu : ( event : React . MouseEvent , request : SendRequest ) => void
118121} ) => {
119122 const { request } = props . sendRequest ;
120123
@@ -133,10 +136,15 @@ const SendTab = observer((props: {
133136 event . stopPropagation ( ) ;
134137 } , [ props . onCloseTab , props . sendRequest ] ) ;
135138
139+ const onContextMenu = React . useCallback ( ( event : React . MouseEvent ) => {
140+ props . onContextMenu ( event , props . sendRequest ) ;
141+ } , [ props . onContextMenu , props . sendRequest ] ) ;
142+
136143 return < TabContainer
137144 selected = { props . isSelectedTab }
138145 onClick = { onTabClick }
139146 onAuxClick = { onTaxAuxClick }
147+ onContextMenu = { onContextMenu }
140148 >
141149 < TabButton
142150 selected = { props . isSelectedTab }
@@ -168,7 +176,8 @@ export const SendTabs = observer((props: {
168176 onSelectTab : ( sendRequest : SendRequest ) => void ;
169177 onMoveSelection : ( distance : number ) => void ;
170178 onCloseTab : ( sendRequest : SendRequest ) => void ;
171- onAddTab : ( ) => void ;
179+ onAddTab : ( requestInput ?: RequestInput ) => void ;
180+ onContextMenu : ( event : React . MouseEvent , items : readonly ContextMenuItem < void > [ ] ) => void ;
172181} ) => {
173182 const containerRef = React . useRef < HTMLDivElement > ( null ) ;
174183
@@ -205,6 +214,32 @@ export const SendTabs = observer((props: {
205214 event . stopPropagation ( ) ;
206215 } , [ ] ) ;
207216
217+ const onContextMenu = React . useCallback ( ( event : React . MouseEvent , request : SendRequest ) => {
218+ event . preventDefault ( ) ;
219+ props . onContextMenu ( event , [
220+ {
221+ type : 'option' ,
222+ label : 'Duplicate Tab' ,
223+ callback : ( ) => props . onAddTab ( _ . cloneDeep ( request . request ) )
224+ } ,
225+ {
226+ type : 'option' ,
227+ label : 'Close Tab' ,
228+ callback : ( ) => props . onCloseTab ( request )
229+ } ,
230+ {
231+ type : 'option' ,
232+ label : 'Close Other Tabs' ,
233+ callback : ( ) => {
234+ const tabs = [ ...props . sendRequests ] ;
235+ for ( let tab of tabs ) {
236+ if ( tab !== request ) props . onCloseTab ( tab ) ;
237+ }
238+ }
239+ }
240+ ] ) ;
241+ } , [ props . onAddTab , props . onCloseTab , props . sendRequests ] ) ;
242+
208243 return < TabsContainer
209244 ref = { containerRef }
210245 onKeyDown = { onKeyDown }
@@ -218,6 +253,7 @@ export const SendTabs = observer((props: {
218253 isSelectedTab = { isSelectedTab }
219254 onSelectTab = { props . onSelectTab }
220255 onCloseTab = { props . onCloseTab }
256+ onContextMenu = { onContextMenu }
221257 />
222258 } )
223259 }
0 commit comments