From f786aff3fc0776efbe3acd89bdceba9ad2b97d5f Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Tue, 25 Jun 2024 13:36:37 +0200 Subject: [PATCH] :bug: Fix can't collapse groups when searching in the assets tab --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 8 ++++++++ frontend/src/app/main/ui/workspace/sidebar/assets.cljs | 4 ++++ .../app/main/ui/workspace/sidebar/assets/components.cljs | 6 ++++-- .../main/ui/workspace/sidebar/assets/file_library.cljs | 7 +++++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 43ff3f8ab..53f918038 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -50,6 +50,7 @@ - Penpot crashes when a new colorpicker is created while uploading an image to another instance [Taiga #8119](https://tree.taiga.io/project/penpot/issue/8119) - Removing Underline and Strikethrough Affects the Previous Text Object [Taiga #8103](https://tree.taiga.io/project/penpot/issue/8103) - Color library loses association with shapes when exporting/importing the document [Taiga #8132](https://tree.taiga.io/project/penpot/issue/8132) +- Fix can't collapse groups when searching in the assets tab [Taiga #8125](https://tree.taiga.io/project/penpot/issue/8125) ## 2.0.3 diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index c2ce35228..5faee0a0c 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1096,6 +1096,14 @@ (update [_ state] (assoc-in state [:workspace-assets :open-status file-id section] open?)))) +(defn clear-assets-section-open + [] + (ptk/reify ::clear-assets-section-open + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-assets :open-status] {})))) + + (defn set-assets-group-open [file-id section path open?] (ptk/reify ::set-assets-group-open diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 85e31946b..a1ec84728 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -9,8 +9,10 @@ (:require [app.common.data.macros :as dm] [app.main.data.modal :as modal] + [app.main.data.workspace :as dw] [app.main.data.workspace.assets :as dwa] [app.main.refs :as refs] + [app.main.store :as st] [app.main.ui.components.context-menu-a11y :refer [context-menu-a11y]] [app.main.ui.components.search-bar :refer [search-bar]] [app.main.ui.context :as ctx] @@ -103,6 +105,7 @@ on-search-term-change (mf/use-fn (fn [event] + (st/emit! (dw/clear-assets-section-open)) (swap! filters* assoc :term event))) on-section-filter-change @@ -112,6 +115,7 @@ (dom/get-value)) (as-> (dom/get-current-target event) $ (dom/get-attribute $ "data-testid")))] + (st/emit! (dw/clear-assets-section-open)) (swap! filters* assoc :section value :open-menu false)))) show-libraries-dialog diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs index 371716d7e..eb2c59c01 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/components.cljs @@ -192,8 +192,10 @@ on-drag-start do-rename cancel-rename on-rename-group on-group on-ungroup on-context-menu selected-full local]}] - (let [group-open? (or ^boolean force-open? - ^boolean (get open-groups prefix (if (= prefix "") true false))) + (let [group-open? (if (false? (get open-groups prefix)) ;; if the user has closed it specifically, respect that + false + (or ^boolean force-open? + ^boolean (get open-groups prefix (if (= prefix "") true false)))) dragging* (mf/use-state false) dragging? (deref dragging*) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/file_library.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/file_library.cljs index 109d067a6..b255013aa 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/file_library.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/file_library.cljs @@ -318,6 +318,7 @@ (and has-term? (some pos? (map count [filtered-components filtered-colors filtered-media filtered-typographies])) (some #(> 60 (count %)) [filtered-components filtered-colors filtered-media filtered-typographies])))) + (mf/defc file-library {::mf/wrap-props false} [{:keys [file local? default-open? filters]}] @@ -333,8 +334,10 @@ open-status (mf/deref open-status-ref) force-open-lib? (force-lib-open? file-id filters) - open? (or force-open-lib? - (d/nilv (:library open-status) default-open?)) + open? (if (false? (:library open-status)) ;; if the user has closed it specifically, respect that + false + (or force-open-lib? + (d/nilv (:library open-status) default-open?))) unselect-all (mf/use-fn