Commit 128a04ef authored by Nick Kipling's avatar Nick Kipling Committed by Nathan Friend

Adjustments to event removal and modal description

parent 918e7d43
...@@ -59,14 +59,17 @@ export default { ...@@ -59,14 +59,17 @@ export default {
); );
}, },
}, },
mounted() {
this.$refs.deleteModal.$refs.modal.$on('hide', this.removeModalEvents);
},
methods: { methods: {
...mapActions(['fetchList', 'deleteItem', 'multiDeleteItems']), ...mapActions(['fetchList', 'deleteItem', 'multiDeleteItems']),
setModalDescription(itemsToDeleteLength, itemIndex) { setModalDescription(itemIndex = -1) {
if (itemsToDeleteLength) { if (itemIndex === -1) {
this.modalDescription = sprintf( this.modalDescription = sprintf(
s__(`ContainerRegistry|You are about to delete <b>%{count}</b> images. This will s__(`ContainerRegistry|You are about to delete <b>%{count}</b> images. This will
delete the images and all tags pointing to them.`), delete the images and all tags pointing to them.`),
{ count: itemsToDeleteLength }, { count: this.itemsToBeDeleted.length },
); );
} else { } else {
const { tag } = this.repo.list[itemIndex]; const { tag } = this.repo.list[itemIndex];
...@@ -86,25 +89,26 @@ export default { ...@@ -86,25 +89,26 @@ export default {
}, },
removeModalEvents() { removeModalEvents() {
this.$refs.deleteModal.$refs.modal.$off('ok'); this.$refs.deleteModal.$refs.modal.$off('ok');
this.$refs.deleteModal.$refs.modal.$off('hide');
}, },
deleteSingleItem(index) { deleteSingleItem(index) {
this.setModalDescription(0, index); this.setModalDescription(index);
this.$refs.deleteModal.$refs.modal.$once('ok', () => { this.$refs.deleteModal.$refs.modal.$once('ok', () => {
this.removeModalEvents(); this.removeModalEvents();
this.handleSingleDelete(this.repo.list[index]); this.handleSingleDelete(this.repo.list[index]);
}); });
this.$refs.deleteModal.$refs.modal.$once('hide', this.removeModalEvents);
}, },
deleteMultipleItems() { deleteMultipleItems() {
if (this.itemsToBeDeleted.length === 1) {
this.setModalDescription(this.itemsToBeDeleted[0]);
} else if (this.itemsToBeDeleted.length > 1) {
this.setModalDescription();
}
this.$refs.deleteModal.$refs.modal.$once('ok', () => { this.$refs.deleteModal.$refs.modal.$once('ok', () => {
this.removeModalEvents(); this.removeModalEvents();
this.handleMultipleDelete(); this.handleMultipleDelete();
}); });
this.$refs.deleteModal.$refs.modal.$once('hide', this.removeModalEvents);
}, },
handleSingleDelete(itemToDelete) { handleSingleDelete(itemToDelete) {
this.deleteItem(itemToDelete) this.deleteItem(itemToDelete)
...@@ -144,7 +148,6 @@ export default { ...@@ -144,7 +148,6 @@ export default {
selectAll() { selectAll() {
this.itemsToBeDeleted = this.repo.list.map((x, index) => index); this.itemsToBeDeleted = this.repo.list.map((x, index) => index);
this.selectAllChecked = true; this.selectAllChecked = true;
this.setModalDescription(this.itemsToBeDeleted.length);
}, },
deselectAll() { deselectAll() {
this.itemsToBeDeleted = []; this.itemsToBeDeleted = [];
...@@ -163,12 +166,6 @@ export default { ...@@ -163,12 +166,6 @@ export default {
this.selectAllChecked = true; this.selectAllChecked = true;
} }
} }
if (this.itemsToBeDeleted.length === 1) {
this.setModalDescription(0, this.itemsToBeDeleted[0]);
} else if (this.itemsToBeDeleted.length > 1) {
this.setModalDescription(this.itemsToBeDeleted.length);
}
}, },
}, },
}; };
......
...@@ -177,6 +177,7 @@ describe('table registry', () => { ...@@ -177,6 +177,7 @@ describe('table registry', () => {
it('should show the plural title and image count when deleting more than one image', done => { it('should show the plural title and image count when deleting more than one image', done => {
selectAllCheckboxes(); selectAllCheckboxes();
vm.setModalDescription();
Vue.nextTick(() => { Vue.nextTick(() => {
expect(vm.modalTitle).toBe('Remove images'); expect(vm.modalTitle).toBe('Remove images');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment