Merge pull request #4048 from penpot/niwinz-staging-bugfix-7

🐛 Fix unexpected exception on consecutive delete files with shift key pressed
This commit is contained in:
Alejandro 2024-01-25 13:00:15 +01:00 committed by GitHub
commit db5c16fb1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 15 deletions

View file

@ -86,7 +86,7 @@
[files selected] [files selected]
(let [get-file #(get files %) (let [get-file #(get files %)
sim-file #(select-keys % [:id :name :project-id :is-shared]) sim-file #(select-keys % [:id :name :project-id :is-shared])
xform (comp (map get-file) xform (comp (keep get-file)
(map sim-file))] (map sim-file))]
(->> (into #{} xform selected) (->> (into #{} xform selected)
(d/index-by :id)))) (d/index-by :id))))
@ -96,14 +96,15 @@
;; we need to this because :dashboard-search-result is a list ;; we need to this because :dashboard-search-result is a list
;; of maps and we need a map of maps (using :id as key). ;; of maps and we need a map of maps (using :id as key).
(let [files (d/index-by :id (:dashboard-search-result state))] (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)) st/state))
(def dashboard-selected-files (def dashboard-selected-files
(l/derived (fn [state] (l/derived (fn [state]
(dashboard-extract-selected (:dashboard-files state) (->> (dm/get-in state [:dashboard-local :selected-files])
(dm/get-in state [:dashboard-local :selected-files]))) (dashboard-extract-selected (:dashboard-files state))))
st/state =)) st/state))
;; ---- Workspace refs ;; ---- Workspace refs

View file

@ -54,12 +54,14 @@
projects)) projects))
(mf/defc file-menu (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 (seq files) "missing `files` prop")
(assert (boolean? show?) "missing `show?` prop") (assert (boolean? show?) "missing `show?` prop")
(assert (fn? on-edit) "missing `on-edit` prop") (assert (fn? on-edit) "missing `on-edit` prop")
(assert (fn? on-menu-close) "missing `on-menu-close` prop") (assert (fn? on-menu-close) "missing `on-menu-close` prop")
(assert (boolean? navigate?) "missing `navigate?` prop") (assert (boolean? navigate?) "missing `navigate?` prop")
(let [is-lib-page? (= :libraries origin) (let [is-lib-page? (= :libraries origin)
is-search-page? (= :search origin) is-search-page? (= :search origin)
top (or top 0) top (or top 0)
@ -88,15 +90,15 @@
(apply st/emit! (map dd/duplicate-file files)) (apply st/emit! (map dd/duplicate-file files))
(st/emit! (dm/success (tr "dashboard.success-duplicate-file" (i18n/c (count files)))))) (st/emit! (dm/success (tr "dashboard.success-duplicate-file" (i18n/c (count files))))))
delete-fn on-delete-accept
(fn [_] (fn [_]
(apply st/emit! (map dd/delete-file files)) (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 on-delete
(fn [event] (fn [event]
(dom/stop-propagation event) (dom/stop-propagation event)
(let [num-shared (filter #(:is-shared %) files)] (let [num-shared (filter #(:is-shared %) files)]
(if (< 0 (count num-shared)) (if (< 0 (count num-shared))
@ -104,7 +106,7 @@
{:type :delete-shared-libraries {:type :delete-shared-libraries
:origin :delete :origin :delete
:ids (into #{} (map :id) files) :ids (into #{} (map :id) files)
:on-accept delete-fn :on-accept on-delete-accept
:count-libraries (count num-shared)})) :count-libraries (count num-shared)}))
(if multi? (if multi?
@ -113,13 +115,13 @@
:title (tr "modals.delete-file-multi-confirm.title" file-count) :title (tr "modals.delete-file-multi-confirm.title" file-count)
:message (tr "modals.delete-file-multi-confirm.message" file-count) :message (tr "modals.delete-file-multi-confirm.message" file-count)
:accept-label (tr "modals.delete-file-multi-confirm.accept" 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 (st/emit! (modal/show
{:type :confirm {:type :confirm
:title (tr "modals.delete-file-confirm.title") :title (tr "modals.delete-file-confirm.title")
:message (tr "modals.delete-file-confirm.message") :message (tr "modals.delete-file-confirm.message")
:accept-label (tr "modals.delete-file-confirm.accept") :accept-label (tr "modals.delete-file-confirm.accept")
:on-accept delete-fn})))))) :on-accept on-delete-accept}))))))
on-move-success on-move-success
(fn [team-id project-id] (fn [team-id project-id]

View file

@ -218,6 +218,9 @@
{:wrap [mf/memo]} {:wrap [mf/memo]}
[{:keys [file origin library-view?] :as props}] [{:keys [file origin library-view?] :as props}]
(let [file-id (:id file) (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) selected-files (if (= origin :search)
(mf/deref refs/dashboard-selected-search) (mf/deref refs/dashboard-selected-search)
(mf/deref refs/dashboard-selected-files)) (mf/deref refs/dashboard-selected-files))

View file

@ -26,7 +26,7 @@
::mf/register-as :delete-shared-libraries ::mf/register-as :delete-shared-libraries
::mf/wrap-props false} ::mf/wrap-props false}
[{:keys [ids on-accept on-cancel accept-style origin count-libraries]}] [{: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*) references (deref references*)
on-accept (or on-accept noop) on-accept (or on-accept noop)
@ -78,8 +78,8 @@
(mf/with-effect [ids] (mf/with-effect [ids]
(->> (rx/from ids) (->> (rx/from ids)
(rx/map #(array-map :file-id %)) (rx/filter some?)
(rx/mapcat #(rp/cmd! :get-library-file-references %)) (rx/mapcat #(rp/cmd! :get-library-file-references {:file-id %}))
(rx/mapcat identity) (rx/mapcat identity)
(rx/map (juxt :id :name)) (rx/map (juxt :id :name))
(rx/reduce conj []) (rx/reduce conj [])