mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 02:11:39 +02:00
🐛 Fix incorrect libraries filtering on workspace
This commit is contained in:
parent
2dcf692853
commit
0e73de17ec
6 changed files with 57 additions and 26 deletions
|
@ -168,11 +168,13 @@
|
||||||
(assoc file :data (d/removem (comp t/pointer? val) data))))))))))
|
(assoc file :data (d/removem (comp t/pointer? val) data))))))))))
|
||||||
|
|
||||||
(defn- libraries-fetched
|
(defn- libraries-fetched
|
||||||
[libraries]
|
[file-id libraries]
|
||||||
(ptk/reify ::libraries-fetched
|
(ptk/reify ::libraries-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [libraries (d/index-by :id libraries)]
|
(let [libraries (->> libraries
|
||||||
|
(map (fn [l] (assoc l :library-of file-id)))
|
||||||
|
(d/index-by :id))]
|
||||||
(update state :files merge libraries)))
|
(update state :files merge libraries)))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
@ -208,7 +210,7 @@
|
||||||
(rx/map #(assoc % :synced-at synced-at)))))
|
(rx/map #(assoc % :synced-at synced-at)))))
|
||||||
(rx/merge-map resolve-file)
|
(rx/merge-map resolve-file)
|
||||||
(rx/reduce conj [])
|
(rx/reduce conj [])
|
||||||
(rx/map libraries-fetched))
|
(rx/map (partial libraries-fetched file-id)))
|
||||||
(->> (rx/from libraries)
|
(->> (rx/from libraries)
|
||||||
(rx/map :id)
|
(rx/map :id)
|
||||||
(rx/mapcat (fn [file-id]
|
(rx/mapcat (fn [file-id]
|
||||||
|
|
|
@ -1201,7 +1201,7 @@
|
||||||
(vals (get state :files)))
|
(vals (get state :files)))
|
||||||
|
|
||||||
do-more-info
|
do-more-info
|
||||||
#(modal/show! :libraries-dialog {:starting-tab "updates"})
|
#(modal/show! :libraries-dialog {:starting-tab "updates" :file-id file-id})
|
||||||
|
|
||||||
do-update
|
do-update
|
||||||
#(do (apply st/emit! (map (fn [library]
|
#(do (apply st/emit! (map (fn [library]
|
||||||
|
@ -1388,7 +1388,10 @@
|
||||||
(let [libraries (:workspace-shared-files state)
|
(let [libraries (:workspace-shared-files state)
|
||||||
library (d/seek #(= (:id %) library-id) libraries)]
|
library (d/seek #(= (:id %) library-id) libraries)]
|
||||||
(if library
|
(if library
|
||||||
(update state :files assoc library-id (dissoc library :library-summary))
|
(update state :files assoc library-id
|
||||||
|
(-> library
|
||||||
|
(dissoc :library-summary)
|
||||||
|
(assoc :library-of file-id)))
|
||||||
state)))
|
state)))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
@ -1401,6 +1404,8 @@
|
||||||
(->> (rp/cmd! :get-file {:id library-id :features features})
|
(->> (rp/cmd! :get-file {:id library-id :features features})
|
||||||
(rx/merge-map fpmap/resolve-file)
|
(rx/merge-map fpmap/resolve-file)
|
||||||
;; FIXME: this should call the libraries-fetched event instead of ad-hoc assoc event
|
;; FIXME: this should call the libraries-fetched event instead of ad-hoc assoc event
|
||||||
|
(rx/map (fn [file]
|
||||||
|
(assoc file :library-of file-id)))
|
||||||
(rx/map (fn [file]
|
(rx/map (fn [file]
|
||||||
(fn [state]
|
(fn [state]
|
||||||
(assoc-in state [:files library-id] file)))))
|
(assoc-in state [:files library-id] file)))))
|
||||||
|
|
|
@ -83,10 +83,32 @@
|
||||||
files (without the content, only summary)"
|
files (without the content, only summary)"
|
||||||
(l/derived :shared-files st/state))
|
(l/derived :shared-files st/state))
|
||||||
|
|
||||||
|
(defn select-libraries
|
||||||
|
[files file-id]
|
||||||
|
(persistent!
|
||||||
|
(reduce-kv (fn [result id file]
|
||||||
|
(if (or (= id file-id)
|
||||||
|
(= (:library-of file) file-id))
|
||||||
|
(assoc! result id file)
|
||||||
|
result))
|
||||||
|
(transient {})
|
||||||
|
files)))
|
||||||
|
|
||||||
|
;; NOTE: for performance reasons, prefer derefing refs/files and then
|
||||||
|
;; use with-memo mechanism with `select-libraries` this will avoid
|
||||||
|
;; executing the select-libraries reduce-kv on each state change and
|
||||||
|
;; only execute it when files are changed. This ref exists for
|
||||||
|
;; backward compatibility with the code, but it is considered
|
||||||
|
;; DEPRECATED and all new code should not use it and old code should
|
||||||
|
;; be gradually migrated to more efficient approach
|
||||||
(def libraries
|
(def libraries
|
||||||
"A derived state that contanins the currently loaded shared libraries
|
"A derived state that contanins the currently loaded shared
|
||||||
with all its content; including the current file"
|
libraries with all its content; including the current file"
|
||||||
(l/derived :files st/state))
|
(l/derived (fn [state]
|
||||||
|
(let [files (get state :files)
|
||||||
|
file-id (get state :current-file-id)]
|
||||||
|
(select-libraries files file-id)))
|
||||||
|
st/state))
|
||||||
|
|
||||||
(defn extract-selected-files
|
(defn extract-selected-files
|
||||||
[files selected]
|
[files selected]
|
||||||
|
|
|
@ -248,10 +248,12 @@
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps file-id)
|
(mf/deps file-id)
|
||||||
#(st/emit! (dwl/set-file-shared file-id false)
|
#(st/emit! (dwl/set-file-shared file-id false)
|
||||||
(modal/show :libraries-dialog {})))
|
(modal/show :libraries-dialog {:file-id file-id})))
|
||||||
|
|
||||||
on-delete-cancel
|
on-delete-cancel
|
||||||
(mf/use-fn #(st/emit! (modal/show :libraries-dialog {})))
|
(mf/use-fn
|
||||||
|
(mf/deps file-id)
|
||||||
|
#(st/emit! (modal/show :libraries-dialog {:file-id file-id})))
|
||||||
|
|
||||||
publish
|
publish
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
@ -259,7 +261,7 @@
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [input-node (dom/get-target event)
|
(let [input-node (dom/get-target event)
|
||||||
publish-library #(st/emit! (dwl/set-file-shared file-id true))
|
publish-library #(st/emit! (dwl/set-file-shared file-id true))
|
||||||
cancel-publish #(st/emit! (modal/show :libraries-dialog {}))]
|
cancel-publish #(st/emit! (modal/show :libraries-dialog {:file-id file-id}))]
|
||||||
(if empty-library?
|
(if empty-library?
|
||||||
(st/emit! (modal/show
|
(st/emit! (modal/show
|
||||||
{:type :confirm
|
{:type :confirm
|
||||||
|
@ -563,17 +565,15 @@
|
||||||
(mf/defc libraries-dialog
|
(mf/defc libraries-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :libraries-dialog}
|
::mf/register-as :libraries-dialog}
|
||||||
[{:keys [starting-tab] :as props :or {starting-tab :libraries}}]
|
[{:keys [starting-tab file-id] :as props :or {starting-tab :libraries}}]
|
||||||
(let [;; NOTE: we don't want to react on file changes, we just want
|
(let [files (mf/deref refs/files)
|
||||||
;; a snapshot of file on the momento of open the dialog
|
file (get files file-id)
|
||||||
file (deref refs/file)
|
team-id (:team-id file)
|
||||||
|
shared? (:is-shared file)
|
||||||
file-id (:id file)
|
|
||||||
team-id (:team-id file)
|
|
||||||
shared? (:is-shared file)
|
|
||||||
|
|
||||||
linked-libraries
|
linked-libraries
|
||||||
(mf/deref refs/files)
|
(mf/with-memo [files file-id]
|
||||||
|
(refs/select-libraries files file-id))
|
||||||
|
|
||||||
linked-libraries
|
linked-libraries
|
||||||
(mf/with-memo [linked-libraries file-id]
|
(mf/with-memo [linked-libraries file-id]
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
[{:keys [layout file page-id] :as props}]
|
[{:keys [layout file page-id] :as props}]
|
||||||
(let [options-mode (mf/deref refs/options-mode-global)
|
(let [options-mode (mf/deref refs/options-mode-global)
|
||||||
project (mf/deref refs/project)
|
project (mf/deref refs/project)
|
||||||
|
file-id (get file :id)
|
||||||
|
|
||||||
design-tokens? (features/use-feature "design-tokens/v1")
|
design-tokens? (features/use-feature "design-tokens/v1")
|
||||||
mode-inspect? (= options-mode :inspect)
|
mode-inspect? (= options-mode :inspect)
|
||||||
|
@ -116,7 +117,7 @@
|
||||||
|
|
||||||
|
|
||||||
assets-tab
|
assets-tab
|
||||||
(mf/html [:& assets-toolbox {:size (- size 58) :file-id file}])
|
(mf/html [:& assets-toolbox {:size (- size 58) :file-id file-id}])
|
||||||
|
|
||||||
tokens-tab
|
tokens-tab
|
||||||
(when design-tokens?
|
(when design-tokens?
|
||||||
|
|
|
@ -33,10 +33,10 @@
|
||||||
::mf/private true}
|
::mf/private true}
|
||||||
[{:keys [filters]}]
|
[{:keys [filters]}]
|
||||||
(let [file-id (mf/use-ctx ctx/current-file-id)
|
(let [file-id (mf/use-ctx ctx/current-file-id)
|
||||||
|
files (mf/deref refs/files)
|
||||||
libraries (mf/deref refs/libraries)
|
libraries (mf/with-memo [files file-id]
|
||||||
libraries (mf/with-memo [libraries file-id]
|
(->> (refs/select-libraries files file-id)
|
||||||
(->> (vals libraries)
|
(vals)
|
||||||
(remove :is-indirect)
|
(remove :is-indirect)
|
||||||
(remove #(= file-id (:id %)))
|
(remove #(= file-id (:id %)))
|
||||||
(map (fn [file]
|
(map (fn [file]
|
||||||
|
@ -129,8 +129,9 @@
|
||||||
|
|
||||||
show-libraries-dialog
|
show-libraries-dialog
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
|
(mf/deps file-id)
|
||||||
(fn []
|
(fn []
|
||||||
(modal/show! :libraries-dialog {})
|
(modal/show! :libraries-dialog {:file-id file-id})
|
||||||
(modal/allow-click-outside!)))
|
(modal/allow-click-outside!)))
|
||||||
|
|
||||||
on-open-menu
|
on-open-menu
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue