mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -05:00
🐛 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.
This commit is contained in:
parent
3c07416c48
commit
98cae9fe10
4 changed files with 21 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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 [])
|
||||
|
|
Loading…
Reference in a new issue