diff --git a/frontend/src/app/main/data/comments.cljs b/frontend/src/app/main/data/comments.cljs index a69d759272..0922eb24d7 100644 --- a/frontend/src/app/main/data/comments.cljs +++ b/frontend/src/app/main/data/comments.cljs @@ -19,6 +19,7 @@ [app.main.data.team :as dtm] [app.main.repo :as rp] [app.util.i18n :as i18n :refer [tr]] + [app.util.storage :as storage] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -531,6 +532,35 @@ (update [_ state] (update state :comments-local dissoc :expanded)))) +(def ^:private hide-resolved-comments-storage-key + :app.main.data.comments/hide-resolved-comments?) + +(defn- load-hide-resolved-comments? + [] + (= true (get @storage/user hide-resolved-comments-storage-key))) + +(defn- persist-hide-resolved-comments! + [hide?] + (swap! storage/user assoc hide-resolved-comments-storage-key hide?)) + +(defn merge-persisted-filters + "Merge persisted hide-resolved preference into comments local state." + [local] + (let [local (or local {})] + (if (contains? local :show) + local + (assoc local :show (if (load-hide-resolved-comments?) + :pending + :all))))) + +(defn initialize-comments-filters + "Load persisted comment filter preferences into `:comments-local`." + [] + (ptk/reify ::initialize-comments-filters + ptk/UpdateEvent + (update [_ state] + (update state :comments-local merge-persisted-filters)))) + (defn update-filters [{:keys [mode show list] :as params}] (ptk/reify ::update-filters @@ -546,7 +576,12 @@ (assoc :show show) (some? list) - (assoc :list list))))))) + (assoc :list list))))) + + ptk/EffectEvent + (effect [_ _ _] + (when (some? show) + (persist-hide-resolved-comments! (= :pending show)))))) (defn update-options [params] diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index 87b9c1007b..424e9cca64 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -77,7 +77,8 @@ (if (nil? lstate) default-local-state lstate))) - (assoc-in [:viewer-local :share-id] share-id))) + (assoc-in [:viewer-local :share-id] share-id) + (update :comments-local dcmt/merge-persisted-filters))) ptk/WatchEvent (watch [_ state _] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index fb6245c31c..fd1c82e47b 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -345,7 +345,8 @@ (assoc :recent-colors (:recent-colors storage/user)) (assoc :recent-fonts (:recent-fonts storage/user)) (assoc :current-file-id file-id) - (assoc :workspace-presence {}))) + (assoc :workspace-presence {}) + (update :comments-local dcmt/merge-persisted-filters))) ptk/WatchEvent (watch [_ state stream] diff --git a/frontend/src/app/main/ui/viewer/comments.cljs b/frontend/src/app/main/ui/viewer/comments.cljs index e08d50cb5a..cbfd533d2b 100644 --- a/frontend/src/app/main/ui/viewer/comments.cljs +++ b/frontend/src/app/main/ui/viewer/comments.cljs @@ -95,6 +95,16 @@ [:span {:class (stl/css :icon)} deprecated-icon/tick])] + [:li {:class (stl/css-case + :dropdown-element true + :selected (= :mentions cmode)) + :data-value "mentions" + :on-click update-mode} + [:span {:class (stl/css :label)} (tr "labels.show-mentions")] + (when (= :mentions cmode) + [:span {:class (stl/css :icon)} + deprecated-icon/tick])] + [:li {:class (stl/css :separator)}] [:li {:class (stl/css-case diff --git a/frontend/src/app/main/ui/viewer/comments.scss b/frontend/src/app/main/ui/viewer/comments.scss index 68169126f5..c413974c73 100644 --- a/frontend/src/app/main/ui/viewer/comments.scss +++ b/frontend/src/app/main/ui/viewer/comments.scss @@ -4,6 +4,7 @@ // // Copyright (c) KALEIDOS INC Sucursal en España SL +@use "ds/_borders.scss" as *; @use "refactor/common-refactor.scss" as deprecated; // COMMENT DROPDOWN ON HEADER @@ -92,7 +93,12 @@ } .separator { - height: deprecated.$s-8; + position: relative; + block-size: var(--sp-xs); + inline-size: calc(100% + var(--sp-s)); + border-top: $b-1 solid var(--color-background-quaternary); + left: calc(-1 * var(--sp-xs)); + margin-top: var(--sp-s); } // FLOATING COMMENT diff --git a/frontend/src/app/main/ui/workspace/comments.scss b/frontend/src/app/main/ui/workspace/comments.scss index 5fb9de3068..dbb829eb68 100644 --- a/frontend/src/app/main/ui/workspace/comments.scss +++ b/frontend/src/app/main/ui/workspace/comments.scss @@ -5,6 +5,7 @@ // Copyright (c) KALEIDOS INC Sucursal en España SL @use "ds/_sizes.scss" as *; +@use "ds/_borders.scss" as *; @use "refactor/common-refactor.scss" as deprecated; .comments-section { @@ -112,7 +113,12 @@ } .separator { - height: deprecated.$s-12; + position: relative; + block-size: var(--sp-xs); + inline-size: calc(100% + var(--sp-s)); + border-top: $b-1 solid var(--color-background-quaternary); + left: calc(-1 * var(--sp-xs)); + margin-top: var(--sp-s); } .comments-section-content { diff --git a/frontend/test/frontend_tests/data/comments_filters_test.cljs b/frontend/test/frontend_tests/data/comments_filters_test.cljs new file mode 100644 index 0000000000..cc0b5181c4 --- /dev/null +++ b/frontend/test/frontend_tests/data/comments_filters_test.cljs @@ -0,0 +1,56 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC Sucursal en España SL + +(ns frontend-tests.data.comments-filters-test + (:require + [app.main.data.comments :as dcmt] + [app.util.storage :as storage] + [cljs.test :as t :include-macros true] + [potok.v2.core :as ptk])) + +(def ^:private storage-key + :app.main.data.comments/hide-resolved-comments?) + +(t/deftest test-merge-persisted-filters-default + (let [prev (get @storage/user storage-key)] + (try + (swap! storage/user dissoc storage-key) + (t/is (= {:show :all} (dcmt/merge-persisted-filters nil))) + (t/is (= {:show :all} (dcmt/merge-persisted-filters {}))) + (finally + (if (some? prev) + (swap! storage/user assoc storage-key prev) + (swap! storage/user dissoc storage-key)))))) + +(t/deftest test-merge-persisted-filters-hide-resolved + (let [prev (get @storage/user storage-key)] + (try + (swap! storage/user assoc storage-key true) + (t/is (= {:show :pending} (dcmt/merge-persisted-filters nil))) + (finally + (if (some? prev) + (swap! storage/user assoc storage-key prev) + (swap! storage/user dissoc storage-key)))))) + +(t/deftest test-merge-persisted-filters-keeps-session-value + (let [prev (get @storage/user storage-key)] + (try + (swap! storage/user assoc storage-key true) + (t/is (= {:show :all :mode :yours} + (dcmt/merge-persisted-filters {:show :all :mode :yours}))) + (finally + (if (some? prev) + (swap! storage/user assoc storage-key prev) + (swap! storage/user dissoc storage-key)))))) + +(t/deftest test-update-filters-updates-show + (let [event (dcmt/update-filters {:show :pending}) + state (ptk/update event {})] + (t/is (= :pending (get-in state [:comments-local :show]))) + + (let [event (dcmt/update-filters {:show :all}) + state (ptk/update event state)] + (t/is (= :all (get-in state [:comments-local :show])))))) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 2adae3e61e..98cc3e5b72 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -8,6 +8,7 @@ [frontend-tests.code-gen-style-test] [frontend-tests.composable-tests.comp.sync-test] [frontend-tests.copy-as-svg-test] + [frontend-tests.data.comments-filters-test] [frontend-tests.data.nitrate-test] [frontend-tests.data.repo-test] [frontend-tests.data.uploads-test] @@ -82,6 +83,7 @@ 'frontend-tests.code-gen-style-test 'frontend-tests.composable-tests.comp.sync-test 'frontend-tests.copy-as-svg-test + 'frontend-tests.data.comments-filters-test 'frontend-tests.data.nitrate-test 'frontend-tests.data.repo-test 'frontend-tests.data.uploads-test