@@ -63,12 +63,15 @@ import { updateManagedGateway } from '@console/store/actions/gateways'
63
63
import {
64
64
selectSelectedGateway ,
65
65
selectSelectedManagedGateway ,
66
+ selectSelectedManagedGatewayHasWifi ,
67
+ selectSelectedManagedGatewayHasEthernet ,
66
68
} from '@console/store/selectors/gateways'
67
69
import { selectUserId } from '@account/store/selectors/user'
68
70
69
71
const m = defineMessages ( {
70
72
firstNotification :
71
- 'You have just claimed a managed gateway. To connect it to WiFi or ethernet you can configure those connections here. The preprovisioned cellular backhaul typically connects automatically.' ,
73
+ 'You have just claimed a managed gateway. You can configure its connection settings here.' ,
74
+ noConnectionSettings : 'This gateway does not have any connection settings to configure.' ,
72
75
updateSuccess : 'Connection settings updated' ,
73
76
updateFailure : 'There was an error updating these connection settings' ,
74
77
} )
@@ -91,14 +94,16 @@ const GatewayConnectionSettings = () => {
91
94
92
95
const connectionsData = useConnectionsData ( )
93
96
97
+ const hasWifi = useSelector ( selectSelectedManagedGatewayHasWifi )
98
+ const hasWifiProfileSet = hasWifi && Boolean ( selectedManagedGateway . wifi_profile_id )
99
+ const hasEthernet = useSelector ( selectSelectedManagedGatewayHasEthernet )
100
+ const hasEthernetProfileSet = hasEthernet && Boolean ( selectedManagedGateway . ethernet_profile_id )
101
+
94
102
const [ initialValues , setInitialValues ] = useState ( {
95
- wifi_profile : { ...initialWifiProfile } ,
96
- ethernet_profile : { ...initialEthernetProfile } ,
103
+ ... ( hasWifi && { wifi_profile : { ...initialWifiProfile } } ) ,
104
+ ... ( hasEthernet && { ethernet_profile : { ...initialEthernetProfile } } ) ,
97
105
} )
98
106
99
- const hasWifiProfileSet = Boolean ( selectedManagedGateway . wifi_profile_id )
100
- const hasEthernetProfileSet = Boolean ( selectedManagedGateway . ethernet_profile_id )
101
-
102
107
useBreadcrumbs (
103
108
'gtws.single.managed-gateway.connection-settings' ,
104
109
< Breadcrumb
@@ -110,7 +115,7 @@ const GatewayConnectionSettings = () => {
110
115
const fetchWifiProfile = useCallback (
111
116
async collaborators => {
112
117
let wifiProfile
113
- let entityId
118
+ let wifiProfileEntityId
114
119
115
120
if ( hasWifiProfileSet ) {
116
121
setError ( undefined )
@@ -125,7 +130,7 @@ const GatewayConnectionSettings = () => {
125
130
) ,
126
131
) ,
127
132
)
128
- entityId = userId
133
+ wifiProfileEntityId = userId
129
134
} catch ( e ) {
130
135
if ( ! isNotFoundError ( e ) ) {
131
136
setError ( e )
@@ -150,7 +155,7 @@ const GatewayConnectionSettings = () => {
150
155
) ,
151
156
) ,
152
157
)
153
- entityId = orgId
158
+ wifiProfileEntityId = orgId
154
159
break
155
160
} catch ( e ) {
156
161
if ( ! isNotFoundError ( e ) ) {
@@ -161,7 +166,7 @@ const GatewayConnectionSettings = () => {
161
166
}
162
167
}
163
168
}
164
- return { wifiProfile, entityId }
169
+ return { wifiProfile, wifiProfileEntityId }
165
170
} ,
166
171
[ dispatch , hasWifiProfileSet , selectedManagedGateway . wifi_profile_id , userId ] ,
167
172
)
@@ -219,21 +224,33 @@ const GatewayConnectionSettings = () => {
219
224
const { entities } = await dispatch ( attachPromise ( getCollaboratorsList ( 'gateway' , gtwId ) ) )
220
225
collaborators = entities
221
226
}
222
- const { wifiProfile, entityId } = await fetchWifiProfile ( collaborators )
223
- const { ethernetProfile } = await fetchEthernetProfile ( )
224
- const isNonSharedProfile = Boolean ( wifiProfile ) && ! Boolean ( wifiProfile . data . shared )
225
- if ( isNonSharedProfile ) {
226
- setNonSharedWifiProfileId ( selectedManagedGateway . wifi_profile_id )
227
+ let newValues = { }
228
+ if ( hasWifi ) {
229
+ const { wifiProfile, wifiProfileEntityId } = await fetchWifiProfile ( collaborators )
230
+ const isNonSharedWifiProfile = Boolean ( wifiProfile ) && ! Boolean ( wifiProfile . data . shared )
231
+ if ( isNonSharedWifiProfile ) {
232
+ setNonSharedWifiProfileId ( selectedManagedGateway . wifi_profile_id )
233
+ }
234
+ newValues = {
235
+ ...newValues ,
236
+ wifi_profile : updateInitialWifiProfile (
237
+ initialValues ,
238
+ wifiProfile ,
239
+ wifiProfileEntityId ,
240
+ isNonSharedWifiProfile ,
241
+ ) ,
242
+ }
243
+ }
244
+ if ( hasEthernet ) {
245
+ const { ethernetProfile } = await fetchEthernetProfile ( )
246
+ newValues = {
247
+ ...newValues ,
248
+ ethernet_profile : updateInitialEthernetProfile ( initialValues , ethernetProfile ) ,
249
+ }
227
250
}
228
251
setInitialValues ( oldValues => ( {
229
252
...oldValues ,
230
- wifi_profile : updateInitialWifiProfile (
231
- oldValues ,
232
- wifiProfile ,
233
- entityId ,
234
- isNonSharedProfile ,
235
- ) ,
236
- ethernet_profile : updateInitialEthernetProfile ( oldValues , ethernetProfile ) ,
253
+ ...newValues ,
237
254
} ) )
238
255
} ,
239
256
[
@@ -312,31 +329,43 @@ const GatewayConnectionSettings = () => {
312
329
313
330
setError ( undefined )
314
331
try {
332
+ let body = { }
315
333
const { wifi_profile, ethernet_profile } = values
316
334
317
- const shouldUpdateNonSharedWifiProfile =
318
- wifi_profile . profile_id === 'non-shared' &&
319
- Boolean ( nonSharedWifiProfileId ) &&
320
- wifi_profile . _enable_wifi_connection
321
-
322
- const wifiProfileId = await getWifiProfileId ( wifi_profile , shouldUpdateNonSharedWifiProfile )
323
- const ethernetProfileId = await getEthernetProfileId (
324
- ethernet_profile ,
325
- cleanValues . ethernet_profile ,
326
- )
327
- const body = {
328
- wifi_profile_id :
329
- ! wifi_profile . _enable_wifi_connection && ! wifi_profile . _override ? null : wifiProfileId ,
330
- ethernet_profile_id : ethernetProfileId ,
335
+ let wifiProfileId
336
+ if ( hasWifi ) {
337
+ const shouldUpdateNonSharedWifiProfile =
338
+ wifi_profile . profile_id === 'non-shared' &&
339
+ Boolean ( nonSharedWifiProfileId ) &&
340
+ wifi_profile . _enable_wifi_connection
341
+
342
+ wifiProfileId = await getWifiProfileId ( wifi_profile , shouldUpdateNonSharedWifiProfile )
343
+ body = {
344
+ ...body ,
345
+ wifi_profile_id :
346
+ ! wifi_profile . _enable_wifi_connection && ! wifi_profile . _override
347
+ ? null
348
+ : wifiProfileId ,
349
+ }
350
+ }
351
+ if ( hasEthernet ) {
352
+ const ethernetProfileId = await getEthernetProfileId (
353
+ ethernet_profile ,
354
+ cleanValues . ethernet_profile ,
355
+ )
356
+ body = {
357
+ ...body ,
358
+ ethernet_profile_id : ethernetProfileId ,
359
+ }
331
360
}
332
361
333
362
await dispatch ( attachPromise ( updateManagedGateway ( gtwId , body ) ) )
334
363
335
364
// Reset the form and the initial values
336
365
let resetValues = { ...values }
337
- if ( wifi_profile . profile_id !== 'non-shared' ) {
366
+ if ( hasWifi && wifi_profile . profile_id !== 'non-shared' ) {
338
367
resetValues = {
339
- ...values ,
368
+ ...resetValues ,
340
369
wifi_profile : {
341
370
...values . wifi_profile ,
342
371
...initialWifiProfile ,
@@ -351,7 +380,7 @@ const GatewayConnectionSettings = () => {
351
380
values : resetValues ,
352
381
} )
353
382
354
- if ( resetValues . wifi_profile . _enable_wifi_connection ) {
383
+ if ( hasWifi && resetValues . wifi_profile . _enable_wifi_connection ) {
355
384
setSaveFormClicked ( true )
356
385
}
357
386
@@ -385,31 +414,39 @@ const GatewayConnectionSettings = () => {
385
414
< RequireRequest requestAction = { loadData } >
386
415
< div className = "item-12 lg:item-6 lg-xl:item-6 xl:item-7" >
387
416
< PageTitle title = { sharedMessages . connectionSettings } />
388
- { isFirstClaim && < Notification info small content = { m . firstNotification } /> }
389
- < Form
390
- error = { error }
391
- onSubmit = { handleSubmit }
392
- initialValues = { initialValues }
393
- validationSchema = { validationSchema }
394
- >
417
+ { hasWifi || hasEthernet ? (
395
418
< >
396
- < WifiSettingsFormFields
419
+ { isFirstClaim && < Notification info small content = { m . firstNotification } /> }
420
+ < Form
421
+ error = { error }
422
+ onSubmit = { handleSubmit }
397
423
initialValues = { initialValues }
398
- isWifiConnected = { connectionsData . isWifiConnected }
399
- saveFormClicked = { saveFormClicked }
400
- />
401
- < hr />
402
- < EthernetSettingsFormFields />
403
-
404
- < SubmitBar className = "mb-cs-l" >
405
- < Form . Submit
406
- component = { SubmitButton }
407
- message = { sharedMessages . saveChanges }
408
- disabled = { isLoading }
409
- />
410
- </ SubmitBar >
424
+ validationSchema = { validationSchema }
425
+ >
426
+ < >
427
+ { hasWifi && (
428
+ < WifiSettingsFormFields
429
+ initialValues = { initialValues }
430
+ isWifiConnected = { connectionsData . isWifiConnected }
431
+ saveFormClicked = { saveFormClicked }
432
+ />
433
+ ) }
434
+ { hasWifi && hasEthernet && < hr /> }
435
+ { hasEthernet && < EthernetSettingsFormFields /> }
436
+
437
+ < SubmitBar className = "mb-cs-l" >
438
+ < Form . Submit
439
+ component = { SubmitButton }
440
+ message = { sharedMessages . saveChanges }
441
+ disabled = { isLoading }
442
+ />
443
+ </ SubmitBar >
444
+ </ >
445
+ </ Form >
411
446
</ >
412
- </ Form >
447
+ ) : (
448
+ < Notification info small content = { m . noConnectionSettings } />
449
+ ) }
413
450
</ div >
414
451
< div className = "item-12 lg:item-6 lg-xl:item-6 xl:item-5" >
415
452
< ManagedGatewayConnections connectionsData = { connectionsData } />
0 commit comments