1
- import React from " react" ;
1
+ import React from ' react' ;
2
2
import {
3
3
Dropdown ,
4
4
DropdownItem ,
5
5
DropdownList ,
6
6
MenuToggle ,
7
7
MenuToggleElement ,
8
- } from "@patternfly/react-core" ;
9
- import { Workspace , WorkspaceState } from "~/shared/types" ;
8
+ MenuToggleAction ,
9
+ } from '@patternfly/react-core' ;
10
+ import { Workspace , WorkspaceState } from '~/shared/types' ;
10
11
11
12
type EndpointsDropdownProps = {
12
13
workspace : Workspace ;
13
14
} ;
14
15
15
- export const EndpointsDropdown : React . FunctionComponent < EndpointsDropdownProps > = ( { workspace} ) => {
16
- const [ isOpen , setIsOpen ] = React . useState ( false ) ;
16
+ export const EndpointsDropdown : React . FunctionComponent < EndpointsDropdownProps > = ( {
17
+ workspace,
18
+ } ) => {
19
+ const [ open , setIsOpen ] = React . useState ( false ) ;
17
20
18
21
const onToggleClick = ( ) => {
19
- setIsOpen ( ! isOpen ) ;
22
+ setIsOpen ( ! open ) ;
20
23
} ;
21
24
22
25
const onSelect = (
23
26
_event : React . MouseEvent < Element , MouseEvent > | undefined ,
24
- value : string | number | undefined ) => {
27
+ value : string | number | undefined ,
28
+ ) => {
25
29
setIsOpen ( false ) ;
26
- if ( typeof value === 'string' ) {
30
+ if ( typeof value === 'string' ) {
27
31
openEndpoint ( value ) ;
28
32
}
29
33
} ;
30
34
35
+ const onClickConnect = ( ) => {
36
+ openEndpoint ( workspace . podTemplate . endpoints [ 0 ] . port ) ;
37
+ } ;
38
+
31
39
const openEndpoint = ( port : string ) => {
32
- window . open ( `workspace/${ workspace . namespace } /${ workspace . name } /${ port } ` , '_blank' ) ;
40
+ window . open ( `workspace/${ workspace . namespace } /${ workspace . name } /${ port } ` , '_blank' ) ;
33
41
} ;
34
42
35
43
return (
36
44
< Dropdown
37
- isOpen = { isOpen }
45
+ isOpen = { open }
38
46
onSelect = { onSelect }
39
47
onOpenChange = { ( isOpen : boolean ) => setIsOpen ( isOpen ) }
40
48
toggle = { ( toggleRef : React . Ref < MenuToggleElement > ) => (
41
49
< MenuToggle
42
50
ref = { toggleRef }
43
51
onClick = { onToggleClick }
44
- isExpanded = { isOpen }
45
- isFullWidth = { true }
46
- isDisabled = { workspace . status . state != WorkspaceState . Running }
47
- > Connect
48
- </ MenuToggle >
52
+ isExpanded = { open }
53
+ isFullWidth
54
+ isDisabled = { workspace . status . state !== WorkspaceState . Running }
55
+ splitButtonItems = { [
56
+ < MenuToggleAction
57
+ id = "connect-endpoint-button"
58
+ key = "connect-endpoint-button"
59
+ onClick = { onClickConnect }
60
+ >
61
+ Connect
62
+ </ MenuToggleAction > ,
63
+ ] }
64
+ />
49
65
) }
50
66
ouiaId = "BasicDropdown"
51
67
shouldFocusToggleOnSelect
@@ -59,4 +75,4 @@ export const EndpointsDropdown: React.FunctionComponent<EndpointsDropdownProps>
59
75
</ DropdownList >
60
76
</ Dropdown >
61
77
) ;
62
- } ;
78
+ } ;
0 commit comments