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

Refactor modal and safe_confirm #2

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/ui/public/autoload/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import 'ui/parse_query';
import 'ui/persisted_log';
import 'ui/private';
import 'ui/promises';
import 'ui/dialogues';
import 'ui/modals';
import 'ui/safe_confirm';
import 'ui/state_management/app_state';
import 'ui/state_management/global_state';
import 'ui/storage';
Expand Down
6 changes: 0 additions & 6 deletions src/ui/public/dialogues/confirm_dialogue_container.html

This file was deleted.

15 changes: 0 additions & 15 deletions src/ui/public/dialogues/directives/confirm_dialogue.html

This file was deleted.

18 changes: 0 additions & 18 deletions src/ui/public/dialogues/directives/confirm_dialogue.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/ui/public/dialogues/modal_dialogue.factory.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/ui/public/dialogues/modal_dialogue.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/ui/public/dialogues/safe_confirm.factory.js

This file was deleted.

34 changes: 0 additions & 34 deletions src/ui/public/dialogues/safe_confirm.js

This file was deleted.

38 changes: 38 additions & 0 deletions src/ui/public/modals/confirm_modal.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { noop } from 'lodash';
import uiModules from 'ui/modules';
import template from './confirm_modal.html';
import { Popover } from './popover';

const module = uiModules.get('kibana');

module.factory('confirmModal', function ($rootScope, $compile) {
let modalPopover;

return function confirmModal(message, onConfirm = noop, onCancel = noop, confirmButtonText = 'Confirm', cancelButtonText = 'Cancel') {

if (modalPopover) throw new Error('Ah ah ah, only one modal, buddy!');

const confirmScope = $rootScope.$new();

confirmScope.message = message;
confirmScope.confirmButtonText = confirmButtonText;
confirmScope.cancelButtonText = cancelButtonText;
confirmScope.onConfirm = () => {
destroy();
onConfirm();
};
confirmScope.onCancel = () => {
destroy();
onCancel();
};

const modalInstance = $compile(template)(confirmScope);
modalPopover = new Popover(modalInstance);

function destroy() {
modalPopover.destroy();
modalPopover = undefined;
confirmScope.$destroy();
}
};
});
23 changes: 23 additions & 0 deletions src/ui/public/modals/confirm_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="disable-app-layer">
<div class="confirm-dialogue" data-test-subj="confirm-dialog">
<div class="confirm-dialogue__message">
{{message}}
</div>
<div class="confirm-dialogue__actions">
<button
class="kuiButton kuiButton--primary"
data-test-subj="confirm-dialog-okay-button"
ng-click="onConfirm()"
>
{{confirmButtonText}}
</button>
<button
class="kuiButton kuiButton--basic"
data-test-subj="confirm-dialog-cancel-button"
ng-click="onCancel()"
>
{{cancelButtonText}}
</button>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions src/ui/public/modals/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './confirm_modal.factory';
17 changes: 17 additions & 0 deletions src/ui/public/modals/popover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import angular from 'angular';

export class Popover {
constructor(element) {
this.element = element;
// document.body.appendChild(this.element);
angular.element(document.body).append(this.element);
}

/**
* Removes the element from the dom.
*/
destroy() {
// document.body.removeChild(this.element);
this.element.remove();
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions src/ui/public/safe_confirm/safe_confirm.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import uiModules from 'ui/modules';
import 'ui/modals';

const module = uiModules.get('kibana');

module.factory('safeConfirm', function ($timeout, Promise, confirmModal) {
return (message) => $timeout(() => {
return new Promise((resolve, reject) => {
confirmModal(message, resolve, reject, 'Yes', 'No');
});
});
});