From d0beeb7e142197152925b9c257a2e4f402ac9fb2 Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Tue, 3 Apr 2018 17:40:27 +0900 Subject: [PATCH] Pass whole selected entity to deleteEntity callback For now, delete-modal service passes only ID to deleteEntity callback. Some plugins need other parameters to delete entity. So this patch passes whole selected entity to callback as second argument. Change-Id: I395470110a5f03ebb08a043ca433b16b999dad3f Needed-By: Ic5aba9b2e953cde7950ae7656cd5a3fee3f4a55c Closes-Bug: #1761074 --- .../framework/widgets/modal/delete-modal.service.js | 3 ++- .../widgets/modal/delete-modal.service.spec.js | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/horizon/static/framework/widgets/modal/delete-modal.service.js b/horizon/static/framework/widgets/modal/delete-modal.service.js index a13ed5cdb0..59a6989e46 100644 --- a/horizon/static/framework/widgets/modal/delete-modal.service.js +++ b/horizon/static/framework/widgets/modal/delete-modal.service.js @@ -71,6 +71,7 @@ * @param {function} context.deleteEntity * The function that should be called to delete each entity. * The first argument is the id of the Entity to delete. + * The second argument is the Entity itself. * Note: This callback might need to suppress errors on the * alert service. * @@ -100,7 +101,7 @@ } function deleteEntityPromise(entity) { - return {promise: context.deleteEntity(entity.id), context: entity}; + return {promise: context.deleteEntity(entity.id, entity), context: entity}; } function notify(result) { diff --git a/horizon/static/framework/widgets/modal/delete-modal.service.spec.js b/horizon/static/framework/widgets/modal/delete-modal.service.spec.js index b660b53a78..e968a0d541 100644 --- a/horizon/static/framework/widgets/modal/delete-modal.service.spec.js +++ b/horizon/static/framework/widgets/modal/delete-modal.service.spec.js @@ -117,8 +117,8 @@ $scope.$apply(); - expect(entityAPI.deleteEntity).toHaveBeenCalledWith('1'); - expect(entityAPI.deleteEntity).toHaveBeenCalledWith('2'); + expect(entityAPI.deleteEntity).toHaveBeenCalledWith('1', {name: 'entity1', id: '1'}); + expect(entityAPI.deleteEntity).toHaveBeenCalledWith('2', {name: 'entity2', id: '2'}); expect(toastService.add).toHaveBeenCalledWith('success', 'Deleted : entity1, entity2.'); expect($scope.$emit).toHaveBeenCalledWith('custom_delete_event_passed', [ '1', '2' ]); }); @@ -134,7 +134,7 @@ $scope.$apply(); - expect(entityAPI.deleteEntity).toHaveBeenCalledWith('bad'); + expect(entityAPI.deleteEntity).toHaveBeenCalledWith('bad', {name: 'entity1', id: 'bad'}); expect(toastService.add).toHaveBeenCalledWith('error', 'Unable to delete: entity1.'); expect($scope.$emit).toHaveBeenCalledWith('custom_delete_event_failed', ['bad']); }); @@ -153,8 +153,8 @@ $scope.$apply(); - expect(entityAPI.deleteEntity).toHaveBeenCalledWith('bad'); - expect(entityAPI.deleteEntity).toHaveBeenCalledWith('1'); + expect(entityAPI.deleteEntity).toHaveBeenCalledWith('bad', {name: 'bad_entity', id: 'bad'}); + expect(entityAPI.deleteEntity).toHaveBeenCalledWith('1', {name: 'entity2', id: '1'}); expect(toastService.add).toHaveBeenCalledWith('success', 'Deleted : entity2.'); expect(toastService.add).toHaveBeenCalledWith('error', 'Unable to delete: bad_entity.'); expect($scope.$emit).toHaveBeenCalledWith('custom_delete_event_passed', ['1']);