Skip to content

Commit

Permalink
Remove showClose and onClose options in confirm modal (elastic#11321)
Browse files Browse the repository at this point in the history
The reason they were added is no longer necessary (something for view
edit mode which didn’t pan out).  It was a point of contention:

See elastic#10104
and
elastic#10069 (review)
for background.

Since it’s no longer needed anyway, and this is going to get moved to
react anyhow, I’m removing the unused functionality.
  • Loading branch information
stacey-gammon committed Apr 19, 2017
1 parent 41303bc commit 0b9b056
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 82 deletions.
66 changes: 1 addition & 65 deletions src/ui/public/modals/__tests__/confirm_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,72 +81,27 @@ describe('ui/modals/confirm_modal', function () {
});
});

describe('x icon', function () {
it('is visible when showClose is true', function () {
const confirmModalOptions = {
confirmButtonText: 'bye',
onConfirm: _.noop,
showClose: true,
title: 'hi'
};
confirmModal('hi', confirmModalOptions);

$rootScope.$digest();
const xIcon = findByDataTestSubj('confirmModalCloseButton');
expect(xIcon.length).to.be(1);
});

it('is not visible when showClose is false', function () {
const confirmModalOptions = {
confirmButtonText: 'bye',
onConfirm: _.noop,
title: 'hi',
showClose: false
};
confirmModal('hi', confirmModalOptions);

$rootScope.$digest();
const xIcon = findByDataTestSubj('confirmModalCloseButton');
expect(xIcon.length).to.be(0);
});
});

describe('callbacks are called:', function () {
const confirmCallback = sinon.spy();
const closeCallback = sinon.spy();
const cancelCallback = sinon.spy();

const confirmModalOptions = {
confirmButtonText: 'bye',
onConfirm: confirmCallback,
onCancel: cancelCallback,
onClose: closeCallback,
title: 'hi',
showClose: true
title: 'hi'
};

beforeEach(() => {
confirmCallback.reset();
closeCallback.reset();
cancelCallback.reset();
});

it('onClose', function () {
confirmModal('hi', confirmModalOptions);
$rootScope.$digest();
findByDataTestSubj('confirmModalCloseButton').click();

expect(closeCallback.called).to.be(true);
expect(confirmCallback.called).to.be(false);
expect(cancelCallback.called).to.be(false);
});

it('onCancel', function () {
confirmModal('hi', confirmModalOptions);
$rootScope.$digest();
findByDataTestSubj('confirmModalCancelButton').click();

expect(closeCallback.called).to.be(false);
expect(confirmCallback.called).to.be(false);
expect(cancelCallback.called).to.be(true);
});
Expand All @@ -156,29 +111,10 @@ describe('ui/modals/confirm_modal', function () {
$rootScope.$digest();
findByDataTestSubj('confirmModalConfirmButton').click();

expect(closeCallback.called).to.be(false);
expect(confirmCallback.called).to.be(true);
expect(cancelCallback.called).to.be(false);
});


it('onClose defaults to onCancel if not specified', function () {
const confirmModalOptions = {
confirmButtonText: 'bye',
onConfirm: confirmCallback,
onCancel: cancelCallback,
title: 'hi',
showClose: true
};

confirmModal('hi', confirmModalOptions);
$rootScope.$digest();
findByDataTestSubj('confirmModalCloseButton').click();

expect(confirmCallback.called).to.be(false);
expect(cancelCallback.called).to.be(true);
});

it('onKeyDown detects ESC and calls onCancel', function () {
const confirmModalOptions = {
confirmButtonText: 'bye',
Expand Down
6 changes: 0 additions & 6 deletions src/ui/public/modals/confirm_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
<div class="kuiModalHeader__title" data-test-subj="confirmModalTitleText">
{{title}}
</div>
<div
ng-if="showClose"
class="kuiModalHeaderCloseButton kuiIcon fa-times"
data-test-subj="confirmModalCloseButton"
ng-click="onClose()"
></div>
</div>
<div class="kuiModalBody">
<div
Expand Down
12 changes: 1 addition & 11 deletions src/ui/public/modals/confirm_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export const ConfirmationButtonTypes = {
* @property {String=} cancelButtonText
* @property {function} onConfirm
* @property {function=} onCancel
* @property {String=} title - If given, shows a title on the confirm modal. A title must be given if
* showClose is true, for aesthetic reasons.
* @property {Boolean=} showClose - If true, shows an [x] icon close button which by default is a noop
* @property {function=} onClose - Custom close button to call if showClose is true. If not supplied
* but showClose is true, the function defaults to onCancel.
* @property {String=} title - If given, shows a title on the confirm modal.
*/

module.factory('confirmModal', function ($rootScope, $compile) {
Expand All @@ -36,14 +32,9 @@ module.factory('confirmModal', function ($rootScope, $compile) {
const defaultOptions = {
onCancel: noop,
cancelButtonText: 'Cancel',
showClose: false,
defaultFocusedButton: ConfirmationButtonTypes.CONFIRM
};

if (customOptions.showClose === true && !customOptions.title) {
throw new Error('A title must be supplied when a close icon is shown');
}

if (!customOptions.confirmButtonText || !customOptions.onConfirm) {
throw new Error('Please specify confirmation button text and onConfirm action');
}
Expand All @@ -60,7 +51,6 @@ module.factory('confirmModal', function ($rootScope, $compile) {
confirmScope.confirmButtonText = options.confirmButtonText;
confirmScope.cancelButtonText = options.cancelButtonText;
confirmScope.title = options.title;
confirmScope.showClose = options.showClose;
confirmScope.onConfirm = () => {
destroy();
options.onConfirm();
Expand Down

0 comments on commit 0b9b056

Please sign in to comment.