@@ -9,19 +9,76 @@ const WorkflowEntryPoints = ({
99 field, selected, type, setShowModal, setSelectedValue,
1010} ) => {
1111 const [ data , setData ] = useState ( {
12- isLoading : true , list : { } , selectedItemId : selected ,
12+ isLoading : true , list : { } , selectedItemId : selected , key : 'workflow-entry-points' ,
1313 } ) ;
14+ const [ prevSelectedHeader , setPrevSelectedHeader ] = useState ( '' ) ;
15+ const [ sortDirectionRepository , setSortDirectionRepository ] = useState ( 'DESC' ) ;
16+ const [ sortDirectionName , setSortDirectionName ] = useState ( 'DESC' ) ;
1417
1518 const workflowTypes = {
1619 provision : __ ( 'Provision' ) ,
1720 reconfigure : __ ( 'Reconfigure' ) ,
1821 retire : __ ( 'Retirement' ) ,
1922 } ;
2023
24+ const sortFunction = ( selectedHeader , itemA , itemB ) => {
25+ if ( selectedHeader . key === 'name' ) {
26+ if ( itemA . name . text === itemB . name . text ) {
27+ return itemA . id - itemB . id ;
28+ }
29+ return itemA . name . text . localeCompare ( itemB . name . text , undefined , { sensitivity : 'base' } ) ;
30+ }
31+ if ( itemA [ 'configuration_script_source.name' ] === undefined ) {
32+ itemA [ 'configuration_script_source.name' ] = { text : '' } ;
33+ } else if ( itemB [ 'configuration_script_source.name' ] === undefined ) {
34+ itemB [ 'configuration_script_source.name' ] = { text : '' } ;
35+ }
36+ return itemA [ 'configuration_script_source.name' ] . text . localeCompare (
37+ itemB [ 'configuration_script_source.name' ] . text , undefined , { semsitivity : 'base' }
38+ ) ;
39+ } ;
40+
41+ const onSort = ( itemKey ) => {
42+ const selectedHeader = data . list . headers . find ( ( item ) => item === itemKey ) ;
43+ if ( selectedHeader ) {
44+ const sortedList = data . list ;
45+ // FIXME: Try to only have 1 sort.
46+ // Need this sort or else you have to click the column names twice to resort when changing columns
47+ sortedList . rows . sort ( ( a , b ) => sortFunction ( selectedHeader , a , b ) ) ;
48+ if ( prevSelectedHeader === selectedHeader . key ) {
49+ if ( selectedHeader . key === 'name' ) {
50+ if ( sortDirectionName === 'ASC' ) {
51+ sortedList . rows . sort ( ( a , b ) => sortFunction ( selectedHeader , a , b ) ) ;
52+ } else {
53+ sortedList . rows . sort ( ( a , b ) => sortFunction ( selectedHeader , b , a ) ) ;
54+ }
55+ setSortDirectionName ( sortDirectionName === 'ASC' ? 'DESC' : 'ASC' ) ;
56+ } else {
57+ if ( sortDirectionRepository === 'ASC' ) {
58+ sortedList . rows . sort ( ( a , b ) => sortFunction ( selectedHeader , a , b ) ) ;
59+ } else {
60+ sortedList . rows . sort ( ( a , b ) => sortFunction ( selectedHeader , b , a ) ) ;
61+ }
62+ setSortDirectionRepository ( sortDirectionRepository === 'ASC' ? 'DESC' : 'ASC' ) ;
63+ }
64+ } else {
65+ setSortDirectionName ( 'DESC' ) ;
66+ setSortDirectionRepository ( 'DESC' ) ;
67+ }
68+ const tempKey = `${ data . key } -${ sortedList . rows [ 0 ] . id } ` ;
69+ setPrevSelectedHeader ( selectedHeader . key ) ;
70+ setData ( {
71+ ...data , isLoading : false , list : sortedList , key : tempKey ,
72+ } ) ;
73+ }
74+ } ;
75+
2176 useEffect ( ( ) => {
2277 http . post ( `/catalog/ae_tree_select_toggle?typ=${ type } ` , { } , { headers : { } , skipJsonParsing : true } )
2378 . then ( ( _data ) => {
24- API . get ( '/api/configuration_script_payloads?expand=resources' )
79+ const url = '/api/configuration_script_payloads/?expand=resources&attributes=configuration_script_source.name&'
80+ + 'collection_class=ManageIQ::Providers::Workflows::AutomationManager::Workflow' ;
81+ API . get ( url )
2582 . then ( ( response ) => {
2683 setData ( {
2784 ...data ,
@@ -81,6 +138,7 @@ const WorkflowEntryPoints = ({
81138 open
82139 modalHeading = { sprintf ( __ ( 'Select Embedded Workflow - %s Entry Point' ) , workflowTypes [ type ] ) }
83140 primaryButtonText = { __ ( 'Apply' ) }
141+ primaryButtonDisabled = { ! data . selectedItemId }
84142 secondaryButtonText = { __ ( 'Cancel' ) }
85143 onRequestSubmit = { onApply }
86144 onRequestClose = { onCloseModal }
@@ -90,6 +148,9 @@ const WorkflowEntryPoints = ({
90148 < MiqDataTable
91149 headers = { data . list . headers }
92150 rows = { data . list . rows }
151+ sortable
152+ onSort = { onSort }
153+ key = { data . key }
93154 onCellClick = { ( selectedRow ) => onSelect ( selectedRow . id ) }
94155 showPagination = { false }
95156 truncateText = { false }
0 commit comments