mirror of
https://github.com/penpot/penpot.git
synced 2025-06-13 03:01:39 +02:00
🐛 Take into account indirect libraries
This commit is contained in:
parent
715b7ba13e
commit
f4374c5046
4 changed files with 37 additions and 7 deletions
|
@ -247,6 +247,7 @@
|
||||||
|
|
||||||
(def ^:private sql:file-libraries
|
(def ^:private sql:file-libraries
|
||||||
"select fl.*,
|
"select fl.*,
|
||||||
|
? as is_indirect,
|
||||||
flr.synced_at as synced_at
|
flr.synced_at as synced_at
|
||||||
from file as fl
|
from file as fl
|
||||||
inner join file_library_rel as flr on (flr.library_file_id = fl.id)
|
inner join file_library_rel as flr on (flr.library_file_id = fl.id)
|
||||||
|
@ -254,8 +255,23 @@
|
||||||
and fl.deleted_at is null")
|
and fl.deleted_at is null")
|
||||||
|
|
||||||
(defn retrieve-file-libraries
|
(defn retrieve-file-libraries
|
||||||
[conn file-id]
|
[conn is-indirect file-id]
|
||||||
(into [] decode-row-xf (db/exec! conn [sql:file-libraries file-id])))
|
(let [direct-libraries
|
||||||
|
(into [] decode-row-xf (db/exec! conn [sql:file-libraries is-indirect file-id]))
|
||||||
|
|
||||||
|
select-distinct
|
||||||
|
(fn [used-libraries new-libraries]
|
||||||
|
(remove (fn [new-library]
|
||||||
|
(some #(= (:id %) (:id new-library)) used-libraries))
|
||||||
|
new-libraries))]
|
||||||
|
|
||||||
|
(reduce (fn [used-libraries library]
|
||||||
|
(concat used-libraries
|
||||||
|
(select-distinct
|
||||||
|
used-libraries
|
||||||
|
(retrieve-file-libraries conn true (:id library)))))
|
||||||
|
direct-libraries
|
||||||
|
direct-libraries)))
|
||||||
|
|
||||||
(s/def ::file-libraries
|
(s/def ::file-libraries
|
||||||
(s/keys :req-un [::profile-id ::file-id]))
|
(s/keys :req-un [::profile-id ::file-id]))
|
||||||
|
@ -264,7 +280,7 @@
|
||||||
[{:keys [profile-id file-id] :as params}]
|
[{:keys [profile-id file-id] :as params}]
|
||||||
(db/with-atomic [conn db/pool]
|
(db/with-atomic [conn db/pool]
|
||||||
(check-edition-permissions! conn profile-id file-id)
|
(check-edition-permissions! conn profile-id file-id)
|
||||||
(retrieve-file-libraries conn file-id)))
|
(retrieve-file-libraries conn false file-id)))
|
||||||
|
|
||||||
|
|
||||||
;; --- Query: Single File Library
|
;; --- Query: Single File Library
|
||||||
|
|
|
@ -136,6 +136,16 @@
|
||||||
[mfn coll]
|
[mfn coll]
|
||||||
(into {} (map (fn [[key val]] [key (mfn key val)]) coll)))
|
(into {} (map (fn [[key val]] [key (mfn key val)]) coll)))
|
||||||
|
|
||||||
|
(defn filterm
|
||||||
|
"Filter values of a map that satisfy a predicate"
|
||||||
|
[pred coll]
|
||||||
|
(into {} (filter pred coll)))
|
||||||
|
|
||||||
|
(defn removem
|
||||||
|
"Remove values of a map that satisfy a predicate"
|
||||||
|
[pred coll]
|
||||||
|
(into {} (remove pred coll)))
|
||||||
|
|
||||||
(defn map-perm
|
(defn map-perm
|
||||||
"Maps a function to each pair of values that can be combined inside the
|
"Maps a function to each pair of values that can be combined inside the
|
||||||
function without repetition.
|
function without repetition.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
(ns app.main.ui.workspace.libraries
|
(ns app.main.ui.workspace.libraries
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as d]
|
||||||
[rumext.alpha :as mf]
|
[rumext.alpha :as mf]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
|
@ -142,7 +143,6 @@
|
||||||
:value (tr "workspace.libraries.update")
|
:value (tr "workspace.libraries.update")
|
||||||
:on-click #(update-library (:id library))}]])]])]))
|
:on-click #(update-library (:id library))}]])]])]))
|
||||||
|
|
||||||
|
|
||||||
(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}
|
||||||
|
@ -152,7 +152,9 @@
|
||||||
locale (mf/deref i18n/locale)
|
locale (mf/deref i18n/locale)
|
||||||
project (mf/deref refs/workspace-project)
|
project (mf/deref refs/workspace-project)
|
||||||
file (mf/deref workspace-file)
|
file (mf/deref workspace-file)
|
||||||
libraries (mf/deref refs/workspace-libraries)
|
libraries (->> (mf/deref refs/workspace-libraries)
|
||||||
|
(d/removem (fn [[key val]]
|
||||||
|
(:is-indirect val))))
|
||||||
shared-files (mf/deref refs/workspace-shared-files)
|
shared-files (mf/deref refs/workspace-shared-files)
|
||||||
|
|
||||||
change-tab #(reset! selected-tab %)
|
change-tab #(reset! selected-tab %)
|
||||||
|
|
|
@ -631,7 +631,9 @@
|
||||||
|
|
||||||
(mf/defc assets-toolbox
|
(mf/defc assets-toolbox
|
||||||
[]
|
[]
|
||||||
(let [libraries (mf/deref refs/workspace-libraries)
|
(let [libraries (->> (mf/deref refs/workspace-libraries)
|
||||||
|
(vals)
|
||||||
|
(remove :is-indirect))
|
||||||
file (mf/deref refs/workspace-file)
|
file (mf/deref refs/workspace-file)
|
||||||
locale (mf/deref i18n/locale)
|
locale (mf/deref i18n/locale)
|
||||||
team-id (mf/use-ctx ctx/current-team-id)
|
team-id (mf/use-ctx ctx/current-team-id)
|
||||||
|
@ -697,7 +699,7 @@
|
||||||
:open? true
|
:open? true
|
||||||
:filters @filters}]
|
:filters @filters}]
|
||||||
|
|
||||||
(for [file (->> (vals libraries)
|
(for [file (->> libraries
|
||||||
(sort-by #(str/lower (:name %))))]
|
(sort-by #(str/lower (:name %))))]
|
||||||
[:& file-library
|
[:& file-library
|
||||||
{:key (:id file)
|
{:key (:id file)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue