@@ -2,18 +2,12 @@ import * as _ from 'lodash-es';
2
2
import * as React from 'react' ;
3
3
import classNames from 'classnames' ;
4
4
import * as PropTypes from 'prop-types' ;
5
- import { connect } from 'react-redux' ;
6
- import { useTranslation , withTranslation } from 'react-i18next' ;
7
- import { useNavigate } from 'react-router-dom-v5-compat' ;
8
- import { Divider , Popper , Title } from '@patternfly/react-core' ;
9
- import { impersonateStateToProps , useSafetyFirst } from '@console/dynamic-plugin-sdk' ;
10
5
import { useUserSettingsCompatibility } from '@console/shared' ;
6
+ import { Divider , Popper , Title } from '@patternfly/react-core' ;
11
7
import { CaretDownIcon } from '@patternfly/react-icons/dist/esm/icons/caret-down-icon' ;
12
8
import { CheckIcon } from '@patternfly/react-icons/dist/esm/icons/check-icon' ;
13
9
import { StarIcon } from '@patternfly/react-icons/dist/esm/icons/star-icon' ;
14
-
15
- import { checkAccess } from './rbac' ;
16
- import { KebabItems } from './kebab' ;
10
+ import { withTranslation } from 'react-i18next' ;
17
11
18
12
class DropdownMixin extends React . PureComponent {
19
13
constructor ( props ) {
@@ -678,147 +672,3 @@ Dropdown.propTypes = {
678
672
required : PropTypes . bool ,
679
673
dataTest : PropTypes . string ,
680
674
} ;
681
-
682
- const ActionsMenuDropdown = ( props ) => {
683
- const { t } = useTranslation ( ) ;
684
- const navigate = useNavigate ( ) ;
685
- const [ active , setActive ] = React . useState ( ! ! props . active ) ;
686
-
687
- const dropdownElement = React . useRef ( ) ;
688
-
689
- const show = ( ) => {
690
- setActive ( true ) ;
691
- } ;
692
-
693
- const hide = ( e ) => {
694
- e ?. stopPropagation ( ) ;
695
- setActive ( false ) ;
696
- } ;
697
-
698
- const listener = React . useCallback (
699
- ( event ) => {
700
- if ( ! active ) {
701
- return ;
702
- }
703
-
704
- const { current } = dropdownElement ;
705
- if ( ! current ) {
706
- return ;
707
- }
708
-
709
- if ( event . target === current || current . contains ( event . target ) ) {
710
- return ;
711
- }
712
-
713
- hide ( event ) ;
714
- } ,
715
- [ active , dropdownElement ] ,
716
- ) ;
717
-
718
- React . useEffect ( ( ) => {
719
- if ( active ) {
720
- window . addEventListener ( 'click' , listener ) ;
721
- } else {
722
- window . removeEventListener ( 'click' , listener ) ;
723
- }
724
- return ( ) => {
725
- window . removeEventListener ( 'click' , listener ) ;
726
- } ;
727
- } , [ active , listener ] ) ;
728
-
729
- const toggle = ( e ) => {
730
- e . preventDefault ( ) ;
731
-
732
- if ( props . disabled ) {
733
- return ;
734
- }
735
-
736
- if ( active ) {
737
- hide ( e ) ;
738
- } else {
739
- show ( e ) ;
740
- }
741
- } ;
742
-
743
- const onClick = ( event , option ) => {
744
- event . preventDefault ( ) ;
745
-
746
- if ( option . callback ) {
747
- option . callback ( ) ;
748
- }
749
-
750
- if ( option . href ) {
751
- navigate ( option . href ) ;
752
- }
753
-
754
- hide ( ) ;
755
- } ;
756
-
757
- return (
758
- < div ref = { dropdownElement } >
759
- < button
760
- type = "button"
761
- aria-haspopup = "true"
762
- aria-label = { t ( 'public~Actions' ) }
763
- aria-expanded = { active }
764
- className = { classNames ( {
765
- 'pf-v6-c-menu-toggle' : true ,
766
- 'pf-m-expanded' : active ,
767
- } ) }
768
- onClick = { toggle }
769
- data-test-id = "actions-menu-button"
770
- >
771
- < span className = "pf-v6-c-menu__toggle-text" > { props . title || t ( 'public~Actions' ) } </ span >
772
- < CaretDownIcon />
773
- </ button >
774
- { active && (
775
- < div className = "co-actions-menu dropdown-menu pf-v6-c-menu" >
776
- < KebabItems options = { props . actions } onClick = { onClick } />
777
- </ div >
778
- ) }
779
- </ div >
780
- ) ;
781
- } ;
782
-
783
- const ActionsMenu_ = ( { actions, impersonate, title = undefined } ) => {
784
- const [ isVisible , setVisible ] = useSafetyFirst ( false ) ;
785
-
786
- // Check if any actions are visible when actions have access reviews.
787
- React . useEffect ( ( ) => {
788
- if ( ! actions . length ) {
789
- setVisible ( false ) ;
790
- return ;
791
- }
792
- const promises = actions . reduce ( ( acc , action ) => {
793
- if ( action . accessReview ) {
794
- acc . push ( checkAccess ( action . accessReview ) ) ;
795
- }
796
- return acc ;
797
- } , [ ] ) ;
798
-
799
- // Only need to resolve if all actions require access review
800
- if ( promises . length !== actions . length ) {
801
- setVisible ( true ) ;
802
- return ;
803
- }
804
- Promise . all ( promises )
805
- . then ( ( results ) => setVisible ( _ . some ( results , 'status.allowed' ) ) )
806
- . catch ( ( ) => setVisible ( true ) ) ;
807
- } , [ actions , impersonate , setVisible ] ) ;
808
- return isVisible ? < ActionsMenuDropdown actions = { actions } title = { title } /> : null ;
809
- } ;
810
-
811
- export const ActionsMenu = connect ( impersonateStateToProps ) ( ActionsMenu_ ) ;
812
-
813
- ActionsMenu . propTypes = {
814
- actions : PropTypes . arrayOf (
815
- PropTypes . shape ( {
816
- label : PropTypes . node ,
817
- labelKey : PropTypes . string ,
818
- href : PropTypes . string ,
819
- callback : PropTypes . func ,
820
- accessReview : PropTypes . object ,
821
- } ) ,
822
- ) . isRequired ,
823
- title : PropTypes . node ,
824
- } ;
0 commit comments