1
1
import React , { useContext , useState } from 'react' ;
2
2
import { useSelector } from 'react-redux' ;
3
- import { Alert , Flex , FlexItem , Label , AlertActionCloseButton } from '@patternfly/react-core' ;
3
+ import { Alert , Flex , FlexItem , Label , AlertActionCloseButton , ExpandableSection } from '@patternfly/react-core' ;
4
4
import { ExclamationTriangleIcon } from '@patternfly/react-icons' ;
5
5
import { FormattedMessage } from 'react-intl' ;
6
6
import { translate as __ } from 'foremanReact/common/I18n' ;
7
- import { selectCVActivationKeys , selectCVHosts , selectCVVersions } from '../../../ContentViewDetailSelectors' ;
7
+ import { selectCVVersions } from '../../../ContentViewDetailSelectors' ;
8
8
import DeleteContext from '../DeleteContext' ;
9
9
import WizardHeader from '../../../../components/WizardHeader' ;
10
+ import AffectedHosts from '../affectedHosts' ;
11
+ import AffectedActivationKeys from '../affectedActivationKeys' ;
10
12
11
13
const CVVersionRemoveReview = ( ) => {
12
14
const [ alertDismissed , setAlertDismissed ] = useState ( false ) ;
15
+ const [ showHosts , setShowHosts ] = useState ( false ) ;
16
+ const [ showAKs , setShowAKs ] = useState ( false ) ;
13
17
const {
14
- cvId, versionIdToRemove, versionNameToRemove, selectedEnvSet,
18
+ cvId, versionEnvironments , versionIdToRemove, versionNameToRemove, selectedEnvSet,
15
19
selectedEnvForAK, selectedCVNameForAK, selectedCVNameForHosts,
16
- selectedEnvForHost, affectedActivationKeys , affectedHosts , deleteFlow, removeDeletionFlow,
20
+ selectedEnvForHost, deleteFlow, removeDeletionFlow,
17
21
} = useContext ( DeleteContext ) ;
18
- const activationKeysResponse = useSelector ( state => selectCVActivationKeys ( state , cvId ) ) ;
19
- const hostsResponse = useSelector ( state => selectCVHosts ( state , cvId ) ) ;
20
- const { results : hostResponse = [ ] } = hostsResponse || { } ;
21
- const { results : akResponse = [ ] } = activationKeysResponse || { } ;
22
22
const cvVersions = useSelector ( state => selectCVVersions ( state , cvId ) ) ;
23
23
const versionDeleteInfo = __ ( `Version ${ versionNameToRemove } will be deleted from all environments. It will no longer be available for promotion.` ) ;
24
24
const removalNotice = __ ( `Version ${ versionNameToRemove } will be removed from the environments listed below, and will remain available for later promotion. ` +
@@ -29,16 +29,19 @@ const CVVersionRemoveReview = () => {
29
29
. flatMap ( cv => cv . content_view_environments || [ ] )
30
30
. filter ( env => selectedEnvSet . has ( env . environment_id ) ) ;
31
31
32
- const multiCVHosts = hostResponse ?. filter ( host =>
33
- host . content_facet_attributes ?. multi_content_view_environment ) || [ ] ;
34
- const multiCVHostsCount = multiCVHosts . length ;
32
+ const selectedEnvs = versionEnvironments . filter ( env => selectedEnvSet . has ( env . id ) ) ;
35
33
36
- const singleCVHostsCount = ( hostResponse ?. length || 0 ) - multiCVHostsCount ;
34
+ const hostCount = selectedEnvs . reduce ( ( sum , env ) =>
35
+ sum + ( env . host_count || 0 ) , 0 ) ;
36
+ const multiCVHostsCount = selectedEnvs . reduce ( ( sum , env ) =>
37
+ sum + ( env . multi_env_host_count || 0 ) , 0 ) ;
38
+ const singleCVHostsCount = hostCount - multiCVHostsCount ;
37
39
38
- const multiCVActivationKeys = akResponse . filter ( key => key . multi_content_view_environment ) ;
39
- const multiCVActivationKeysCount = multiCVActivationKeys . length ;
40
-
41
- const singleCVActivationKeysCount = akResponse . length - multiCVActivationKeysCount ;
40
+ const akCount = selectedEnvs . reduce ( ( sum , env ) =>
41
+ sum + ( env . activation_key_count || 0 ) , 0 ) ;
42
+ const multiCVActivationKeysCount = selectedEnvs . reduce ( ( sum , env ) =>
43
+ sum + ( env . multi_env_ak_count || 0 ) , 0 ) ;
44
+ const singleCVActivationKeysCount = akCount - multiCVActivationKeysCount ;
42
45
43
46
return (
44
47
< >
@@ -66,7 +69,7 @@ const CVVersionRemoveReview = () => {
66
69
< FlexItem key = { name } > < Label color = "purple" href = { `/lifecycle_environments/${ id } ` } > { name } </ Label > </ FlexItem > ) }
67
70
</ Flex >
68
71
</ > }
69
- { affectedHosts &&
72
+ { hostCount > 0 &&
70
73
< >
71
74
< h3 > { __ ( 'Content hosts' ) } </ h3 >
72
75
{ singleCVHostsCount > 0 && (
@@ -121,8 +124,22 @@ const CVVersionRemoveReview = () => {
121
124
</ FlexItem >
122
125
</ Flex >
123
126
) }
127
+ < ExpandableSection
128
+ toggleText = { showHosts ? 'Hide hosts' : 'Show hosts' }
129
+ onToggle = { ( ) => setShowHosts ( prev => ! prev ) }
130
+ isExpanded = { showHosts }
131
+ >
132
+ < AffectedHosts
133
+ { ...{
134
+ cvId,
135
+ versionEnvironments,
136
+ selectedEnvSet,
137
+ } }
138
+ deleteCV = { false }
139
+ />
140
+ </ ExpandableSection >
124
141
</ > }
125
- { affectedActivationKeys &&
142
+ { akCount > 0 &&
126
143
< >
127
144
< h3 > { __ ( 'Activation keys' ) } </ h3 >
128
145
{ singleCVActivationKeysCount > 0 && (
@@ -177,6 +194,20 @@ const CVVersionRemoveReview = () => {
177
194
</ FlexItem >
178
195
</ Flex >
179
196
) }
197
+ < ExpandableSection
198
+ toggleText = { showAKs ? 'Hide activation keys' : 'Show activation keys' }
199
+ onToggle = { ( ) => setShowAKs ( prev => ! prev ) }
200
+ isExpanded = { showAKs }
201
+ >
202
+ < AffectedActivationKeys
203
+ { ...{
204
+ cvId,
205
+ versionEnvironments,
206
+ selectedEnvSet,
207
+ } }
208
+ deleteCV = { false }
209
+ />
210
+ </ ExpandableSection >
180
211
</ > }
181
212
</ >
182
213
) ;
0 commit comments