Skip to content

Commit 7791b3c

Browse files
authored
ui: simplify code using optional chaining in the zone view (#5626)
1 parent d8d5665 commit 7791b3c

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

ui/src/views/infra/zone/ZoneWizardAddResources.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ export default {
130130
},
131131
computed: {
132132
zoneType () {
133-
return this.prefillContent.zoneType ? this.prefillContent.zoneType.value : null
133+
return this.prefillContent.zoneType?.value || null
134134
},
135135
hypervisor () {
136-
return this.prefillContent.hypervisor ? this.prefillContent.hypervisor.value : null
136+
return this.prefillContent.hypervisor?.value || null
137137
},
138138
localstorageenabled () {
139139
return this.prefillContent?.localstorageenabled?.value || false
@@ -143,7 +143,7 @@ export default {
143143
},
144144
steps () {
145145
const steps = []
146-
const hypervisor = this.prefillContent.hypervisor ? this.prefillContent.hypervisor.value : null
146+
const hypervisor = this.prefillContent.hypervisor?.value || null
147147
steps.push({
148148
title: 'label.cluster',
149149
fromKey: 'clusterResource',
@@ -713,7 +713,7 @@ export default {
713713
}
714714
},
715715
created () {
716-
this.currentStep = this.prefillContent.resourceStep ? this.prefillContent.resourceStep : 0
716+
this.currentStep = this.prefillContent.resourceStep?.resourceStep || 0
717717
if (this.stepChild && this.stepChild !== '') {
718718
this.currentStep = this.steps.findIndex(item => item.fromKey === this.stepChild)
719719
}
@@ -791,7 +791,7 @@ export default {
791791
}
792792
},
793793
fetchScope () {
794-
const hypervisor = this.prefillContent.hypervisor ? this.prefillContent.hypervisor.value : null
794+
const hypervisor = this.prefillContent.hypervisor?.value || null
795795
const scope = []
796796
if (['KVM', 'VMware', 'Hyperv'].includes(hypervisor)) {
797797
scope.push({
@@ -812,7 +812,7 @@ export default {
812812
this.$forceUpdate()
813813
},
814814
fetchProtocol () {
815-
const hypervisor = this.prefillContent.hypervisor ? this.prefillContent.hypervisor.value : null
815+
const hypervisor = this.prefillContent.hypervisor?.value || null
816816
const protocols = []
817817
if (hypervisor === 'KVM') {
818818
protocols.push({
@@ -903,7 +903,7 @@ export default {
903903
this.$forceUpdate()
904904
},
905905
async fetchConfigurationSwitch () {
906-
const hypervisor = this.prefillContent.hypervisor ? this.prefillContent.hypervisor.value : null
906+
const hypervisor = this.prefillContent.hypervisor?.value || null
907907
this.$emit('fieldsChanged', { dvSwitchEnabled: { value: false } })
908908
this.$emit('fieldsChanged', { vSwitchEnabled: { value: false } })
909909
if (hypervisor && hypervisor === 'VMware') {

ui/src/views/infra/zone/ZoneWizardNetworkSetupStep.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ export default {
148148
},
149149
computed: {
150150
zoneType () {
151-
return this.prefillContent.zoneType ? this.prefillContent.zoneType.value : null
151+
return this.prefillContent.zoneType?.value || null
152152
},
153153
sgEnabled () {
154-
return this.prefillContent.securityGroupsEnabled ? this.prefillContent.securityGroupsEnabled.value : false
154+
return this.prefillContent.securityGroupsEnabled?.value || false
155155
},
156156
havingNetscaler () {
157-
return this.prefillContent.networkOfferingSelected ? this.prefillContent.networkOfferingSelected.havingNetscaler : false
157+
return this.prefillContent.networkOfferingSelected?.havingNetscaler || false
158158
},
159159
guestTrafficRangeMode () {
160160
return this.zoneType === 'Basic' ||
@@ -372,7 +372,7 @@ export default {
372372
created () {
373373
this.physicalNetworks = this.prefillContent.physicalNetworks
374374
this.steps = this.filteredSteps()
375-
this.currentStep = this.prefillContent.networkStep ? this.prefillContent.networkStep : 0
375+
this.currentStep = this.prefillContent?.networkStep || 0
376376
if (this.stepChild && this.stepChild !== '') {
377377
this.currentStep = this.steps.findIndex(item => item.formKey === this.stepChild)
378378
}

ui/src/views/infra/zone/ZoneWizardPhysicalNetworkSetupStep.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ export default {
287287
return this.zoneType === 'Advanced'
288288
},
289289
zoneType () {
290-
return this.prefillContent.zoneType ? this.prefillContent.zoneType.value : null
290+
return this.prefillContent.zoneType?.value || null
291291
},
292292
securityGroupsEnabled () {
293-
return this.isAdvancedZone && (this.prefillContent.securityGroupsEnabled ? this.prefillContent.securityGroupsEnabled.value : false)
293+
return this.isAdvancedZone && (this.prefillContent.securityGroupsEnabled?.value || false)
294294
},
295295
networkOfferingSelected () {
296296
return this.prefillContent.networkOfferingSelected

ui/src/views/infra/zone/ZoneWizardZoneDetailsStep.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ export default {
382382
ipV6Regex: /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i
383383
}),
384384
created () {
385-
this.hypervisors = this.prefillContent.hypervisors ? this.prefillContent.hypervisors : null
386-
this.networkOfferings = this.prefillContent.networkOfferings ? this.prefillContent.networkOfferings : null
385+
this.hypervisors = this.prefillContent.hypervisors?.hypervisors || null
386+
this.networkOfferings = this.prefillContent?.networkOfferings || null
387387
this.form = this.$form.createForm(this, {
388388
onFieldsChange: (_, changedFields) => {
389389
if (changedFields.networkOfferingId && this.prefillContent.networkOfferingSelected) {
@@ -433,37 +433,37 @@ export default {
433433
return this.zoneType === 'Advanced'
434434
},
435435
zoneType () {
436-
return this.prefillContent.zoneType ? this.prefillContent.zoneType.value : null
436+
return this.prefillContent.zoneType?.value || null
437437
},
438438
securityGroupsEnabled () {
439-
return this.isAdvancedZone && (this.prefillContent.securityGroupsEnabled ? this.prefillContent.securityGroupsEnabled.value : false)
439+
return this.isAdvancedZone && (this.prefillContent.securityGroupsEnabled?.value || false)
440440
},
441441
name () {
442-
return this.prefillContent.name ? this.prefillContent.name.value : null
442+
return this.prefillContent.name?.value || null
443443
},
444444
ipv4Dns1 () {
445-
return this.prefillContent.ipv4Dns1 ? this.prefillContent.ipv4Dns1.value : null
445+
return this.prefillContent.ipv4Dns1?.value || null
446446
},
447447
ipv4Dns2 () {
448-
return this.prefillContent.ipv4Dns2 ? this.prefillContent.ipv4Dns2.value : null
448+
return this.prefillContent.ipv4Dns2?.value || null
449449
},
450450
ipv6Dns1 () {
451-
return this.prefillContent.ipv6Dns1 ? this.prefillContent.ipv6Dns1.value : null
451+
return this.prefillContent.ipv6Dns1?.value || null
452452
},
453453
ipv6Dns2 () {
454-
return this.prefillContent.ipv6Dns2 ? this.prefillContent.ipv6Dns2.value : null
454+
return this.prefillContent.ipv6Dns2?.value || null
455455
},
456456
internalDns1 () {
457-
return this.prefillContent.internalDns1 ? this.prefillContent.internalDns1.value : null
457+
return this.prefillContent.internalDns1?.value || null
458458
},
459459
internalDns2 () {
460-
return this.prefillContent.internalDns2 ? this.prefillContent.internalDns2.value : null
460+
return this.prefillContent.internalDns2?.value || null
461461
},
462462
ipv6Cidr () {
463-
return this.prefillContent.ipv6Cidr ? this.prefillContent.ipv6Cidr.value : null
463+
return this.prefillContent.ipv6Cidr?.value || null
464464
},
465465
ip6gateway () {
466-
return this.prefillContent.ip6gateway ? this.prefillContent.ip6gateway.value : null
466+
return this.prefillContent.ip6gateway?.value || null
467467
},
468468
currentHypervisor () {
469469
if (this.prefillContent.hypervisor) {
@@ -474,7 +474,7 @@ export default {
474474
return null
475475
},
476476
currentNetworkOfferingId () {
477-
const lastNetworkOfferingId = this.prefillContent.networkOfferingSelected ? this.prefillContent.networkOfferingSelected.id : null
477+
const lastNetworkOfferingId = this.prefillContent.networkOfferingSelected?.id || null
478478
if (this.networkOfferings) {
479479
if (lastNetworkOfferingId !== null && this.networkOfferings[lastNetworkOfferingId]) {
480480
return lastNetworkOfferingId
@@ -484,29 +484,29 @@ export default {
484484
return null
485485
},
486486
networkDomain () {
487-
return this.prefillContent.networkDomain ? this.prefillContent.networkDomain.value : null
487+
return this.prefillContent.networkDomain?.value || null
488488
},
489489
guestcidraddress () {
490-
return this.prefillContent.guestcidraddress ? this.prefillContent.guestcidraddress.value : '10.1.1.0/24'
490+
return this.prefillContent.guestcidraddress?.value || '10.1.1.0/24'
491491
},
492492
isDedicated () {
493-
return this.prefillContent.isDedicated ? this.prefillContent.isDedicated.value : false
493+
return this.prefillContent.isDedicated?.value || false
494494
},
495495
domain () {
496-
const lastDomainId = this.prefillContent.domainId ? this.prefillContent.domainId.value : null
496+
const lastDomainId = this.prefillContent.domainId?.value || null
497497
if (this.domains !== null && lastDomainId !== null && this.domains[lastDomainId]) {
498498
return lastDomainId
499499
}
500500
return null
501501
},
502502
account () {
503-
return this.prefillContent.account ? this.prefillContent.account.value : null
503+
return this.prefillContent.account?.value || null
504504
},
505505
localstorageenabled () {
506-
return this.prefillContent.localstorageenabled ? this.prefillContent.localstorageenabled.value : false
506+
return this.prefillContent.localstorageenabled?.value || false
507507
},
508508
localstorageenabledforsystemvm () {
509-
return this.prefillContent.localstorageenabledforsystemvm ? this.prefillContent.localstorageenabledforsystemvm.value : false
509+
return this.prefillContent.localstorageenabledforsystemvm?.value || false
510510
}
511511
},
512512
methods: {

0 commit comments

Comments
 (0)