From 98cae9fe101c45cb9ab0891f55a26fdd4f3f2e71 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Jan 2024 11:54:03 +0100 Subject: [PATCH] :bug: Fix unexpected exception on consecutive delete files with shift key pressed If you select N files (using shift key), then delete them and continuing pressing the shift select an other file and proceed to delete it an exception is raised. This is happens because the previous selection is not cleared. This commit fixes that. --- frontend/src/app/main/refs.cljs | 11 ++++++----- .../src/app/main/ui/dashboard/file_menu.cljs | 16 +++++++++------- frontend/src/app/main/ui/dashboard/grid.cljs | 3 +++ frontend/src/app/main/ui/delete_shared.cljs | 6 +++--- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 58fce5791..1a63a5032 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -86,7 +86,7 @@ [files selected] (let [get-file #(get files %) sim-file #(select-keys % [:id :name :project-id :is-shared]) - xform (comp (map get-file) + xform (comp (keep get-file) (map sim-file))] (->> (into #{} xform selected) (d/index-by :id)))) @@ -96,14 +96,15 @@ ;; we need to this because :dashboard-search-result is a list ;; of maps and we need a map of maps (using :id as key). (let [files (d/index-by :id (:dashboard-search-result state))] - (dashboard-extract-selected files (dm/get-in state [:dashboard-local :selected-files])))) + (->> (dm/get-in state [:dashboard-local :selected-files]) + (dashboard-extract-selected files)))) st/state)) (def dashboard-selected-files (l/derived (fn [state] - (dashboard-extract-selected (:dashboard-files state) - (dm/get-in state [:dashboard-local :selected-files]))) - st/state =)) + (->> (dm/get-in state [:dashboard-local :selected-files]) + (dashboard-extract-selected (:dashboard-files state)))) + st/state)) ;; ---- Workspace refs diff --git a/frontend/src/app/main/ui/dashboard/file_menu.cljs b/frontend/src/app/main/ui/dashboard/file_menu.cljs index 283460530..dd7c452d0 100644 --- a/frontend/src/app/main/ui/dashboard/file_menu.cljs +++ b/frontend/src/app/main/ui/dashboard/file_menu.cljs @@ -54,12 +54,14 @@ projects)) (mf/defc file-menu - [{:keys [files show? on-edit on-menu-close top left navigate? origin parent-id] :as props}] + {::mf/wrap-props false} + [{:keys [files show? on-edit on-menu-close top left navigate? origin parent-id]}] (assert (seq files) "missing `files` prop") (assert (boolean? show?) "missing `show?` prop") (assert (fn? on-edit) "missing `on-edit` prop") (assert (fn? on-menu-close) "missing `on-menu-close` prop") (assert (boolean? navigate?) "missing `navigate?` prop") + (let [is-lib-page? (= :libraries origin) is-search-page? (= :search origin) top (or top 0) @@ -88,15 +90,15 @@ (apply st/emit! (map dd/duplicate-file files)) (st/emit! (dm/success (tr "dashboard.success-duplicate-file" (i18n/c (count files)))))) - delete-fn + on-delete-accept (fn [_] (apply st/emit! (map dd/delete-file files)) - (st/emit! (dm/success (tr "dashboard.success-delete-file" (i18n/c (count files)))))) + (st/emit! (dm/success (tr "dashboard.success-delete-file" (i18n/c (count files)))) + (dd/clear-selected-files))) on-delete (fn [event] (dom/stop-propagation event) - (let [num-shared (filter #(:is-shared %) files)] (if (< 0 (count num-shared)) @@ -104,7 +106,7 @@ {:type :delete-shared-libraries :origin :delete :ids (into #{} (map :id) files) - :on-accept delete-fn + :on-accept on-delete-accept :count-libraries (count num-shared)})) (if multi? @@ -113,13 +115,13 @@ :title (tr "modals.delete-file-multi-confirm.title" file-count) :message (tr "modals.delete-file-multi-confirm.message" file-count) :accept-label (tr "modals.delete-file-multi-confirm.accept" file-count) - :on-accept delete-fn})) + :on-accept on-delete-accept})) (st/emit! (modal/show {:type :confirm :title (tr "modals.delete-file-confirm.title") :message (tr "modals.delete-file-confirm.message") :accept-label (tr "modals.delete-file-confirm.accept") - :on-accept delete-fn})))))) + :on-accept on-delete-accept})))))) on-move-success (fn [team-id project-id] diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs index f4cf52eb2..107943180 100644 --- a/frontend/src/app/main/ui/dashboard/grid.cljs +++ b/frontend/src/app/main/ui/dashboard/grid.cljs @@ -218,6 +218,9 @@ {:wrap [mf/memo]} [{:keys [file origin library-view?] :as props}] (let [file-id (:id file) + + ;; FIXME: this breaks react hooks rule, hooks should never to + ;; be in a conditional code selected-files (if (= origin :search) (mf/deref refs/dashboard-selected-search) (mf/deref refs/dashboard-selected-files)) diff --git a/frontend/src/app/main/ui/delete_shared.cljs b/frontend/src/app/main/ui/delete_shared.cljs index c31b77bdf..f1254fc86 100644 --- a/frontend/src/app/main/ui/delete_shared.cljs +++ b/frontend/src/app/main/ui/delete_shared.cljs @@ -26,7 +26,7 @@ ::mf/register-as :delete-shared-libraries ::mf/wrap-props false} [{:keys [ids on-accept on-cancel accept-style origin count-libraries]}] - (let [references* (mf/use-state {}) + (let [references* (mf/use-state nil) references (deref references*) on-accept (or on-accept noop) @@ -78,8 +78,8 @@ (mf/with-effect [ids] (->> (rx/from ids) - (rx/map #(array-map :file-id %)) - (rx/mapcat #(rp/cmd! :get-library-file-references %)) + (rx/filter some?) + (rx/mapcat #(rp/cmd! :get-library-file-references {:file-id %})) (rx/mapcat identity) (rx/map (juxt :id :name)) (rx/reduce conj [])