mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
✨ Sort asset subfolders alphabetically (#8952)
Subgroups in asset libraries were rendered in hash-map order because update-in descends into plain maps instead of sorted ones. Add a recursive post-process that rebuilds every level as a sorted-map so subfolders are alphabetical at every nesting depth. Closes #2572 Signed-off-by: eureka928 <meobius123@gmail.com>
This commit is contained in:
parent
d90e7f8164
commit
8b14de2610
@ -31,6 +31,7 @@
|
||||
- Use page name for multi-export ZIP/PDF downloads (by @Dexterity104) [Github #8773](https://github.com/penpot/penpot/issues/8773)
|
||||
- Make links in comments clickable (by @eureka928) [Github #1602](https://github.com/penpot/penpot/issues/1602)
|
||||
- Add visibility toggle for strokes (by @eureka928) [Github #7438](https://github.com/penpot/penpot/issues/7438)
|
||||
- Sort asset library subfolders alphabetically at every nesting level (by @eureka928) [Github #2572](https://github.com/penpot/penpot/issues/2572)
|
||||
|
||||
### :bug: Bugs fixed
|
||||
|
||||
|
||||
@ -86,6 +86,17 @@
|
||||
:on-click on-context-menu
|
||||
:icon i/menu}]]])))
|
||||
|
||||
(defn- sort-groups
|
||||
"Recursively sort subgroup keys alphabetically at every nesting level."
|
||||
[groups reverse-sort?]
|
||||
(let [cmp (if reverse-sort? #(compare %2 %1) compare)
|
||||
sort-tree (fn sort-tree [m]
|
||||
(into (sorted-map-by cmp)
|
||||
(map (fn [[k v]]
|
||||
[k (if (map? v) (sort-tree v) v)]))
|
||||
m))]
|
||||
(sort-tree groups)))
|
||||
|
||||
(defn group-assets
|
||||
"Convert a list of assets in a nested structure like this:
|
||||
|
||||
@ -97,19 +108,17 @@
|
||||
"
|
||||
[assets reverse-sort?]
|
||||
(when-not (empty? assets)
|
||||
(reduce (fn [groups {:keys [path] :as asset}]
|
||||
(let [path (cpn/split-path (or path ""))]
|
||||
(update-in groups
|
||||
(conj path "")
|
||||
(fn [group]
|
||||
(if group
|
||||
(conj group asset)
|
||||
[asset])))))
|
||||
(sorted-map-by (fn [key1 key2]
|
||||
(if reverse-sort?
|
||||
(compare key2 key1)
|
||||
(compare key1 key2))))
|
||||
assets)))
|
||||
(-> (reduce (fn [groups {:keys [path] :as asset}]
|
||||
(let [path (cpn/split-path (or path ""))]
|
||||
(update-in groups
|
||||
(conj path "")
|
||||
(fn [group]
|
||||
(if group
|
||||
(conj group asset)
|
||||
[asset])))))
|
||||
{}
|
||||
assets)
|
||||
(sort-groups reverse-sort?))))
|
||||
|
||||
(def ^:private schema:group-form
|
||||
[:map {:title "GroupForm"}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user