@@ -3,25 +3,31 @@ import {
33 impersonateStateToProps ,
44 useSafetyFirst ,
55} from '@console/dynamic-plugin-sdk' ;
6- import { Dropdown , MenuToggle , MenuToggleElement } from '@patternfly/react-core' ;
6+ import { Button , Dropdown , MenuToggle , MenuToggleElement } from '@patternfly/react-core' ;
77import { some } from 'lodash-es' ;
88import { useTranslation } from 'react-i18next' ;
99import { connect } from 'react-redux' ;
1010import { useNavigate } from 'react-router-dom-v5-compat' ;
1111
1212import { ReactNode , RefObject , useEffect , useState } from 'react' ;
13- import { KebabItems , KebabOption } from './kebab' ;
13+ import { KebabItem , KebabItems , KebabOption } from './kebab' ;
1414import { checkAccess } from './rbac' ;
1515
1616type ActionsMenuProps = {
1717 actions : KebabOption [ ] ;
1818 title ?: ReactNode ;
1919} ;
2020
21- const ActionsMenuDropdown = ( props ) => {
21+ type ActionsMenuDropdownProps = {
22+ actions : KebabOption [ ] ;
23+ title ?: ReactNode ;
24+ active ?: boolean ;
25+ } ;
26+
27+ const ActionsMenuDropdown : React . FCC < ActionsMenuDropdownProps > = ( { actions, title, active } ) => {
2228 const { t } = useTranslation ( ) ;
2329 const navigate = useNavigate ( ) ;
24- const [ active , setActive ] = useState ( ! ! props . active ) ;
30+ const [ isActive , setIsActive ] = useState ( ! ! active ) ;
2531
2632 const onClick = ( event , option ) => {
2733 event . preventDefault ( ) ;
@@ -34,14 +40,22 @@ const ActionsMenuDropdown = (props) => {
3440 navigate ( option . href ) ;
3541 }
3642
37- setActive ( false ) ;
43+ setIsActive ( false ) ;
3844 } ;
3945
46+ if ( actions . length === 0 ) {
47+ return null ;
48+ }
49+
50+ if ( actions . length === 1 ) {
51+ return < KebabItem option = { actions [ 0 ] } onClick = { onClick } Component = { Button } /> ;
52+ }
53+
4054 return (
4155 < Dropdown
42- isOpen = { active }
43- onSelect = { ( ) => setActive ( false ) }
44- onOpenChange = { setActive }
56+ isOpen = { isActive }
57+ onSelect = { ( ) => setIsActive ( false ) }
58+ onOpenChange = { setIsActive }
4559 shouldFocusToggleOnSelect
4660 popperProps = { {
4761 enableFlip : true ,
@@ -50,15 +64,15 @@ const ActionsMenuDropdown = (props) => {
5064 toggle = { ( toggleRef : RefObject < MenuToggleElement > ) => (
5165 < MenuToggle
5266 ref = { toggleRef }
53- onClick = { ( ) => setActive ( ! active ) }
67+ onClick = { ( ) => setIsActive ( ! active ) }
5468 isExpanded = { active }
5569 data-test-id = "actions-menu-button"
5670 >
57- { props . title || t ( 'public~Actions' ) }
71+ { title || t ( 'public~Actions' ) }
5872 </ MenuToggle >
5973 ) }
6074 >
61- < KebabItems options = { props . actions } onClick = { onClick } />
75+ < KebabItems options = { actions } onClick = { onClick } />
6276 </ Dropdown >
6377 ) ;
6478} ;
0 commit comments