From 8926b8828f5b4da3defa0f563e1a92e1fa1005f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 5 Mar 2019 10:31:03 +0100 Subject: [PATCH] add support for notifications of type 'warning' --- web/static/src/scss/app.scss | 9 ++++++++- web/static/src/ts/discuss/discuss.ts | 9 +++++++++ web/static/src/ts/ui/notification.ts | 4 ++++ web/static/src/xml/templates.xml | 4 +++- .../ui/__snapshots__/notification.test.ts.snap | 18 ++++++++++++++++-- .../tests/ui/__snapshots__/root.test.ts.snap | 2 ++ web/static/tests/ui/notification.test.ts | 11 +++++++++++ 7 files changed, 53 insertions(+), 4 deletions(-) diff --git a/web/static/src/scss/app.scss b/web/static/src/scss/app.scss index 7b8ec843..e1b08497 100644 --- a/web/static/src/scss/app.scss +++ b/web/static/src/scss/app.scss @@ -1,6 +1,5 @@ $navbar-height: 46px; $main-color: #875a7b; -$o-notification-info-bg-color: #fcfbea; $o-main-text-color: #666666; html { @@ -139,6 +138,9 @@ body { } /***** Notifications *****/ +$o-notification-info-bg-color: #fcfbea; +$o-notification-error-bg-color: #f16567; + .o_notification_container { position: absolute; width: 300px; @@ -153,6 +155,11 @@ body { box-shadow: 0px 0px 5px 1px $o-main-text-color; position: relative; + &.o_error { + color: white; + background-color: $o-notification-error-bg-color; + } + .o_close { position: absolute; top: 5px; diff --git a/web/static/src/ts/discuss/discuss.ts b/web/static/src/ts/discuss/discuss.ts index 741761de..56840789 100644 --- a/web/static/src/ts/discuss/discuss.ts +++ b/web/static/src/ts/discuss/discuss.ts @@ -52,6 +52,15 @@ export class Discuss extends Widget<{}, State> { sticky }); } + + addWarning() { + this.env.addNotification({ + title: "This is a warning", + message: "All your bases are belong to us", + type: "warning", + sticky: true + }); + } } class ColorWidget extends Widget<{ color: "red" | "blue" }, {}> { diff --git a/web/static/src/ts/ui/notification.ts b/web/static/src/ts/ui/notification.ts index ae409a93..2b08cf0c 100644 --- a/web/static/src/ts/ui/notification.ts +++ b/web/static/src/ts/ui/notification.ts @@ -9,4 +9,8 @@ export class Notification extends Widget { ev.preventDefault(); this.env.closeNotification(this.props.id); } + + get icon() { + return this.props.type === "warning" ? "fa-exclamation" : "fa-lightbulb"; + } } diff --git a/web/static/src/xml/templates.xml b/web/static/src/xml/templates.xml index 10e0c2f7..e68d0065 100644 --- a/web/static/src/xml/templates.xml +++ b/web/static/src/xml/templates.xml @@ -61,9 +61,10 @@ -
diff --git a/web/static/tests/ui/notification.test.ts b/web/static/tests/ui/notification.test.ts index 5f41778b..2c70fd15 100644 --- a/web/static/tests/ui/notification.test.ts +++ b/web/static/tests/ui/notification.test.ts @@ -49,6 +49,17 @@ test("can be rendered", async () => { expect(fixture.innerHTML).toMatchSnapshot(); }); +test("can be rendered (type = warning)", async () => { + const notif = makeNotification({ + title: "title", + message: "message", + type: "warning" + }); + const navbar = new Notification(env, notif); + await navbar.mount(fixture); + expect(fixture.innerHTML).toMatchSnapshot(); +}); + test("can be closed by clicking on it (if sticky)", async () => { env.addNotification({ title: "title",