From 154a573ed76992ec36b8bfb9d78987e9f4051865 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Tue, 30 Apr 2024 12:06:37 +0200 Subject: [PATCH] `panel.notification.info(message)` --- .../internals/panel/notification/index.vue | 13 ++++++++++ panel/src/panel/modal.test.js | 2 +- panel/src/panel/notification.js | 26 +++++++++++++++---- panel/src/panel/notification.test.js | 8 ++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/panel/lab/internals/panel/notification/index.vue b/panel/lab/internals/panel/notification/index.vue index 931725e871..4e109f7630 100644 --- a/panel/lab/internals/panel/notification/index.vue +++ b/panel/lab/internals/panel/notification/index.vue @@ -55,6 +55,19 @@ /> + + + window.panel.notification.info(notification); +

Displays an info notification

+ +
+

diff --git a/panel/src/panel/modal.test.js b/panel/src/panel/modal.test.js index 7a8a50e5e5..f2eb71a252 100644 --- a/panel/src/panel/modal.test.js +++ b/panel/src/panel/modal.test.js @@ -147,8 +147,8 @@ describe.concurrent("panel/modal.js", () => { message: "Test" }); - expect(panel.notification.type).toStrictEqual("success"); expect(panel.notification.message).toStrictEqual("Test"); + expect(panel.notification.theme).toStrictEqual("positive"); }); it("should emit panel events after submit", async () => { diff --git a/panel/src/panel/notification.js b/panel/src/panel/notification.js index a118491a4f..b99811626b 100644 --- a/panel/src/panel/notification.js +++ b/panel/src/panel/notification.js @@ -118,6 +118,26 @@ export default (panel = {}) => { }); }, + /** + * Shortcut to create an info + * notification. You can pass a simple + * string or a state object. + * + * @param {Object|String} info + * @returns {Object} The notification state + */ + info(info = {}) { + if (typeof info === "string") { + info = { message: info }; + } + + return this.open({ + icon: "info", + theme: "info", + ...info + }); + }, + /** * Checks if the notification is a fatal * error. Those are displayed in the @@ -204,11 +224,7 @@ export default (panel = {}) => { * @param {Object|String} success * @returns {Object} The notification state */ - success(success) { - if (!success) { - success = {}; - } - + success(success = {}) { if (typeof success === "string") { success = { message: success }; } diff --git a/panel/src/panel/notification.test.js b/panel/src/panel/notification.test.js index d286073d20..d53d91c1a1 100644 --- a/panel/src/panel/notification.test.js +++ b/panel/src/panel/notification.test.js @@ -100,12 +100,16 @@ describe("panel.notification", () => { const notification = Notification(panel); notification.success("Test"); - expect(notification.theme).toStrictEqual("positive"); - notification.error("Test"); + notification.info("Test"); + expect(notification.theme).toStrictEqual("info"); + notification.error("Test"); expect(notification.theme).toStrictEqual("negative"); + + notification.open({ theme: "love" }); + expect(notification.theme).toStrictEqual("love"); }); it("should set a timer for success notifications", async () => {