Skip to content

Commit 60848ce

Browse files
committed
enable double confirmation in delete flow for resource
1 parent 1e512ab commit 60848ce

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

ui/public/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@
795795
"label.delete.ciscoasa1000v": "Delete CiscoASA1000v",
796796
"label.delete.ciscovnmc.resource": "Delete CiscoVNMC resource",
797797
"label.delete.condition": "Delete condition",
798+
"label.delete.confirmation": "Enter the exact resource name to proceed with deletion",
798799
"label.delete.custom.action": "Delete Custom Action",
799800
"label.delete.dedicated.vlan.range": "Deleted dedicated VLAN/VNI range.",
800801
"label.delete.domain": "Delete domain",

ui/src/config/section/project.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default {
162162
},
163163
groupAction: true,
164164
popup: true,
165+
requireNameConfirmation: true,
165166
groupMap: (selection, values) => { return selection.map(x => { return { id: x, cleanup: values.cleanup || null } }) },
166167
args: (record, store) => {
167168
const fields = []

ui/src/views/AutogenView.vue

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
:footer="null"
196196
style="top: 20px;"
197197
:width="modalWidth"
198-
:ok-button-props="getOkProps()"
198+
:ok-button-props="okButtonProps"
199199
:cancel-button-props="getCancelProps()"
200200
:confirmLoading="actionLoading"
201201
@cancel="cancelAction"
@@ -270,8 +270,18 @@
270270
</a-table>
271271
</div>
272272
<br v-if="currentAction.paramFields.length > 0" />
273-
</span>
274-
<a-form
273+
</span>
274+
<div v-if="currentAction.requireNameConfirmation && !(currentAction.groupAction && selectedRowKeys.length > 0)" style="margin-bottom: 5px">
275+
<a-form-item>
276+
<a-input v-model:value="actionConfirmText" :placeholder="resource.name" />
277+
</a-form-item>
278+
<a-alert type="info">
279+
<template #message>
280+
<div v-html="$t('label.delete.confirmation')"></div>
281+
</template>
282+
</a-alert>
283+
</div>
284+
<a-form
275285
:ref="formRef"
276286
:model="form"
277287
:rules="rules"
@@ -526,6 +536,7 @@
526536
type="primary"
527537
@click="handleSubmit"
528538
ref="submit"
539+
:disabled="isSubmitDisabled"
529540
>{{ $t('label.ok') }}</a-button>
530541
</div>
531542
</a-form>
@@ -686,6 +697,7 @@ export default {
686697
confirmDirty: false,
687698
firstIndex: 0,
688699
modalWidth: '30vw',
700+
actionConfirmText: '',
689701
promises: []
690702
}
691703
},
@@ -893,6 +905,22 @@ export default {
893905
return 'active'
894906
}
895907
return 'self'
908+
},
909+
okButtonProps () {
910+
if (this.currentAction?.requireNameConfirmation && !(this.currentAction.groupAction && this.selectedRowKeys.length > 0)) {
911+
const isConfirmed = this.actionConfirmText.trim() === this.resource?.name?.trim()
912+
return { type: 'primary', disabled: !isConfirmed }
913+
}
914+
if (this.selectedRowKeys.length > 0 && this.currentAction?.groupAction) {
915+
return {}
916+
}
917+
return { type: 'primary' }
918+
},
919+
isSubmitDisabled () {
920+
if (this.currentAction?.requireNameConfirmation && !(this.currentAction.groupAction && this.selectedRowKeys.length > 0)) {
921+
return this.actionConfirmText.trim() !== this.resource?.name?.trim()
922+
}
923+
return false
896924
}
897925
},
898926
methods: {
@@ -902,12 +930,6 @@ export default {
902930
}
903931
return 'inline-flex'
904932
},
905-
getOkProps () {
906-
if (this.selectedRowKeys.length > 0 && this.currentAction?.groupAction) {
907-
} else {
908-
return { props: { type: 'primary' } }
909-
}
910-
},
911933
getCancelProps () {
912934
if (this.selectedRowKeys.length > 0 && this.currentAction?.groupAction) {
913935
return { props: { type: 'primary' } }
@@ -1303,6 +1325,7 @@ export default {
13031325
this.actionLoading = false
13041326
this.showAction = false
13051327
this.currentAction = {}
1328+
this.actionConfirmText = ''
13061329
},
13071330
cancelAction () {
13081331
eventBus.emit('action-closing', { action: this.currentAction })
@@ -1360,6 +1383,7 @@ export default {
13601383
this.currentAction = action
13611384
this.currentAction.params = store.getters.apis[this.currentAction.api].params
13621385
this.resource = action.resource
1386+
this.actionConfirmText = ''
13631387
this.$emit('change-resource', this.resource)
13641388
var paramFields = this.currentAction.params
13651389
paramFields.sort(function (a, b) {
@@ -1642,6 +1666,12 @@ export default {
16421666
},
16431667
handleSubmit (e) {
16441668
if (this.actionLoading) return
1669+
1670+
if (this.currentAction?.requireNameConfirmation && !(this.currentAction.groupAction && this.selectedRowKeys.length > 0)) {
1671+
if (this.actionConfirmText.trim() !== this.resource?.name?.trim()) {
1672+
return
1673+
}
1674+
}
16451675
this.promises = []
16461676
if (!this.dataView && this.currentAction.groupAction && this.selectedRowKeys.length > 0) {
16471677
if (this.selectedRowKeys.length > 0) {

0 commit comments

Comments
 (0)