Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove showClose and onClose options in confirm modal #11321

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 1 addition & 65 deletions src/ui/public/modals/__tests__/confirm_modal.js
Original file line number Diff line number Diff line change
@@ -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);
});
@@ -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',
6 changes: 0 additions & 6 deletions src/ui/public/modals/confirm_modal.html
Original file line number Diff line number Diff line change
@@ -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
12 changes: 1 addition & 11 deletions src/ui/public/modals/confirm_modal.js
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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');
}
@@ -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();