toast: add remove method to clear a single message (#4101)
Co-authored-by: Clément Bernard <cbernard@groupeisagri.com>pull/4570/head
parent
4bcb9bd14f
commit
cee96884f9
|
@ -43,6 +43,7 @@ export default {
|
||||||
styleElement: null,
|
styleElement: null,
|
||||||
mounted() {
|
mounted() {
|
||||||
ToastEventBus.on('add', this.onAdd);
|
ToastEventBus.on('add', this.onAdd);
|
||||||
|
ToastEventBus.on('remove', this.onRemove);
|
||||||
ToastEventBus.on('remove-group', this.onRemoveGroup);
|
ToastEventBus.on('remove-group', this.onRemoveGroup);
|
||||||
ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups);
|
ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups);
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
ToastEventBus.off('add', this.onAdd);
|
ToastEventBus.off('add', this.onAdd);
|
||||||
|
ToastEventBus.off('remove', this.onRemove);
|
||||||
ToastEventBus.off('remove-group', this.onRemoveGroup);
|
ToastEventBus.off('remove-group', this.onRemoveGroup);
|
||||||
ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups);
|
ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups);
|
||||||
},
|
},
|
||||||
|
@ -87,6 +89,9 @@ export default {
|
||||||
this.add(message);
|
this.add(message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onRemove(message) {
|
||||||
|
this.remove({ message, type: 'close' });
|
||||||
|
},
|
||||||
onRemoveGroup(group) {
|
onRemoveGroup(group) {
|
||||||
if (this.group === group) {
|
if (this.group === group) {
|
||||||
this.messages = [];
|
this.messages = [];
|
||||||
|
|
|
@ -23,6 +23,11 @@ export interface ToastServiceMethods {
|
||||||
* @param {ToastMessageOptions} message - Message instance.
|
* @param {ToastMessageOptions} message - Message instance.
|
||||||
*/
|
*/
|
||||||
add(message: ToastMessageOptions): void;
|
add(message: ToastMessageOptions): void;
|
||||||
|
/**
|
||||||
|
* Clears the message.
|
||||||
|
* @param {ToastMessageOptions} message - Message instance.
|
||||||
|
*/
|
||||||
|
remove(message: ToastMessageOptions): void;
|
||||||
/**
|
/**
|
||||||
* Clears the messages that belongs to the group.
|
* Clears the messages that belongs to the group.
|
||||||
* @param {string} group - Name of the message group.
|
* @param {string} group - Name of the message group.
|
||||||
|
|
|
@ -7,6 +7,9 @@ export default {
|
||||||
add: (message) => {
|
add: (message) => {
|
||||||
ToastEventBus.emit('add', message);
|
ToastEventBus.emit('add', message);
|
||||||
},
|
},
|
||||||
|
remove: (message) => {
|
||||||
|
ToastEventBus.emit('remove', message);
|
||||||
|
},
|
||||||
removeGroup: (group) => {
|
removeGroup: (group) => {
|
||||||
ToastEventBus.emit('remove-group', group);
|
ToastEventBus.emit('remove-group', group);
|
||||||
},
|
},
|
||||||
|
|
|
@ -49887,6 +49887,19 @@
|
||||||
"returnType": "void",
|
"returnType": "void",
|
||||||
"description": "Displays the message in a suitable Toast component."
|
"description": "Displays the message in a suitable Toast component."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "remove",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "message",
|
||||||
|
"optional": false,
|
||||||
|
"type": "ToastMessageOptions",
|
||||||
|
"description": "Message instance."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"returnType": "void",
|
||||||
|
"description": "Clears the message."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "removeGroup",
|
"name": "removeGroup",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
|
|
Loading…
Reference in New Issue