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

Use toasts from @nextcloud/dialogs, deprecate OCP.Toast and fix usages #19346

Merged
merged 3 commits into from
Apr 6, 2020
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
6 changes: 3 additions & 3 deletions apps/files/js/dist/files-app-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files/js/dist/files-app-settings.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions apps/files/js/dist/personal-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files/js/dist/personal-settings.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions apps/files/js/dist/sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files/js/dist/sidebar.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/files/src/components/TransferOwnershipDialogue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import axios from '@nextcloud/axios'
import debounce from 'debounce'
import { generateOcsUrl } from '@nextcloud/router'
import { getFilePickerBuilder } from '@nextcloud/dialogs'
import { getFilePickerBuilder, showSuccess } from '@nextcloud/dialogs'
import { Multiselect } from '@nextcloud/vue/dist/Components/Multiselect'
import Vue from 'vue'

Expand Down Expand Up @@ -210,7 +210,7 @@ export default {

this.directory = undefined
this.selectedUser = null
OCP.Toast.success(t('files', 'Ownership transfer request sent'))
showSuccess(t('files', 'Ownership transfer request sent'))
})
.catch(error => {
logger.error('Could not send ownership transfer request', { error })
Expand Down
48 changes: 28 additions & 20 deletions apps/workflowengine/js/workflowengine.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/workflowengine/js/workflowengine.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/workflowengine/src/components/Event.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<script>
import { Multiselect } from '@nextcloud/vue/dist/Components/Multiselect'
import { showWarning } from '@nextcloud/dialogs'

export default {
name: 'Event',
Expand Down Expand Up @@ -57,7 +58,7 @@ export default {
methods: {
updateEvent(events) {
if (events.length === 0) {
window.OCP.Toast.warning(t('workflowengine', 'At least one event must be selected'))
showWarning(t('workflowengine', 'At least one event must be selected'))
return
}
const existingEntity = this.rule.entity
Expand Down
18 changes: 9 additions & 9 deletions core/js/dist/install.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/install.js.map

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions core/js/dist/login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/login.js.map

Large diffs are not rendered by default.

93 changes: 57 additions & 36 deletions core/js/dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/main.js.map

Large diffs are not rendered by default.

40 changes: 24 additions & 16 deletions core/js/dist/maintenance.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/maintenance.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/js/dist/recommendedapps.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/js/dist/recommendedapps.js.map

Large diffs are not rendered by default.

61 changes: 24 additions & 37 deletions core/js/tests/specs/coreSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ describe('Core base tests', function() {
});
});
describe('Notifications', function() {
var showSpy;
var showHtmlSpy;
var clock;

Expand All @@ -694,118 +693,106 @@ describe('Core base tests', function() {

beforeEach(function() {
clock = sinon.useFakeTimers();
showSpy = sinon.spy(OCP.Toast, 'message');

$('#testArea').append('<div id="content"></div>');
});
afterEach(function() {
showSpy.restore();
// jump past animations
clock.tick(10000);
clock.restore();
$('#testArea .toastify').remove();
$('body .toastify').remove();
});
describe('showTemporary', function() {
it('shows a plain text notification with default timeout', function() {
OC.Notification.showTemporary('My notification test');

expect(showSpy.calledOnce).toEqual(true);
expect(showSpy.firstCall.args[0]).toEqual('My notification test');
//expect(showSpy.firstCall.args[1]).toEqual({isHTML: false, timeout: 7});

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);
expect(getNotificationText($row)).toEqual('My notification test');
});
it('shows a HTML notification with default timeout', function() {
OC.Notification.showTemporary('<a>My notification test</a>', { isHTML: true });

expect(showSpy.calledOnce).toEqual(true);
expect(showSpy.firstCall.args[0]).toEqual('<a>My notification test</a>');
expect(showSpy.firstCall.args[1].isHTML).toEqual(true)

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);
expect(getNotificationText($row)).toEqual('<a>My notification test</a>');
});
it('hides itself after 7 seconds', function() {
OC.Notification.showTemporary('');

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

// travel in time +7000 milliseconds
clock.tick(7500);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);
});
it('hides itself after a given time', function() {
OC.Notification.showTemporary('', {timeout: 10});

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

// travel in time +7000 milliseconds
clock.tick(7500);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(1);

// travel in time another 4000 milliseconds
clock.tick(4000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);
});
});
describe('show', function() {
it('hides itself after a given time', function() {
OC.Notification.show('', {timeout: 10});

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

clock.tick(11500);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);
});
it('does not hide itself if no timeout given to show', function() {
OC.Notification.show('');

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

// travel in time +1000 seconds
clock.tick(1000000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(1);
});
});
describe('showHtml', function() {
it('hides itself after a given time', function() {
OC.Notification.showHtml('<p></p>', {timeout: 10});

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

clock.tick(11500);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);
});
it('does not hide itself if no timeout given to show', function() {
OC.Notification.showHtml('<p></p>');

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

// travel in time +1000 seconds
clock.tick(1000000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(1);
});
});
Expand All @@ -815,15 +802,15 @@ describe('Core base tests', function() {

var notification = OC.Notification.showTemporary('');

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

OC.Notification.hide(notification, hideCallback);

// Give time to the hide animation to finish
clock.tick(1000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);

expect(hideCallback.calledOnce).toEqual(true);
Expand All @@ -833,15 +820,15 @@ describe('Core base tests', function() {

var notification = OC.Notification.show('', {timeout: 10});

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

OC.Notification.hide(notification, hideCallback);

// Give time to the hide animation to finish
clock.tick(1000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);

expect(hideCallback.calledOnce).toEqual(true);
Expand All @@ -851,15 +838,15 @@ describe('Core base tests', function() {

var notification = OC.Notification.show('');

var $row = $('#testArea .toastify');
var $row = $('body .toastify');
expect($row.length).toEqual(1);

OC.Notification.hide(notification, hideCallback);

// Give time to the hide animation to finish
clock.tick(1000);

$row = $('#testArea .toastify');
$row = $('body .toastify');
expect($row.length).toEqual(0);

expect(hideCallback.calledOnce).toEqual(true);
Expand All @@ -870,7 +857,7 @@ describe('Core base tests', function() {
var $row2 = OC.Notification.showTemporary('Two', {timeout: 2});
var $row3 = OC.Notification.showTemporary('Three');

var $el = $('#testArea');
var $el = $('body');
var $rows = $el.find('.toastify');
expect($rows.length).toEqual(3);

Expand All @@ -890,7 +877,7 @@ describe('Core base tests', function() {
var $row1 = OC.Notification.show('One');
var $row2 = OC.Notification.show('Two');

var $el = $('#testArea');
var $el = $('body');
var $rows = $el.find('.toastify');
expect($rows.length).toEqual(2);

Expand Down
35 changes: 22 additions & 13 deletions core/src/OC/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

import _ from 'underscore'
import $ from 'jquery'
import { showMessage } from '@nextcloud/dialogs'

/**
* @todo Write documentation
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package instead
* @namespace OC.Notification
*/
export default {
Expand All @@ -35,7 +36,7 @@ export default {

/**
* @param {Function} callback callback function
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
setDefault: function(callback) {
this.getDefaultNotificationFunction = callback
Expand All @@ -49,7 +50,7 @@ export default {
*
* @param {jQuery} [$row] notification row
* @param {Function} [callback] callback
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
hide: function($row, callback) {
if (_.isFunction($row)) {
Expand All @@ -65,7 +66,11 @@ export default {

// remove the row directly
$row.each(function() {
$(this)[0].toastify.hideToast()
if ($(this)[0].toastify) {
$(this)[0].toastify.hideToast()
} else {
console.error('cannot hide toast because object is not set')
}
if (this === this.updatableNotification) {
this.updatableNotification = null
}
Expand All @@ -88,13 +93,14 @@ export default {
* @param {string} [options.type] notification type
* @param {int} [options.timeout=0] timeout value, defaults to 0 (permanent)
* @returns {jQuery} jQuery element for notification row
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
showHtml: function(html, options) {
options = options || {}
options.isHTML = true
options.timeout = (!options.timeout) ? -1 : options.timeout
const toast = window.OCP.Toast.message(html, options)
const toast = showMessage(html, options)
toast.toastElement.toastify = toast
return $(toast.toastElement)
},

Expand All @@ -106,12 +112,13 @@ export default {
* @param {string} [options.type] notification type
* @param {int} [options.timeout=0] timeout value, defaults to 0 (permanent)
* @returns {jQuery} jQuery element for notification row
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
show: function(text, options) {
options = options || {}
options.timeout = (!options.timeout) ? -1 : options.timeout
const toast = window.OCP.Toast.message(text, options)
const toast = showMessage(text, options)
toast.toastElement.toastify = toast
return $(toast.toastElement)
},

Expand All @@ -120,13 +127,14 @@ export default {
*
* @param {string} text Message to display
* @returns {jQuery} JQuery element for notificaiton row
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
showUpdate: function(text) {
if (this.updatableNotification) {
this.updatableNotification.hideToast()
}
this.updatableNotification = OCP.Toast.message(text, { timeout: -1 })
this.updatableNotification = showMessage(text, { timeout: -1 })
this.updatableNotification.toastElement.toastify = this.updatableNotification
return $(this.updatableNotification.toastElement)
},

Expand All @@ -140,19 +148,20 @@ export default {
* @param {boolean} [options.isHTML=false] an indicator for HTML notifications (true) or text (false)
* @param {string} [options.type] notification type
* @returns {JQuery<any>} the toast element
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
showTemporary: function(text, options) {
options = options || {}
options.timeout = options.timeout || 7
const toast = window.OCP.Toast.message(text, options)
const toast = showMessage(text, options)
toast.toastElement.toastify = toast
return $(toast.toastElement)
},

/**
* Returns whether a notification is hidden.
* @returns {boolean}
* @deprecated 17.0.0 use OCP.Toast
* @deprecated 17.0.0 use the `@nextcloud/dialogs` package
*/
isHidden: function() {
return !$('#content').find('.toastify').length
Expand Down
8 changes: 4 additions & 4 deletions core/src/OCP/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/**
*
*/
import * as AppConfig from './appconfig'
import * as Comments from './comments'
import Loader from './loader'
import { loadState } from '@nextcloud/initial-state'
import Collaboration from './collaboration'
import Toast from './toast'
import * as WhatsNew from './whatsnew'
import Toast from './toast'

/** @namespace OCP */
export default {
Expand All @@ -21,6 +18,9 @@ export default {
loadState,
},
Loader,
/**
* @deprecated 19.0.0 use the `@nextcloud/dialogs` package instead
*/
Toast,
WhatsNew,
}
Loading