7
7
ICatalogCard ,
8
8
ItemView ,
9
9
} from '@stolostron/react-data-view'
10
- import { useCallback , useMemo , useState } from 'react'
10
+ import React , { useCallback , useMemo , useState } from 'react'
11
11
import { useTranslation } from '../../../../../lib/acm-i18next'
12
12
import { NavigationPath , useBackCancelNavigation } from '../../../../../NavigationPath'
13
13
import {
@@ -21,8 +21,39 @@ import {
21
21
import { DOC_LINKS , ViewDocumentationLink } from '../../../../../lib/doc-util'
22
22
import { useSharedAtoms , useRecoilState } from '../../../../../shared-recoil'
23
23
import { ClusterInfrastructureType , getTypedCreateClusterPath } from '../ClusterInfrastructureType'
24
- import { Divider , ExpandableSection } from '@patternfly/react-core'
24
+ import { Divider , ExpandableSection , Stack , StackItem } from '@patternfly/react-core'
25
25
import { useDataViewStrings } from '../../../../../lib/dataViewStrings'
26
+ import { ClusterImageSet } from '../../../../../resources'
27
+ import { TFunction } from 'i18next'
28
+
29
+ const hasClusterImageSetWithArch = ( clusterImageSets : ClusterImageSet [ ] , arch : string ) =>
30
+ clusterImageSets . filter ( ( cis ) => cis . spec ?. releaseImage . endsWith ( arch ) && cis . metadata . labels ?. visible === 'true' )
31
+
32
+ const clusterImageSetsRequired = (
33
+ clusterImageSets : ClusterImageSet [ ] ,
34
+ t : TFunction ,
35
+ children ?: React . ReactNode
36
+ ) : {
37
+ alertTitle : ICatalogCard [ 'alertTitle' ]
38
+ alertVariant : ICatalogCard [ 'alertVariant' ]
39
+ alertContent : ICatalogCard [ 'alertContent' ]
40
+ } => ( {
41
+ alertTitle : clusterImageSets . length ? undefined : t ( 'OpenShift release images unavailable' ) ,
42
+ alertVariant : 'info' ,
43
+ alertContent : (
44
+ < Stack hasGutter >
45
+ < StackItem >
46
+ < >
47
+ { t (
48
+ 'No release image is available. Follow cluster creation prerequisite documentation to learn how to add release images.'
49
+ ) }
50
+ </ >
51
+ < ViewDocumentationLink doclink = { DOC_LINKS . CREATE_CLUSTER_PREREQ } />
52
+ </ StackItem >
53
+ { children && < StackItem > { children } </ StackItem > }
54
+ </ Stack >
55
+ ) ,
56
+ } )
26
57
27
58
type CardProvider = Provider & ( ClusterInfrastructureType | Provider . hostinventory | Provider . nutanix )
28
59
type CardData = {
@@ -131,7 +162,7 @@ export function CreateClusterCatalog() {
131
162
} else if ( provider === Provider . hostinventory ) {
132
163
return clusterImageSets . length ? nextStep ( NavigationPath . createBMControlPlane ) : undefined
133
164
} else if ( provider === Provider . nutanix ) {
134
- return clusterImageSets . length
165
+ return hasClusterImageSetWithArch ( clusterImageSets , 'x86_64' ) . length
135
166
? nextStep ( {
136
167
pathname : NavigationPath . createDiscoverHost ,
137
168
search : 'nutanix=true' ,
@@ -164,33 +195,38 @@ export function CreateClusterCatalog() {
164
195
labels,
165
196
onClick : getOnClickAction ( provider ) ,
166
197
}
167
- if ( provider === Provider . hostinventory ) {
168
- card = {
169
- ...card ,
170
- title : t ( 'Host inventory' ) ,
171
- alertTitle : clusterImageSets . length ? undefined : t ( 'OpenShift release images unavailable' ) ,
172
- alertVariant : 'info' ,
173
- alertContent : (
174
- < >
175
- { t (
176
- 'No release image is available. Follow cluster creation prerequisite documentation to learn how to add release images.'
177
- ) }
178
- < ViewDocumentationLink doclink = { DOC_LINKS . CREATE_CLUSTER_PREREQ } />
179
- </ >
180
- ) ,
181
- }
182
- } else if ( provider === Provider . redhatvirtualization ) {
183
- card = {
184
- ...card ,
185
- alertTitle : t ( 'Deprecated host platform' ) ,
186
- alertVariant : 'info' ,
187
- alertContent : (
188
- < >
189
- { t ( 'Red Hat Virtualization is deprecated for OpenShift 4.13.' ) }
190
- < ViewDocumentationLink doclink = { DOC_LINKS . RHV_DEPRECATION } />
191
- </ >
192
- ) ,
193
- }
198
+
199
+ switch ( provider ) {
200
+ case Provider . hostinventory :
201
+ card = {
202
+ ...card ,
203
+ title : t ( 'Host inventory' ) ,
204
+ ...clusterImageSetsRequired ( clusterImageSets , t ) ,
205
+ }
206
+ break
207
+ case Provider . nutanix :
208
+ card = {
209
+ ...card ,
210
+ ...clusterImageSetsRequired (
211
+ hasClusterImageSetWithArch ( clusterImageSets , 'x86_64' ) ,
212
+ t ,
213
+ < > { t ( 'Nutanix requires x86_64 release image. No other architecture is supported.' ) } </ >
214
+ ) ,
215
+ }
216
+ break
217
+ case Provider . redhatvirtualization :
218
+ card = {
219
+ ...card ,
220
+ alertTitle : t ( 'Deprecated host platform' ) ,
221
+ alertVariant : 'info' ,
222
+ alertContent : (
223
+ < >
224
+ { t ( 'Red Hat Virtualization is deprecated for OpenShift 4.13.' ) }
225
+ < ViewDocumentationLink doclink = { DOC_LINKS . RHV_DEPRECATION } />
226
+ </ >
227
+ ) ,
228
+ }
229
+ break
194
230
}
195
231
return card
196
232
}
@@ -209,7 +245,7 @@ export function CreateClusterCatalog() {
209
245
} )
210
246
211
247
return { cardsWithCreds, cardsWithOutCreds }
212
- } , [ getCredentialLabels , clusterImageSets . length , t , cardsData , getOnClickAction ] )
248
+ } , [ getCredentialLabels , clusterImageSets , t , cardsData , getOnClickAction ] )
213
249
214
250
const keyFn = useCallback ( ( card : ICatalogCard ) => card . id , [ ] )
215
251
0 commit comments