@@ -20,11 +20,11 @@ import {
20
20
import { ExternalPlaformIds , ExternalPlatformLabels , ExternalPlatformLinks } from './constants' ;
21
21
import { PlatformType , SupportLevel } from '@openshift-assisted/types/assisted-installer-service' ;
22
22
import {
23
- NewFeatureSupportLevelData ,
24
23
NewFeatureSupportLevelMap ,
25
24
useNewFeatureSupportLevel ,
26
25
} from '../../../../common/components/newFeatureSupportLevels' ;
27
26
import NewFeatureSupportLevelBadge from '../../../../common/components/newFeatureSupportLevels/NewFeatureSupportLevelBadge' ;
27
+ import { useFeature } from '../../../hooks/use-feature' ;
28
28
29
29
const INPUT_NAME = 'platform' ;
30
30
const fieldId = getFieldId ( INPUT_NAME , 'input' ) ;
@@ -45,7 +45,12 @@ export type ExternalPlatformInfo = {
45
45
46
46
const getDisabledReasonForExternalPlatform = (
47
47
isSNO : boolean ,
48
- newFeatureSupportLevelContext : NewFeatureSupportLevelData ,
48
+ getFeatureDisabledReason : (
49
+ featureId : FeatureId ,
50
+ supportLevelData ?: NewFeatureSupportLevelMap ,
51
+ cpuArchitecture ?: SupportedCpuArchitecture ,
52
+ platformType ?: PlatformType ,
53
+ ) => string | undefined ,
49
54
platform : PlatformType ,
50
55
featureSupportLevelData ?: NewFeatureSupportLevelMap | null ,
51
56
cpuArchitecture ?: SupportedCpuArchitecture ,
@@ -58,43 +63,63 @@ const getDisabledReasonForExternalPlatform = (
58
63
) {
59
64
return `Plaform integration is not supported for Single-Node OpenShift with the selected CPU architecture.` ;
60
65
} else {
61
- return newFeatureSupportLevelContext . getFeatureDisabledReason (
66
+ return getFeatureDisabledReason (
62
67
ExternalPlaformIds [ platform ] as FeatureId ,
63
68
featureSupportLevelData ?? undefined ,
64
69
cpuArchitecture ,
65
70
) ;
66
71
}
67
72
} ;
68
73
74
+ const isAvailablePlatform = ( platform : PlatformType ) => ( isDisconnected ?: boolean ) => {
75
+ if ( isDisconnected && platform === 'nutanix' ) {
76
+ return false ;
77
+ }
78
+ return platform !== undefined ;
79
+ } ;
80
+
69
81
const getExternalPlatformTypes = (
70
82
isSNO : boolean ,
71
- newFeatureSupportLevelContext : NewFeatureSupportLevelData ,
83
+ getFeatureSupportLevel : (
84
+ featureId : FeatureId ,
85
+ supportLevelData ?: NewFeatureSupportLevelMap ,
86
+ ) => SupportLevel | undefined ,
87
+ getFeatureDisabledReason : (
88
+ featureId : FeatureId ,
89
+ supportLevelData ?: NewFeatureSupportLevelMap ,
90
+ cpuArchitecture ?: SupportedCpuArchitecture ,
91
+ platformType ?: PlatformType ,
92
+ ) => string | undefined ,
72
93
featureSupportLevelData ?: NewFeatureSupportLevelMap | null ,
73
94
cpuArchitecture ?: SupportedCpuArchitecture ,
95
+ isDisconnected ?: boolean ,
74
96
) : Partial < { [ key in PlatformType ] : ExternalPlatformInfo } > => {
75
97
const platforms = [ 'none' , 'nutanix' , 'external' , 'vsphere' ] as PlatformType [ ] ;
76
98
77
- return platforms . filter ( Boolean ) . reduce (
78
- ( a , platform ) => ( {
79
- ...a ,
80
- [ platform ] : {
81
- label : ExternalPlatformLabels [ platform ] ,
82
- href : ExternalPlatformLinks [ platform ] ,
83
- disabledReason : getDisabledReasonForExternalPlatform (
84
- isSNO ,
85
- newFeatureSupportLevelContext ,
86
- platform ,
87
- featureSupportLevelData ?? undefined ,
88
- cpuArchitecture ,
89
- ) ,
90
- supportLevel : newFeatureSupportLevelContext . getFeatureSupportLevel (
91
- ExternalPlaformIds [ platform ] as FeatureId ,
92
- featureSupportLevelData ?? undefined ,
93
- ) ,
94
- } ,
95
- } ) ,
96
- { } ,
97
- ) ;
99
+ const newPlatform = platforms
100
+ . filter ( ( platform ) => isAvailablePlatform ( platform ) ( isDisconnected ) )
101
+ . reduce (
102
+ ( a , platform ) => ( {
103
+ ...a ,
104
+ [ platform ] : {
105
+ label : ExternalPlatformLabels [ platform ] ,
106
+ href : ExternalPlatformLinks [ platform ] ,
107
+ disabledReason : getDisabledReasonForExternalPlatform (
108
+ isSNO ,
109
+ getFeatureDisabledReason ,
110
+ platform ,
111
+ featureSupportLevelData ?? undefined ,
112
+ cpuArchitecture ,
113
+ ) ,
114
+ supportLevel : getFeatureSupportLevel (
115
+ ExternalPlaformIds [ platform ] as FeatureId ,
116
+ featureSupportLevelData ?? undefined ,
117
+ ) ,
118
+ } ,
119
+ } ) ,
120
+ { } ,
121
+ ) ;
122
+ return newPlatform ;
98
123
} ;
99
124
100
125
export const areAllExternalPlatformIntegrationDisabled = (
@@ -124,30 +149,42 @@ export const ExternalPlatformDropdown = ({
124
149
const [ externalPlatformTypes , setExternalPlatformTypes ] = React . useState <
125
150
Partial < { [ key in PlatformType ] : ExternalPlatformInfo } >
126
151
> ( { } ) ;
152
+ const isSingleClusterFeatureEnabled = useFeature ( 'ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE' ) ;
127
153
128
154
const tooltipDropdownDisabled = getReasonForDropdownDisabled (
129
155
isSNO ,
130
156
cpuArchitecture ? architectureData [ cpuArchitecture ] . label : '' ,
131
157
) ;
132
158
133
- const handleClick = ( event : MouseEvent < HTMLButtonElement > , href : string ) => {
159
+ const handleClick = ( event : MouseEvent < HTMLButtonElement > , href : string ) : void => {
134
160
event . stopPropagation ( ) ; // Stop event propagation here
135
161
window . open ( href , '_blank' ) ;
136
162
} ;
137
- const newFeatureSupportLevelContext = useNewFeatureSupportLevel ( ) ;
163
+
164
+ // eslint-disable-next-line @typescript-eslint/unbound-method
165
+ const { getFeatureSupportLevel, getFeatureDisabledReason } = useNewFeatureSupportLevel ( ) ;
166
+
138
167
React . useEffect ( ( ) => {
139
168
// Calculate updated externalPlatformTypes based on the dependencies
140
169
const updatedExternalPlatformTypes = getExternalPlatformTypes (
141
170
isSNO ,
142
- newFeatureSupportLevelContext ,
171
+ getFeatureSupportLevel ,
172
+ getFeatureDisabledReason ,
143
173
featureSupportLevelData ,
144
174
cpuArchitecture ,
175
+ isSingleClusterFeatureEnabled ,
145
176
) ;
146
177
147
178
// Update the state with the new externalPlatformTypes
148
179
setExternalPlatformTypes ( updatedExternalPlatformTypes ) ;
149
- // eslint-disable-next-line react-hooks/exhaustive-deps
150
- } , [ featureSupportLevelData , cpuArchitecture , isSNO ] ) ;
180
+ } , [
181
+ featureSupportLevelData ,
182
+ cpuArchitecture ,
183
+ isSNO ,
184
+ isSingleClusterFeatureEnabled ,
185
+ getFeatureSupportLevel ,
186
+ getFeatureDisabledReason ,
187
+ ] ) ;
151
188
152
189
const dropdownIsDisabled = React . useMemo ( ( ) => {
153
190
return areAllExternalPlatformIntegrationDisabled ( externalPlatformTypes ) ;
0 commit comments