From 142ae322560facd659c2f0d7b00e8d43260ff009 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:08:46 +0200 Subject: [PATCH 1/5] :sparkles: Add better call signature for srepl/notify! fn helper --- backend/src/app/srepl/main.clj | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index 1c4c5430aa..0a5181ffe2 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -190,6 +190,12 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn notify! + "Send flash notifications. + + This method allows send flash notifications to specified target destinations. + The message can be a free text or a preconfigured one. + + The destination can be: all, profile-id, team-id, or a coll of them." [{:keys [::mbus/msgbus ::db/pool]} & {:keys [dest code message level] :or {code :generic level :info} :as params}] @@ -197,10 +203,6 @@ ["invalid level %" level] (contains? #{:success :error :info :warning} level)) - (dm/verify! - ["invalid code: %" code] - (contains? #{:generic :upgrade-version} code)) - (letfn [(send [dest] (l/inf :hint "sending notification" :dest (str dest)) (let [message {:type :notification @@ -226,6 +228,9 @@ (resolve-dest [dest] (cond + (= :all dest) + [uuid/zero] + (uuid? dest) [dest] @@ -241,14 +246,15 @@ (mapcat resolve-dest)) dest) - (and (coll? dest) - (every? coll? dest)) + (and (vector? dest) + (every? vector? dest)) (sequence (comp (map vec) (mapcat resolve-dest)) dest) - (vector? dest) + (and (vector? dest) + (keyword? (first dest))) (let [[op param] dest] (cond (= op :email) From 9e0fb44b3fcbc86d21ee21351732fbf00e9c8fdc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:11:14 +0200 Subject: [PATCH 2/5] :bug: Remove unnecesary delay on hide notification banner --- frontend/src/app/main/data/messages.cljs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/frontend/src/app/main/data/messages.cljs b/frontend/src/app/main/data/messages.cljs index 024fec415a..eb3d48c47b 100644 --- a/frontend/src/app/main/data/messages.cljs +++ b/frontend/src/app/main/data/messages.cljs @@ -15,7 +15,6 @@ (declare hide) (declare show) -(def default-animation-timeout 600) (def default-timeout 7000) (def ^:private @@ -76,14 +75,7 @@ (ptk/reify ::hide ptk/UpdateEvent (update [_ state] - (d/update-when state :message assoc :status :hide)) - - ptk/WatchEvent - (watch [_ _ stream] - (let [stopper (rx/filter (ptk/type? ::show) stream)] - (->> (rx/of #(dissoc % :message)) - (rx/delay default-animation-timeout) - (rx/take-until stopper)))))) + (dissoc state :message)))) (defn hide-tag [tag] From 7e50ab52b9789470e572c5a5d86ed8cff362ecd3 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:11:49 +0200 Subject: [PATCH 3/5] :paperclip: Add minor improvement on notification message validation --- frontend/src/app/main/data/messages.cljs | 57 ++++++++++++------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/frontend/src/app/main/data/messages.cljs b/frontend/src/app/main/data/messages.cljs index eb3d48c47b..b02eb7d75d 100644 --- a/frontend/src/app/main/data/messages.cljs +++ b/frontend/src/app/main/data/messages.cljs @@ -17,39 +17,40 @@ (def default-timeout 7000) -(def ^:private - schema:message - (sm/define - [:map {:title "Message"} - [:type [::sm/one-of #{:success :error :info :warning}]] - [:status {:optional true} - [::sm/one-of #{:visible :hide}]] - [:position {:optional true} - [::sm/one-of #{:fixed :floating :inline}]] - [:notification-type {:optional true} - [::sm/one-of #{:inline :context :toast}]] - [:controls {:optional true} - [::sm/one-of #{:none :close :inline-actions :bottom-actions}]] - [:tag {:optional true} - [:or :string :keyword]] - [:timeout {:optional true} - [:maybe :int]] - [:actions {:optional true} - [:vector - [:map - [:label :string] - [:callback ::sm/fn]]]] - [:links {:optional true} - [:vector - [:map - [:label :string] - [:callback ::sm/fn]]]]])) +(def ^:private schema:message + [:map {:title "Message"} + [:type [::sm/one-of #{:success :error :info :warning}]] + [:status {:optional true} + [::sm/one-of #{:visible :hide}]] + [:position {:optional true} + [::sm/one-of #{:fixed :floating :inline}]] + [:notification-type {:optional true} + [::sm/one-of #{:inline :context :toast}]] + [:controls {:optional true} + [::sm/one-of #{:none :close :inline-actions :bottom-actions}]] + [:tag {:optional true} + [:or :string :keyword]] + [:timeout {:optional true} + [:maybe :int]] + [:actions {:optional true} + [:vector + [:map + [:label :string] + [:callback ::sm/fn]]]] + [:links {:optional true} + [:vector + [:map + [:label :string] + [:callback ::sm/fn]]]]]) + +(def ^:private valid-message? + (sm/validator schema:message)) (defn show [data] (dm/assert! "expected valid message map" - (sm/check! schema:message data)) + (valid-message? data)) (ptk/reify ::show ptk/UpdateEvent From 57c60716f0e555a72d458d13f12ca2a630033313 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:12:36 +0200 Subject: [PATCH 4/5] :sparkles: Add minor improvements to notifications-hub component --- frontend/src/app/main/ui/messages.cljs | 57 ++++++++++--------- .../ui/notifications/toast_notification.cljs | 10 ++-- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/frontend/src/app/main/ui/messages.cljs b/frontend/src/app/main/ui/messages.cljs index 00df9c3f3d..ba40ad1cfa 100644 --- a/frontend/src/app/main/ui/messages.cljs +++ b/frontend/src/app/main/ui/messages.cljs @@ -17,33 +17,38 @@ (mf/defc notifications-hub [] (let [message (mf/deref refs/message) - - on-close #(st/emit! dmsg/hide) - - toast-message {:type (or (:type message) :info) - :links (:links message) - :on-close on-close - :content (:content message)} - - inline-message {:actions (:actions message) - :links (:links message) - :content (:content message)} - - context-message {:type (or (:type message) :info) - :links (:links message) - :content (:content message)} - - is-context-msg (and (nil? (:timeout message)) (nil? (:actions message))) - is-toast-msg (or (= :toast (:notification-type message)) (some? (:timeout message))) - is-inline-msg (or (= :inline (:notification-type message)) (and (some? (:position message)) (= :floating (:position message))))] + on-close (mf/use-fn #(st/emit! dmsg/hide)) + context? (and (nil? (:timeout message)) + (nil? (:actions message))) + inline? (or (= :inline (:notification-type message)) + (= :floating (:position message))) + toast? (or (= :toast (:notification-type message)) + (some? (:timeout message)))] (when message (cond - is-toast-msg - [:& toast-notification toast-message] - is-inline-msg - [:& inline-notification inline-message] - is-context-msg - [:& context-notification context-message] + toast? + [:& toast-notification + {:type (or (:type message) :info) + :links (:links message) + :on-close on-close + :content (:content message)}] + + inline? + [:& inline-notification + {:actions (:actions message) + :links (:links message) + :content (:content message)}] + + context? + [:& context-notification + {:type (or (:type message) :info) + :links (:links message) + :content (:content message)}] + :else - [:& toast-notification toast-message])))) + [:& toast-notification + {:type (or (:type message) :info) + :links (:links message) + :on-close on-close + :content (:content message)}])))) diff --git a/frontend/src/app/main/ui/notifications/toast_notification.cljs b/frontend/src/app/main/ui/notifications/toast_notification.cljs index c4583c9019..639e605c08 100644 --- a/frontend/src/app/main/ui/notifications/toast_notification.cljs +++ b/frontend/src/app/main/ui/notifications/toast_notification.cljs @@ -38,12 +38,10 @@ neutral-icon)) (mf/defc toast-notification - "These are ephemeral elements that disappear when - the close button is pressed, - the page is refreshed, - the page is navigated to another page or - after 7 seconds, which is enough time to be read, - except for error messages that require user interaction." + "These are ephemeral elements that disappear when the close button + is pressed, the page is refreshed, the page is navigated to another + page or after 7 seconds, which is enough time to be read, except for + error messages that require user interaction." {::mf/props :obj} [{:keys [type content on-close links] :as props}] From 975efd80cbc28b11d9c428b1c19a8a540ffaf7e8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 22 Jul 2024 13:13:40 +0200 Subject: [PATCH 5/5] :sparkles: Add maintenance predefined notification --- frontend/src/app/main/data/common.cljs | 14 ++++++++++++++ frontend/translations/en.po | 4 ++++ frontend/translations/es.po | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/frontend/src/app/main/data/common.cljs b/frontend/src/app/main/data/common.cljs index 4bab615e94..839dd5c29e 100644 --- a/frontend/src/app/main/data/common.cljs +++ b/frontend/src/app/main/data/common.cljs @@ -13,6 +13,7 @@ [app.main.data.modal :as modal] [app.main.features :as features] [app.main.repo :as rp] + [app.main.store :as st] [app.util.i18n :refer [tr]] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -58,6 +59,10 @@ [] (.reload js/location)) +(defn hide-notifications! + [] + (st/emit! msg/hide)) + (defn handle-notification [{:keys [message code level] :as params}] (ptk/reify ::show-notification @@ -75,6 +80,15 @@ :actions [{:label "Refresh" :callback force-reload!}] :tag :notification))) + :maintenance + (rx/of (msg/dialog + :content (tr "notifications.by-code.maintenance") + :controls :inline-actions + :type level + :actions [{:label (tr "labels.accept") + :callback hide-notifications!}] + :tag :notification)) + (rx/of (msg/dialog :content message :controls :close diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 7a972067de..cc72e0264a 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -2209,6 +2209,10 @@ msgstr "Update a component in a shared library" msgid "notifications.by-code.upgrade-version" msgstr "A new version is available, please refresh the page" +#: src/app/main/data/common.cljs +msgid "notifications.by-code.maintenance" +msgstr "Maintenance break: we will be down for a short maintenance within 5 minutes." + #: src/app/main/ui/dashboard/team.cljs msgid "notifications.invitation-email-sent" msgstr "Invitation sent successfully" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index 3b9bd101db..b511d8f654 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -2285,6 +2285,10 @@ msgstr "Actualizar un componente en biblioteca" msgid "notifications.by-code.upgrade-version" msgstr "Una nueva versión está disponible, por favor actualiza la página" +#: src/app/main/data/common.cljs +msgid "notifications.by-code.maintenance" +msgstr "Pausa de mantenimiento: en los próximos 5 minutos estaremos fuera de servicio por un breve mantenimiento." + #: src/app/main/ui/dashboard/team.cljs msgid "notifications.invitation-email-sent" msgstr "Invitación enviada con éxito"